





UpperCAmelCase_      							=     range(2, 20 + 1)
UpperCAmelCase_      							=     [10**k for k in range(ks[-1] + 1)]
UpperCAmelCase_      							=     {}





def 						lowerCamelCase__     (     UpperCamelCase__			:       Optional[Any]       ,    UpperCamelCase__			:       List[Any]       ,    UpperCamelCase__			:       Union[str, Any]       ,    UpperCamelCase__			:       str						)			-> List[str]:



					'''simple docstring'''




					_snake_case									=				sum(a_i[j] for j in range(UpperCamelCase__       ,    len(UpperCamelCase__						)						)						)
					_snake_case									=				sum(a_i[j] * base[j] for j in range(min(len(UpperCamelCase__						)       ,    UpperCamelCase__						)						)						)

					_snake_case							,     _snake_case									=				0, 0
					_snake_case									=				n - i

					_snake_case									=				memo.get(UpperCamelCase__						)

					if sub_memo is not None:
										_snake_case									=				sub_memo.get(UpperCamelCase__						)

										if jumps is not None and len(UpperCamelCase__						) > 0:
															# find and make the largest jump without going over
															_snake_case									=				-1
															for _k in range(len(UpperCamelCase__						) - 1       ,    -1       ,    -1						):
																				if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
																									_snake_case									=				_k
																									break

															if max_jump >= 0:
																				_snake_case							,     _snake_case							,     _snake_case									=				jumps[max_jump]
																				# since the difference between jumps is cached, add c
																				_snake_case									=				diff + c
																				for j in range(min(UpperCamelCase__       ,    len(UpperCamelCase__						)						)						):
																									_snake_case							,     _snake_case									=				divmod(UpperCamelCase__       ,    10						)
																				if new_c > 0:
																									add(UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__						)

										else:
															_snake_case									=				[]
					else:
										_snake_case									=				{c: []}
										_snake_case									=				sub_memo

					if dn >= max_dn or c + diff >= base[k]:
										return diff, dn

					if k > ks[0]:
										while True:
															# keep doing smaller jumps
															_snake_case							,     _snake_case									=				next_term(UpperCamelCase__       ,    k - 1       ,    i + dn       ,    UpperCamelCase__						)
															diff += _diff
															dn += terms_jumped

															if dn >= max_dn or c + diff >= base[k]:
																				break
					else:
										# would be too small a jump, just compute sequential terms instead
										_snake_case							,     _snake_case									=				compute(UpperCamelCase__       ,    UpperCamelCase__       ,    i + dn       ,    UpperCamelCase__						)
										diff += _diff
										dn += terms_jumped

					_snake_case									=				sub_memo[c]

					# keep jumps sorted by # of terms skipped
					_snake_case									=				0
					while j < len(UpperCamelCase__						):
										if jumps[j][1] > dn:
															break
										j += 1

					# cache the jump for this value digitsum(b) and c
					sub_memo[c].insert(UpperCamelCase__       ,    (diff, dn, k)						)
					return (diff, dn)





def 						lowerCamelCase__     (     UpperCamelCase__			:       str       ,    UpperCamelCase__			:       str       ,    UpperCamelCase__			:       List[str]       ,    UpperCamelCase__			:       Union[str, Any]						)			-> Optional[Any]:



					'''simple docstring'''




					if i >= n:
										return 0, i
					if k > len(UpperCamelCase__						):
										a_i.extend([0 for _ in range(k - len(UpperCamelCase__						)						)]						)

					# note: a_i -> b * 10^k + c
					# ds_b -> digitsum(b)
					# ds_c -> digitsum(c)
					_snake_case									=				i
					_snake_case							,     _snake_case							,     _snake_case									=				0, 0, 0
					for j in range(len(UpperCamelCase__						)						):
										if j >= k:
															ds_b += a_i[j]
										else:
															ds_c += a_i[j]

					while i < n:
										i += 1
										_snake_case									=				ds_c + ds_b
										diff += addend
										_snake_case									=				0
										for j in range(UpperCamelCase__						):
															_snake_case									=				a_i[j] + addend
															_snake_case							,     _snake_case									=				divmod(UpperCamelCase__       ,    10						)

															ds_c += a_i[j]

										if addend > 0:
															break

					if addend > 0:
										add(UpperCamelCase__       ,    UpperCamelCase__       ,    UpperCamelCase__						)
					return diff, i - start_i





def 						lowerCamelCase__     (     UpperCamelCase__			:       Any       ,    UpperCamelCase__			:       Union[str, Any]       ,    UpperCamelCase__			:       Optional[Any]						)			-> Any:



					'''simple docstring'''




					for j in range(UpperCamelCase__       ,    len(UpperCamelCase__						)						):
										_snake_case									=				digits[j] + addend
										if s >= 10:
															_snake_case							,     _snake_case									=				divmod(UpperCamelCase__       ,    10						)
															_snake_case									=				addend // 10 + quotient
										else:
															_snake_case									=				s
															_snake_case									=				addend // 10

										if addend == 0:
															break

					while addend > 0:
										_snake_case							,     _snake_case									=				divmod(UpperCamelCase__       ,    10						)
										digits.append(UpperCamelCase__						)





