"""simple docstring"""






import json
import os
from collections import Counter

import torch
import torchvision
import torchvision.transforms as transforms
from PIL import Image
from torch import nn
from torch.utils.data import Dataset


__A			   = {1: (1, 1), 2: (2, 1), 3: (3, 1), 4: (2, 2), 5: (5, 1), 6: (3, 2), 7: (7, 1), 8: (4, 2), 9: (3, 3)}


class     UpperCAmelCase						(nn.Module  ):



    """simple docstring"""

    def __init__(   self    ,			_UpperCAmelCase							):
       super().__init__()
       lowercase__:   Tuple					=      torchvision.models.resnetaaa(pretrained=_UpperCAmelCase							)
       lowercase__:   Dict					=      list(model.children()							)[:-2]
       lowercase__:   int					=      nn.Sequential(*_UpperCAmelCase							)
       lowercase__:   Dict					=      nn.AdaptiveAvgPoolad(POOLING_BREAKDOWN[args.num_image_embeds]							)






    def _snake_case			(   self    ,			_UpperCAmelCase							):
       # Bx3x224x224 -> Bx2048x7x7 -> Bx2048xN -> BxNx2048
       lowercase__:   Any					=      self.pool(self.model(_UpperCAmelCase							)							)
       lowercase__:   int					=      torch.flatten(_UpperCAmelCase    ,			start_dim=2							)
       lowercase__:   List[str]					=      out.transpose(1    ,			2							).contiguous()
       return out  # BxNx2048



class     UpperCAmelCase						(_UpperCAmelCase  ):



    """simple docstring"""

    def __init__(   self    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase							):
       lowercase__:   Union[str, Any]					=      [json.loads(_UpperCAmelCase							) for l in open(_UpperCAmelCase							)]
       lowercase__:   Tuple					=      os.path.dirname(_UpperCAmelCase							)
       lowercase__:   Optional[int]					=      tokenizer
       lowercase__:   List[Any]					=      labels
       lowercase__:   List[str]					=      len(_UpperCAmelCase							)
       lowercase__:   Union[str, Any]					=      max_seq_length

       lowercase__:   Optional[int]					=      transforms






    def __len__(   self							):
       return len(self.data							)






    def __getitem__(   self    ,			_UpperCAmelCase							):
       lowercase__:   Union[str, Any]					=      torch.LongTensor(self.tokenizer.encode(self.data[index]['''text''']    ,			add_special_tokens=_UpperCAmelCase							)							)
       lowercase__, lowercase__, lowercase__:   Dict					=      sentence[0], sentence[1:-1], sentence[-1]
       lowercase__:   Optional[Any]					=      sentence[: self.max_seq_length]

       lowercase__:   Tuple					=      torch.zeros(self.n_classes							)
       lowercase__:   str					=      1

       lowercase__:   Dict					=      Image.open(os.path.join(self.data_dir    ,			self.data[index]['''img''']							)							).convert('''RGB'''							)
       lowercase__:   List[str]					=      self.transforms(_UpperCAmelCase							)

       return {
           "image_start_token": start_token,
           "image_end_token": end_token,
           "sentence": sentence,
           "image": image,
           "label": label,
       }






    def _snake_case			(   self							):
       lowercase__:   Dict					=      Counter()
       for row in self.data:
          label_freqs.update(row['''label''']							)
       return label_freqs



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase )  ->  int:
   lowercase__:   int					=      [len(row['''sentence'''] ) for row in batch]
   lowercase__, lowercase__:   Optional[Any]					=      len(__UpperCAmelCase ), max(__UpperCAmelCase )

   lowercase__:   str					=      torch.zeros(__UpperCAmelCase       ,    __UpperCAmelCase       ,    dtype=torch.long )
   lowercase__:   str					=      torch.zeros(__UpperCAmelCase       ,    __UpperCAmelCase       ,    dtype=torch.long )

   for i_batch, (input_row, length) in enumerate(zip(__UpperCAmelCase       ,    __UpperCAmelCase ) ):
      lowercase__:   Any					=      input_row['''sentence''']
      lowercase__:   Optional[Any]					=      1

   lowercase__:   List[str]					=      torch.stack([row['''image'''] for row in batch] )
   lowercase__:   List[Any]					=      torch.stack([row['''label'''] for row in batch] )
   lowercase__:   List[str]					=      torch.stack([row['''image_start_token'''] for row in batch] )
   lowercase__:   List[str]					=      torch.stack([row['''image_end_token'''] for row in batch] )

   return text_tensor, mask_tensor, img_tensor, img_start_token, img_end_token, tgt_tensor



def SCREAMING_SNAKE_CASE__			(   )  ->  Union[str, Any]:
   return [
       "Crime",
       "Drama",
       "Thriller",
       "Action",
       "Comedy",
       "Romance",
       "Documentary",
       "Short",
       "Mystery",
       "History",
       "Family",
       "Adventure",
       "Fantasy",
       "Sci-Fi",
       "Western",
       "Horror",
       "Sport",
       "War",
       "Music",
       "Musical",
       "Animation",
       "Biography",
       "Film-Noir",
   ]




def SCREAMING_SNAKE_CASE__			(   )  ->  Optional[Any]:
   return transforms.Compose(
       [
           transforms.Resize(2_5_6 ),
           transforms.CenterCrop(2_2_4 ),
           transforms.ToTensor(),
           transforms.Normalize(
               mean=[0.4_6_7_7_7_0_4_4, 0.4_4_5_3_1_4_2_9, 0.4_0_6_6_1_0_1_7]       ,    std=[0.1_2_2_2_1_9_9_4, 0.1_2_1_4_5_8_3_5, 0.1_4_3_8_0_4_6_9]       ,    ),
       ] )

"""simple docstring"""






def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase=2_8_1_2_3 )  ->  Any:
   lowercase__:   Optional[Any]					=      [1] * (limit + 1)

   for i in range(2       ,    int(limit**0.5 ) + 1 ):
      sum_divs[i * i] += i
      for k in range(i + 1       ,    limit // i + 1 ):
         sum_divs[k * i] += k + i

   lowercase__:   Union[str, Any]					=      set()
   lowercase__:   Optional[Any]					=      0

   for n in range(1       ,    limit + 1 ):
      if sum_divs[n] > n:
         abundants.add(__UpperCAmelCase )

      if not any((n - a in abundants) for a in abundants ):
         res += n

   return res


if __name__ == "__main__":
       print(solution())
