"""simple docstring"""






from __future__ import annotations

from typing import Any

class lowerCamelCase		(_SCREAMING_SNAKE_CASE      ):






					'''simple docstring'''


					pass



class lowerCamelCase		:






					'''simple docstring'''


					def __init__(						self			:				Union[str, Any]   , _snake_case			:				List[str]		)							->       None:
									SCREAMING_SNAKE_CASE__		  =				data
									SCREAMING_SNAKE_CASE__		  =				None



					def __iter__(						self			:				Any		)							->       Tuple:
									SCREAMING_SNAKE_CASE__		  =				self
									SCREAMING_SNAKE_CASE__		  =				[]
									while node:
													if node in visited:
																	raise ContainsLoopError
													visited.append(UpperCamelCase__		)
													yield node.data
													SCREAMING_SNAKE_CASE__		  =				node.next_node



					@property
					def 			lowerCAmelCase_					(						self			:				Dict		)							->       bool:





									try:
													list(self		)
													return False
									except ContainsLoopError:
													return True


if __name__ == "__main__":
						_A   					=    Node(1)
						_A   					=    Node(2)
						_A   					=    Node(3)
						_A   					=    Node(4)
						print(root_node.has_loop)  # False
						_A   					=    root_node.next_node
						print(root_node.has_loop)  # True

						_A   					=    Node(5)
						_A   					=    Node(6)
						_A   					=    Node(5)
						_A   					=    Node(6)
						print(root_node.has_loop)  # False

						_A   					=    Node(1)
						print(root_node.has_loop)  # False





"""simple docstring"""






def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   List[str]:
				if not head:
								return True
				# split the list to two parts
				SCREAMING_SNAKE_CASE__  ,       SCREAMING_SNAKE_CASE__		  =				head.next, head
				while fast and fast.next:
								SCREAMING_SNAKE_CASE__		  =				fast.next.next
								SCREAMING_SNAKE_CASE__		  =				slow.next
				SCREAMING_SNAKE_CASE__		  =				slow.next
				SCREAMING_SNAKE_CASE__		  =				None  # Don't forget here! But forget still works!
				# reverse the second part
				SCREAMING_SNAKE_CASE__		  =				None
				while second:
								SCREAMING_SNAKE_CASE__		  =				second.next
								SCREAMING_SNAKE_CASE__		  =				node
								SCREAMING_SNAKE_CASE__		  =				second
								SCREAMING_SNAKE_CASE__		  =				nxt
				# compare two parts
				# second part has the same or one less node
				while node:
								if node.val != head.val:
												return False
								SCREAMING_SNAKE_CASE__		  =				node.next
								SCREAMING_SNAKE_CASE__		  =				head.next
				return True




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   str:
				if not head or not head.next:
								return True

				# 1. Get the midpoint (slow)
				SCREAMING_SNAKE_CASE__		  =				SCREAMING_SNAKE_CASE__		  =				SCREAMING_SNAKE_CASE__		  =				head
				while fast and fast.next:
								SCREAMING_SNAKE_CASE__  ,       SCREAMING_SNAKE_CASE__		  =				fast.next.next, slow.next

				# 2. Push the second half into the stack
				SCREAMING_SNAKE_CASE__		  =				[slow.val]
				while slow.next:
								SCREAMING_SNAKE_CASE__		  =				slow.next
								stack.append(slow.val       )

				# 3. Comparison
				while stack:
								if stack.pop() != cur.val:
												return False
								SCREAMING_SNAKE_CASE__		  =				cur.next

				return True




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   str:
				if not head or not head.next:
								return True
				SCREAMING_SNAKE_CASE__		  =				{}
				SCREAMING_SNAKE_CASE__		  =				0
				while head:
								if head.val in d:
												d[head.val].append(__UpperCAmelCase       )
								else:
												SCREAMING_SNAKE_CASE__		  =				[pos]
								SCREAMING_SNAKE_CASE__		  =				head.next
								pos += 1
				SCREAMING_SNAKE_CASE__		  =				pos - 1
				SCREAMING_SNAKE_CASE__		  =				0
				for v in d.values():
								if len(__UpperCAmelCase       ) % 2 != 0:
												middle += 1
								else:
												SCREAMING_SNAKE_CASE__		  =				0
												for i in range(0  ,					len(__UpperCAmelCase       )       ):
																if v[i] + v[len(__UpperCAmelCase       ) - 1 - step] != checksum:
																				return False
																step += 1
								if middle > 1:
												return False
				return True