def 						lowerCamelCase__     (     UpperCamelCase__			:       int = 10**15						)			-> int:



					'''simple docstring'''




					_snake_case									=				[1]
					_snake_case									=				1
					_snake_case									=				0
					while True:
										_snake_case							,     _snake_case									=				next_term(UpperCamelCase__       ,    20       ,    i + dn       ,    UpperCamelCase__						)
										dn += terms_jumped
										if dn == n - i:
															break

					_snake_case									=				0
					for j in range(len(UpperCamelCase__						)						):
										a_n += digits[j] * 10**j
					return a_n


if __name__ == "__main__":
					print(F"{solution() = }")










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


UpperCAmelCase_      							=     {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					):




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






					def 	lowerCAmelCase			(		self				,						lowerCAmelCase_  )		->							str:
										# Bx3x224x224 -> Bx2048x7x7 -> Bx2048xN -> BxNx2048
										_snake_case									=				self.pool(self.model(lowerCAmelCase_  )  )
										_snake_case									=				torch.flatten(lowerCAmelCase_				,						start_dim=2  )
										_snake_case									=				out.transpose(1				,						2  ).contiguous()
										return out  # BxNx2048





class 			UpperCamelCase_		(  _lowerCamelCase					):




					def __init__(		self				,						lowerCAmelCase_				,						lowerCAmelCase_				,						lowerCAmelCase_				,						lowerCAmelCase_				,						lowerCAmelCase_  )		->							Optional[Any]:
										_snake_case									=				[json.loads(lowerCAmelCase_  ) for l in open(lowerCAmelCase_  )]
										_snake_case									=				os.path.dirname(lowerCAmelCase_  )
										_snake_case									=				tokenizer
										_snake_case									=				labels
										_snake_case									=				len(lowerCAmelCase_  )
										_snake_case									=				max_seq_length

										_snake_case									=				transforms




					def __len__(		self  )		->							Any:
										return len(self.data  )




					def __getitem__(		self				,						lowerCAmelCase_  )		->							Optional[int]:
										_snake_case									=				torch.LongTensor(self.tokenizer.encode(self.data[index]['text']				,						add_special_tokens=lowerCAmelCase_  )  )
										_snake_case							,     _snake_case							,     _snake_case									=				sentence[0], sentence[1:-1], sentence[-1]
										_snake_case									=				sentence[: self.max_seq_length]

										_snake_case									=				torch.zeros(self.n_classes  )
										_snake_case									=				1

										_snake_case									=				Image.open(os.path.join(self.data_dir				,						self.data[index]['img']  )  ).convert('RGB'  )
										_snake_case									=				self.transforms(lowerCAmelCase_  )

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






					def 	lowerCAmelCase			(		self  )		->							Tuple:
										_snake_case									=				Counter()
										for row in self.data:
															label_freqs.update(row['label']  )
										return label_freqs





def 						lowerCamelCase__     (     UpperCamelCase__			:       str						)			-> Dict:



					'''simple docstring'''




					_snake_case									=				[len(row['sentence']						) for row in batch]
					_snake_case							,     _snake_case									=				len(UpperCamelCase__						), max(UpperCamelCase__						)

					_snake_case									=				torch.zeros(UpperCamelCase__       ,    UpperCamelCase__       ,    dtype=torch.long						)
					_snake_case									=				torch.zeros(UpperCamelCase__       ,    UpperCamelCase__       ,    dtype=torch.long						)

					for i_batch, (input_row, length) in enumerate(zip(UpperCamelCase__       ,    UpperCamelCase__						)						):
										_snake_case									=				input_row['sentence']
										_snake_case									=				1

					_snake_case									=				torch.stack([row['image'] for row in batch]						)
					_snake_case									=				torch.stack([row['label'] for row in batch]						)
					_snake_case									=				torch.stack([row['image_start_token'] for row in batch]						)
					_snake_case									=				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 						lowerCamelCase__     (     )			-> str:



					'''simple docstring'''




					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 						lowerCamelCase__     (     )			-> Tuple:



					'''simple docstring'''




					return transforms.Compose(
					    [
					        transforms.Resize(256						),
					        transforms.CenterCrop(224						),
					        transforms.ToTensor(),
					        transforms.Normalize(
					            mean=[0.4677_7044, 0.4453_1429, 0.4066_1017]       ,    std=[0.1222_1994, 0.1214_5835, 0.1438_0469]       ,    ),
					    ]						)



