

UpperCAmelCase__ :     Any				    =    [sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(100_000)]






def 					__lowercase      (     _A			)     ->						int:
      SCREAMING_SNAKE_CASE :      Optional[Any]       =   0
      while number:
            # Increased Speed Slightly by checking every 5 digits together.
            sum_of_digits_squared += DIGITS_SQUARED[number % 100000]
            number //= 100000

      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_000_000
UpperCAmelCase__ :     Optional[int]				    =    True
UpperCAmelCase__ :     Optional[Any]				    =    False






def 					__lowercase      (     _A			)     ->						bool:

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

      SCREAMING_SNAKE_CASE :      Any       =   chain(next_number(_A			)			)
      SCREAMING_SNAKE_CASE :      Any       =   number_chain

      while number < 10000000:
            SCREAMING_SNAKE_CASE :      List[str]       =   number_chain
            number *= 10

      return number_chain






def 					__lowercase      (     _A = 10000000			)     ->						int:
      for i in range(1						,    _A			):
            if CHAINS[i] is None:
                  chain(i + 1			)

      return CHAINS[:number].count(_A			)


if __name__ == "__main__":
  import doctest

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







def 					__lowercase      (     _A			)     ->						list[int]:
      SCREAMING_SNAKE_CASE :      int       =   [0 for i in range(len(_A			)			)]

      # initialize interval's left pointer and right pointer
      SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      Dict       =   0, 0

      for i in range(1						,    len(_A			)			):
            # case when current index is inside the interval
            if i <= right_pointer:
                  SCREAMING_SNAKE_CASE :      Any       =   min(right_pointer - i + 1						,    z_result[i - left_pointer]			)
                  SCREAMING_SNAKE_CASE :      Optional[Any]       =   min_edge

            while go_next(_A						,    _A						,    _A			):
                  z_result[i] += 1

            # if new index's result gives us more right interval,
            # we've to update left_pointer and right_pointer
            if i + z_result[i] - 1 > right_pointer:
                  SCREAMING_SNAKE_CASE     ,	SCREAMING_SNAKE_CASE :      List[Any]       =   i, i + z_result[i] - 1

      return z_result






def 					__lowercase      (     _A						,    _A						,    _A			)     ->						bool:
      return i + z_result[i] < len(_A			) and s[z_result[i]] == s[i + z_result[i]]






def 					__lowercase      (     _A						,    _A			)     ->						int:
      SCREAMING_SNAKE_CASE :      Any       =   0
      # concatenate 'pattern' and 'input_str' and call z_function
      # with concatenated string
      SCREAMING_SNAKE_CASE :      List[Any]       =   z_function(pattern + input_str			)

      for val in z_result:
            # if value is greater then length of the pattern string
            # that means this index is starting position of substring
            # which is equal to pattern string
            if val >= len(_A			):
                  answer += 1

      return answer


if __name__ == "__main__":
  import doctest

  doctest.testmod()




