



import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


UpperCAmelCase							 =					False
try:
	UpperCAmelCase							 =					_is_package_available("""google.colab""")
except ModuleNotFoundError:
	pass

@input.register
class  __snake_case      :







							'''simple docstring'''






							def __init__(							self  ,  a_ = None  ,  a_ = []		):
											a__				      =		0
											a__				      =		choices
											a__				      =		prompt
											if sys.platform == "win32":
															a__				      =		"*"
											else:
															a__				      =		"➔ "


							def _a      (							self  ,  a_  ,  a_ = ""		):



											if sys.platform != "win32":
															writeColor(self.choices[index]  ,  32  ,  __lowerCamelCase		)
											else:
															forceWrite(self.choices[index]  ,  __lowerCamelCase		)


							def _a      (							self  ,  a_		):



											if index == self.position:
															forceWrite(F''' {self.arrow_char} '''		)
															self.write_choice(__lowerCamelCase		)
											else:
															forceWrite(F'''    {self.choices[index]}'''		)
											reset_cursor()


							def _a      (							self  ,  a_  ,  a_ = 1		):
											a__				      =		self.position
											if direction == Direction.DOWN:
															if self.position + 1 >= len(self.choices		):
																			return
															self.position += num_spaces
											else:
															if self.position - 1 < 0:
																			return
															self.position -= num_spaces
											clear_line()
											self.print_choice(__lowerCamelCase		)
											move_cursor(__lowerCamelCase  ,  direction.name		)
											self.print_choice(self.position		)


							@input.mark(KEYMAP["""up"""]		)
							def _a      (							self		):
											self.move_direction(Direction.UP		)


							@input.mark(KEYMAP["""down"""]		)
							def _a      (							self		):
											self.move_direction(Direction.DOWN		)


							@input.mark(KEYMAP["""newline"""]		)
							def _a      (							self		):
											move_cursor(len(self.choices		) - self.position  ,  """DOWN"""		)
											return self.position


							@input.mark(KEYMAP["""interrupt"""]		)
							def _a      (							self		):
											move_cursor(len(self.choices		) - self.position  ,  """DOWN"""		)
											raise KeyboardInterrupt


							@input.mark_multiple(*[KEYMAP[str(__lowerCamelCase		)] for number in range(10		)]		)
							def _a      (							self		):
											a__				      =		int(chr(self.current_selection		)		)
											a__				      =		index - self.position
											if index == self.position:
															return
											if index < len(self.choices		):
															if self.position > index:
																			self.move_direction(Direction.UP  ,  -movement		)
															elif self.position < index:
																			self.move_direction(Direction.DOWN  ,  __lowerCamelCase		)
															else:
																			return
											else:
															return







							def _a      (							self  ,  a_ = 0		):



											if self.prompt:
															linebreak()
															forceWrite(self.prompt  ,  """\n"""		)
															if in_colab:
																			forceWrite("""Please input a choice index (starting from 0), and press enter"""  ,  """\n"""		)
															else:
																			forceWrite("""Please select a choice using the arrow or number keys, and selecting with enter"""  ,  """\n"""		)
											a__				      =		default_choice
											for i in range(len(self.choices		)		):
															self.print_choice(__lowerCamelCase		)
															forceWrite("""\n"""		)
											move_cursor(len(self.choices		) - self.position  ,  """UP"""		)
											with cursor.hide():
															while True:
																			if in_colab:
																							try:
																											a__				      =		int(builtins.input()		)
																							except ValueError:
																											a__				      =		default_choice
																			else:
																							a__				      =		self.handle_input()
																			if choice is not None:
																							reset_cursor()
																							for _ in range(len(self.choices		) + 1		):
																											move_cursor(1  ,  """UP"""		)
																											clear_line()
																							self.write_choice(__lowerCamelCase  ,  """\n"""		)
																							return choice






def 			A_      (	__a     :				Any		):

				"""simple docstring"""
				if not head:
								return True
				# split the list to two parts
				a__      ,			a__				      =		head.next, head
				while fast and fast.next:
								a__				      =		fast.next.next
								a__				      =		slow.next
				a__				      =		slow.next
				a__				      =		None  # Don't forget here! But forget still works!
				# reverse the second part
				a__				      =		None
				while second:
								a__				      =		second.next
								a__				      =		node
								a__				      =		second
								a__				      =		nxt
				# compare two parts
				# second part has the same or one less node
				while node:
								if node.val != head.val:
												return False
								a__				      =		node.next
								a__				      =		head.next
				return True

def 			A_      (	__a     :				int		):

				"""simple docstring"""
				if not head or not head.next:
								return True

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

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

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

				return True




def 			A_      (	__a     :				Any		):

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

