






'''simple docstring'''







import argparse
from collections import defaultdict

import yaml


UpperCamelCase    :      Optional[int]  			=		'docs/source/en/_toctree.yml'
def 						A__			(				__lowerCAmelCase		:			Union[str, Any]						):
						lowerCamelCase__         =  defaultdict(__lowerCAmelCase						)
						for doc in model_doc:
												counts[doc["local"]] += 1
						lowerCamelCase__         =  [key for key, value in counts.items() if value > 1]

						lowerCamelCase__         =  []
						for duplicate_key in duplicates:
												lowerCamelCase__         =  list({doc["""title"""] for doc in model_doc if doc["""local"""] == duplicate_key}						)
												if len(__lowerCAmelCase						) > 1:
																		raise ValueError(
																		    F'''{duplicate_key} is present several times in the documentation table of content at '''
																		    """`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the """
																		    """others."""						)
												# Only add this once
												new_doc.append({"""local""": duplicate_key, """title""": titles[0]}						)

						# Add none duplicate-keys
						new_doc.extend([doc for doc in model_doc if counts[doc["""local"""]] == 1]						)

						# Sort
						return sorted(__lowerCAmelCase   ,    key=lambda __lowerCAmelCase						: s["title"].lower()						)
def 						A__			(				__lowerCAmelCase		:			Dict=False						):
						with open(__lowerCAmelCase   ,    encoding="""utf-8"""						) as f:
												lowerCamelCase__         =  yaml.safe_load(f.read()						)

						# Get to the API doc
						lowerCamelCase__         =  0
						while content[api_idx]["title"] != "API":
												api_idx += 1
						lowerCamelCase__         =  content[api_idx]["""sections"""]

						# Then to the model doc
						lowerCamelCase__         =  0
						while api_doc[model_idx]["title"] != "Models":
												model_idx += 1

						lowerCamelCase__         =  api_doc[model_idx]["""sections"""]

						lowerCamelCase__         =  [(idx, section) for idx, section in enumerate(__lowerCAmelCase						) if """sections""" in section]
						lowerCamelCase__         =  False
						for idx, modality_doc in modalities_docs:
												lowerCamelCase__         =  modality_doc["""sections"""]
												lowerCamelCase__         =  clean_model_doc_toc(__lowerCAmelCase						)

												if old_modality_doc != new_modality_doc:
																		lowerCamelCase__         =  True
																		if overwrite:
																								lowerCamelCase__         =  new_modality_doc

						if diff:
												if overwrite:
																		lowerCamelCase__         =  model_doc
																		lowerCamelCase__         =  api_doc
																		with open(__lowerCAmelCase   ,    """w"""   ,    encoding="""utf-8"""						) as f:
																								f.write(yaml.dump(__lowerCAmelCase   ,    allow_unicode=__lowerCAmelCase						)						)
												else:
																		raise ValueError(
																		    """The model doc part of the table of content is not properly sorted, run `make style` to fix this."""						)


if __name__ == "__main__":
							UpperCamelCase    :      Dict  			=		argparse.ArgumentParser()
							parser.add_argument('--fix_and_overwrite', action='store_true', help='Whether to fix inconsistencies.')
							UpperCamelCase    :      str  			=		parser.parse_args()

							check_model_doc(args.fix_and_overwrite)









'''simple docstring'''







UpperCamelCase    :      Tuple  			=		[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(10_00_00)]
def 						A__			(				__lowerCAmelCase		:			int						):
						lowerCamelCase__         =  0
						while number:
												# Increased Speed Slightly by checking every 5 digits together.
												sum_of_digits_squared += DIGITS_SQUARED[number % 10_0000]
												number //= 10_0000

						return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
UpperCamelCase    :      list[bool | None]  			=		[None] * 10_00_00_00
UpperCamelCase    :      Tuple  			=		True
UpperCamelCase    :      Optional[int]  			=		False
def 						A__			(				__lowerCAmelCase		:			int						):

						if CHAINS[number - 1] is not None:
												return CHAINS[number - 1]  # type: ignore

						lowerCamelCase__         =  chain(next_number(__lowerCAmelCase						)						)
						lowerCamelCase__         =  number_chain

						while number < 1000_0000:
												lowerCamelCase__         =  number_chain
												number *= 10

						return number_chain
def 						A__			(				__lowerCAmelCase		:			int = 1000_0000						):
						for i in range(1   ,    __lowerCAmelCase						):
												if CHAINS[i] is None:
																		chain(i + 1						)

						return CHAINS[:number].count(__lowerCAmelCase						)


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							print(F'{solution() = }')

