





'''simple docstring'''






A__				:   Union[str, Any]      =[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(10_00_00)]
def    UpperCamelCase__      (		lowerCAmelCase  ):





      """simple docstring"""


      _lowerCAmelCase							     =							0
      while number:
            # Increased Speed Slightly by checking every 5 digits together.
            sum_of_digits_squared += DIGITS_SQUARED[number % 10_00_00]
            number //= 10_00_00

      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
A__				:   list[bool | None]      =[None] * 10_00_00_00
A__				:   Union[str, Any]      =True
A__				:   int      =False
def    UpperCamelCase__      (		lowerCAmelCase  ):





      """simple docstring"""


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

      _lowerCAmelCase							     =							chain(next_number(lowerCAmelCase  )  )
      _lowerCAmelCase							     =							number_chain

      while number < 10_00_00_00:
            _lowerCAmelCase							     =							number_chain
            number *= 10

      return number_chain
def    UpperCamelCase__      (		lowerCAmelCase = 10_00_00_00  ):





      """simple docstring"""


      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() = }""")








from __future__ import annotations




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			list[list[int]])					->    bool:






							'''simple docstring'''





							__UpperCamelCase	:   Any			   =					len(_lowerCamelCase)
							# We need to create solution object to save path.
							__UpperCamelCase	:   List[str]			   =					[[0 for _ in range(_lowerCamelCase)] for _ in range(_lowerCamelCase)]
							__UpperCamelCase	:   Optional[int]			   =					run_maze(_lowerCamelCase						,  0						,  0						,  _lowerCamelCase)
							if solved:
														print("\n".join(str(_lowerCamelCase) for row in solutions))
							else:
														print("No solution exists!")
							return solved




def 	_SCREAMING_SNAKE_CASE					(		_lowerCamelCase :			list[list[int]]						,  _lowerCamelCase :			int						,  _lowerCamelCase :			int						,  _lowerCamelCase :			list[list[int]])					->    bool:






							'''simple docstring'''





							__UpperCamelCase	:   Tuple			   =					len(_lowerCamelCase)
							# Final check point.
							if i == j == (size - 1):
														__UpperCamelCase	:   Optional[int]			   =					1
														return True

							__UpperCamelCase	:   List[Any]			   =					(not i < 0) and (not j < 0)  # Check lower bounds
							__UpperCamelCase	:   List[str]			   =					(i < size) and (j < size)  # Check upper bounds

							if lower_flag and upper_flag:
														# check for already visited and block points.
														__UpperCamelCase	:   int			   =					(not solutions[i][j]) and (not maze[i][j])
														if block_flag:
																					# check visited
																					__UpperCamelCase	:   Tuple			   =					1

																					# check for directions
																					if (
																					    run_maze(_lowerCamelCase						,  i + 1						,  _lowerCamelCase						,  _lowerCamelCase)
																					    or run_maze(_lowerCamelCase						,  _lowerCamelCase						,  j + 1						,  _lowerCamelCase)
																					    or run_maze(_lowerCamelCase						,  i - 1						,  _lowerCamelCase						,  _lowerCamelCase)
																					    or run_maze(_lowerCamelCase						,  _lowerCamelCase						,  j - 1						,  _lowerCamelCase)
																					):
																												return True

																					__UpperCamelCase	:   Tuple			   =					0
																					return False
							return False


if __name__ == "__main__":
		import doctest

		doctest.testmod()