'''simple docstring'''



import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)






class 	UpperCamelCase__(       unittest.TestCase	):




				def 					a__(		self      :			Optional[int]				)->					int:

										"""simple docstring"""




										UpperCAmelCase					    =     ["a", "b", "c"]

										# Defaults to last layer if both are None
										UpperCAmelCase					    =     get_aligned_output_features_output_indices(_a				,   _a				,   _a				)
										self.assertEqual(_a				,   ['''c''']				)
										self.assertEqual(_a				,   [2]				)

										# Out indices set to match out features
										UpperCAmelCase					    =     get_aligned_output_features_output_indices(['''a''', '''c''']				,   _a				,   _a				)
										self.assertEqual(_a				,   ['''a''', '''c''']				)
										self.assertEqual(_a				,   [0, 2]				)

										# Out features set to match out indices
										UpperCAmelCase					    =     get_aligned_output_features_output_indices(_a				,   [0, 2]				,   _a				)
										self.assertEqual(_a				,   ['''a''', '''c''']				)
										self.assertEqual(_a				,   [0, 2]				)

										# Out features selected from negative indices
										UpperCAmelCase					    =     get_aligned_output_features_output_indices(_a				,   [-3, -1]				,   _a				)
										self.assertEqual(_a				,   ['''a''', '''c''']				)
										self.assertEqual(_a				,   [-3, -1]				)




				def 					a__(		self      :			str				)->					Tuple:

										"""simple docstring"""




										with self.assertRaises(_a				):
																verify_out_features_out_indices(['''a''', '''b''']				,   (0, 1)				,   _a				)

										# Out features must be a list
										with self.assertRaises(_a				):
																verify_out_features_out_indices(('''a''', '''b''')				,   (0, 1)				,   ['''a''', '''b''']				)

										# Out features must be a subset of stage names
										with self.assertRaises(_a				):
																verify_out_features_out_indices(['''a''', '''b''']				,   (0, 1)				,   ['''a''']				)

										# Out indices must be a list or tuple
										with self.assertRaises(_a				):
																verify_out_features_out_indices(_a				,   0				,   ['''a''', '''b''']				)

										# Out indices must be a subset of stage names
										with self.assertRaises(_a				):
																verify_out_features_out_indices(_a				,   (0, 1)				,   ['''a''']				)

										# Out features and out indices must be the same length
										with self.assertRaises(_a				):
																verify_out_features_out_indices(['''a''', '''b''']				,   (0,)				,   ['''a''', '''b''', '''c''']				)

										# Out features should match out indices
										with self.assertRaises(_a				):
																verify_out_features_out_indices(['''a''', '''b''']				,   (0, 2)				,   ['''a''', '''b''', '''c''']				)

										# Out features and out indices should be in order
										with self.assertRaises(_a				):
																verify_out_features_out_indices(['''b''', '''a''']				,   (0, 1)				,   ['''a''', '''b''']				)

										# Check passes with valid inputs
										verify_out_features_out_indices(['''a''', '''b''', '''d''']				,   (0, 1, -1)				,   ['''a''', '''b''', '''c''', '''d''']				)





				def 					a__(		self      :			Optional[int]				)->					Union[str, Any]:

										"""simple docstring"""




										UpperCAmelCase					    =     BackboneMixin()

										UpperCAmelCase					    =     ["a", "b", "c"]
										UpperCAmelCase					    =     ["a", "c"]
										UpperCAmelCase					    =     [0, 2]

										# Check that the output features and indices are set correctly
										self.assertEqual(backbone.out_features				,   ['''a''', '''c''']				)
										self.assertEqual(backbone.out_indices				,   [0, 2]				)

										# Check out features and indices are updated correctly
										UpperCAmelCase					    =     ["a", "b"]
										self.assertEqual(backbone.out_features				,   ['''a''', '''b''']				)
										self.assertEqual(backbone.out_indices				,   [0, 1]				)

										UpperCAmelCase					    =     [-3, -1]
										self.assertEqual(backbone.out_features				,   ['''a''', '''c''']				)
										self.assertEqual(backbone.out_indices				,   [-3, -1]				)









'''simple docstring'''



_lowercase      :      Any            =					range(2, 20 + 1)
_lowercase      :      str            =					[10**k for k in range(ks[-1] + 1)]
_lowercase      :      dict[int, dict[int, list[list[int]]]]            =					{}


def 				lowerCamelCase__				(	A       :      int				,       A       :      str				,       A       :      List[Any]				,       A       :      Union[str, Any]					):




						'''simple docstring'''






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

						UpperCAmelCase    ,    UpperCAmelCase					    =     0, 0
						UpperCAmelCase					    =     n - i

						UpperCAmelCase					    =     memo.get(A					)

						if sub_memo is not None:
												UpperCAmelCase					    =     sub_memo.get(A					)

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

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

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

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

						if k > ks[0]:
												while True:
																		# keep doing smaller jumps
																		UpperCAmelCase    ,    UpperCAmelCase					    =     next_term(A				,       k - 1				,       i + dn				,       A					)
																		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
												UpperCAmelCase    ,    UpperCAmelCase					    =     compute(A				,       A				,       i + dn				,       A					)
												diff += _diff
												dn += terms_jumped

						UpperCAmelCase					    =     sub_memo[c]

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

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


def 				lowerCamelCase__				(	A       :      Dict				,       A       :      Optional[int]				,       A       :      List[Any]				,       A       :      int					):




						'''simple docstring'''






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

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

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

																		ds_c += a_i[j]

												if addend > 0:
																		break

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


def 				lowerCamelCase__				(	A       :      List[str]				,       A       :      Optional[int]				,       A       :      Optional[Any]					):




						'''simple docstring'''






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

												if addend == 0:
																		break

						while addend > 0:
												UpperCAmelCase    ,    UpperCAmelCase					    =     divmod(A				,       10					)
												digits.append(A					)


def 				lowerCamelCase__				(	A       :      int = 10**15					):




						'''simple docstring'''






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

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


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





