
'''simple docstring'''







class  lowerCAmelCase__   :






					def __init__(   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE=None				,							__SCREAMING_SNAKE_CASE=None		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       data
											lowercase_	:     List[Any]													=       previous
											lowercase_	:     int													=       next_node






					def __str__(   self		):


											"""simple docstring"""





											return F'''{self.data}'''






					def 	_snake_case    (   self		):


											"""simple docstring"""





											return self.data






					def 	_snake_case    (   self		):


											"""simple docstring"""





											return self.next






					def 	_snake_case    (   self		):


											"""simple docstring"""





											return self.previous







class  lowerCAmelCase__   :






					def __init__(   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Any													=       head






					def __iter__(   self		):


											"""simple docstring"""





											return self






					def 	_snake_case    (   self		):


											"""simple docstring"""





											if not self.current:
																	raise StopIteration
											else:
																	lowercase_	:     Union[str, Any]													=       self.current.get_data()
																	lowercase_	:     Optional[Any]													=       self.current.get_next()
																	return value







class  lowerCAmelCase__   :






					def __init__(   self		):


											"""simple docstring"""





											lowercase_	:     Dict													=       None  # First node in list
											lowercase_	:     Optional[int]													=       None  # Last node in list






					def __str__(   self		):


											"""simple docstring"""





											lowercase_	:     Any													=       self.head
											lowercase_	:     List[Any]													=       []
											while current is not None:
																	nodes.append(current.get_data()		)
																	lowercase_	:     str													=       current.get_next()
											return " ".join(str(__SCREAMING_SNAKE_CASE		) for node in nodes		)






					def __contains__(   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       self.head
											while current:
																	if current.get_data() == value:
																							return True
																	lowercase_	:     int													=       current.get_next()
											return False






					def __iter__(   self		):


											"""simple docstring"""





											return LinkedListIterator(self.head		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											if self.head:
																	return self.head.get_data()
											return None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											if self.tail:
																	return self.tail.get_data()
											return None






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if self.head is None:
																	lowercase_	:     int													=       node
																	lowercase_	:     List[Any]													=       node
											else:
																	self.insert_before_node(self.head				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if self.head is None:
																	self.set_head(__SCREAMING_SNAKE_CASE		)
											else:
																	self.insert_after_node(self.tail				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Dict													=       Node(__SCREAMING_SNAKE_CASE		)
											if self.head is None:
																	self.set_head(__SCREAMING_SNAKE_CASE		)
											else:
																	self.set_tail(__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Dict													=       node
											lowercase_	:     List[str]													=       node.previous

											if node.get_previous() is None:
																	lowercase_	:     Union[str, Any]													=       node_to_insert
											else:
																	lowercase_	:     Optional[Any]													=       node_to_insert

											lowercase_	:     Any													=       node_to_insert






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       node
											lowercase_	:     Dict													=       node.next

											if node.get_next() is None:
																	lowercase_	:     Union[str, Any]													=       node_to_insert
											else:
																	lowercase_	:     Any													=       node_to_insert

											lowercase_	:     Union[str, Any]													=       node_to_insert






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     List[str]													=       1
											lowercase_	:     Tuple													=       Node(__SCREAMING_SNAKE_CASE		)
											lowercase_	:     Dict													=       self.head
											while node:
																	if current_position == position:
																							self.insert_before_node(__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		)
																							return
																	current_position += 1
																	lowercase_	:     List[Any]													=       node.next
											self.insert_after_node(self.tail				,							__SCREAMING_SNAKE_CASE		)






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											lowercase_	:     Optional[Any]													=       self.head
											while node:
																	if node.get_data() == item:
																							return node
																	lowercase_	:     Tuple													=       node.get_next()
											raise Exception('''Node not found'''		)






					def 	_snake_case    (   self				,							__SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if (node := self.get_node(__SCREAMING_SNAKE_CASE		)) is not None:
																	if node == self.head:
																							lowercase_	:     Union[str, Any]													=       self.head.get_next()

																	if node == self.tail:
																							lowercase_	:     List[Any]													=       self.tail.get_previous()

																	self.remove_node_pointers(__SCREAMING_SNAKE_CASE		)






					@staticmethod
					def 	_snake_case    (   __SCREAMING_SNAKE_CASE		):


											"""simple docstring"""





											if node.get_next():
																	lowercase_	:     str													=       node.previous

											if node.get_previous():
																	lowercase_	:     List[Any]													=       node.next

											lowercase_	:     Optional[Any]													=       None
											lowercase_	:     Dict													=       None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											return self.head is None







def 					snake_case_		(				):



						"""simple docstring"""







if __name__ == "__main__":
							import doctest

							doctest.testmod()





'''simple docstring'''







_lowercase :  int    							=       [sum(int(c, 1_0) ** 2 for c in i.__str__()) for i in range(1_0_0_0_0_0)]
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						lowercase_	:     Optional[int]													=       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
_lowercase :  list[bool | None]    							=       [None] * 1_0_0_0_0_0_0_0
_lowercase :  List[str]    							=       True
_lowercase :  Optional[int]    							=       False
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





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

						lowercase_	:     Tuple													=       chain(next_number(__SCREAMING_SNAKE_CASE							)							)
						lowercase_	:     Union[str, Any]													=       number_chain

						while number < 10000000:
												lowercase_	:     int													=       number_chain
												number *= 10

						return number_chain
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int = 10000000							):



						"""simple docstring"""





						for i in range(1      ,      __SCREAMING_SNAKE_CASE							):
												if CHAINS[i] is None:
																		chain(i + 1							)

						return CHAINS[:number].count(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							import doctest

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



