
'''simple docstring'''







import os
import string
import sys


_lowercase :  str    							=       1 << 8

_lowercase :  Tuple    							=       {
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 2_7,
    "up": 6_5 + ARROW_KEY_FLAG,
    "down": 6_6 + ARROW_KEY_FLAG,
    "right": 6_7 + ARROW_KEY_FLAG,
    "left": 6_8 + ARROW_KEY_FLAG,
    "mod_int": 9_1,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 5_0,
    "delete": 5_1,
    "pg_up": 5_3,
    "pg_down": 5_4,
}

_lowercase :  List[str]    							=       KEYMAP["up"]
_lowercase :  Any    							=       KEYMAP["left"]

if sys.platform == "win32":
							_lowercase :  str    							=       []
							_lowercase :  List[str]    							=       {
							    B"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
							    B"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
							    B"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
							    B"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
							    B"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
							    B"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
							    B"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
							    B"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
							}

for i in range(1_0):
							_lowercase :  Any    							=       ord(str(i))
def 					snake_case_		(				):



						"""simple docstring"""





						if os.name == "nt":
												import msvcrt

												lowercase_	:     Dict													=       '''mbcs'''
												# Flush the keyboard buffer
												while msvcrt.kbhit():
																		msvcrt.getch()
												if len(__SCREAMING_SNAKE_CASE							) == 0:
																		# Read the keystroke
																		lowercase_	:     Optional[Any]													=       msvcrt.getch()

																		# If it is a prefix char, get second part
																		if ch in (b"\x00", b"\xe0"):
																								lowercase_	:     Any													=       ch + msvcrt.getch()
																								# Translate actual Win chars to bullet char types
																								try:
																														lowercase_	:     Tuple													=       chr(WIN_KEYMAP[cha]							)
																														WIN_CH_BUFFER.append(chr(KEYMAP['''mod_int''']							)							)
																														WIN_CH_BUFFER.append(__SCREAMING_SNAKE_CASE							)
																														if ord(__SCREAMING_SNAKE_CASE							) in (
																														    KEYMAP["insert"] - 1 << 9,
																														    KEYMAP["delete"] - 1 << 9,
																														    KEYMAP["pg_up"] - 1 << 9,
																														    KEYMAP["pg_down"] - 1 << 9,
																														):
																																				WIN_CH_BUFFER.append(chr(126							)							)
																														lowercase_	:     Dict													=       chr(KEYMAP['''esc''']							)
																								except KeyError:
																														lowercase_	:     Dict													=       cha[1]
																		else:
																								lowercase_	:     List[Any]													=       ch.decode(__SCREAMING_SNAKE_CASE							)
												else:
																		lowercase_	:     Any													=       WIN_CH_BUFFER.pop(0							)
						elif os.name == "posix":
												import termios
												import tty

												lowercase_	:     Dict													=       sys.stdin.fileno()
												lowercase_	:     List[Any]													=       termios.tcgetattr(__SCREAMING_SNAKE_CASE							)
												try:
																		tty.setraw(__SCREAMING_SNAKE_CASE							)
																		lowercase_	:     Tuple													=       sys.stdin.read(1							)
												finally:
																		termios.tcsetattr(__SCREAMING_SNAKE_CASE      ,      termios.TCSADRAIN      ,      __SCREAMING_SNAKE_CASE							)
						return ch




def 					snake_case_		(				):



						"""simple docstring"""





						lowercase_	:     Optional[int]													=       get_raw_chars()
						if ord(__SCREAMING_SNAKE_CASE							) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
												return char

						elif ord(__SCREAMING_SNAKE_CASE							) == KEYMAP["esc"]:
												lowercase_	:     str													=       get_raw_chars()
												if ord(__SCREAMING_SNAKE_CASE							) == KEYMAP["mod_int"]:
																		lowercase_	:     Dict													=       get_raw_chars()
																		if ord(__SCREAMING_SNAKE_CASE							) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(__SCREAMING_SNAKE_CASE							) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
																								return chr(ord(__SCREAMING_SNAKE_CASE							) + ARROW_KEY_FLAG							)
																		else:
																								return KEYMAP["undefined"]
												else:
																		return get_raw_chars()

						else:
												if char in string.printable:
																		return char
												else:
																		return KEYMAP["undefined"]








def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							if bit_count < 0:
														raise ValueError("The given input must be positive"  )

							# get the generated string sequence
							_lowerCAmelCase     :							List[str]    =    gray_code_sequence_string(_lowerCamelCase  )
							#
							# convert them to integers
							for i in range(len(_lowerCamelCase  )  ):
														_lowerCAmelCase     :							List[str]    =    int(sequence[i]				, 2  )

							return sequence






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							if bit_count == 0:
														return ["0"]

							if bit_count == 1:
														return ["0", "1"]

							_lowerCAmelCase     :							List[Any]    =    1 << bit_count  # defines the length of the sequence
							# 1<< n is equivalent to 2^n

							# recursive answer will generate answer for n-1 bits
							_lowerCAmelCase     :							Optional[int]    =    gray_code_sequence_string(bit_count - 1  )

							_lowerCAmelCase     :							str    =    []

							# append 0 to first half of the smaller sequence generated
							for i in range(seq_len // 2  ):
														_lowerCAmelCase     :							Dict    =    "0" + smaller_sequence[i]
														sequence.append(_lowerCamelCase  )

							# append 1 to second half ... start from the end of the list
							for i in reversed(range(seq_len // 2  )  ):
														_lowerCAmelCase     :							Optional[Any]    =    "1" + smaller_sequence[i]
														sequence.append(_lowerCamelCase  )

							return sequence


if __name__ == "__main__":
						import doctest

						doctest.testmod()
