





import os
import string
import sys


lowerCAmelCase__  :List[str]             =							1 << 8

lowerCAmelCase__  :Any             =							{
    """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,
}

lowerCAmelCase__  :Any             =							KEYMAP["""up"""]
lowerCAmelCase__  :Tuple             =							KEYMAP["""left"""]

if sys.platform == "win32":
		lowerCAmelCase__  :Tuple             =							[]
		lowerCAmelCase__  :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):
		lowerCAmelCase__  :str             =							ord(str(i))

def 	lowerCAmelCase__			(      )  ->		Optional[Any]:


							'''simple docstring'''





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

														_UpperCAmelCase					=      'mbcs'
														# Flush the keyboard buffer
														while msvcrt.kbhit():
																					msvcrt.getch()
														if len(SCREAMING_SNAKE_CASE_	) == 0:
																					# Read the keystroke
																					_UpperCAmelCase					=      msvcrt.getch()

																					# If it is a prefix char, get second part
																					if ch in (b"\x00", b"\xe0"):
																												_UpperCAmelCase					=      ch + msvcrt.getch()
																												# Translate actual Win chars to bullet char types
																												try:
																																			_UpperCAmelCase					=      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(1_2_6	)	)
																																			_UpperCAmelCase					=      chr(KEYMAP['esc']	)
																												except KeyError:
																																			_UpperCAmelCase					=      cha[1]
																					else:
																												_UpperCAmelCase					=      ch.decode(SCREAMING_SNAKE_CASE_	)
														else:
																					_UpperCAmelCase					=      WIN_CH_BUFFER.pop(0	)
							elif os.name == "posix":
														import termios
														import tty

														_UpperCAmelCase					=      sys.stdin.fileno()
														_UpperCAmelCase					=      termios.tcgetattr(SCREAMING_SNAKE_CASE_	)
														try:
																					tty.setraw(SCREAMING_SNAKE_CASE_	)
																					_UpperCAmelCase					=      sys.stdin.read(1	)
														finally:
																					termios.tcsetattr(SCREAMING_SNAKE_CASE_      ,  termios.TCSADRAIN      ,  SCREAMING_SNAKE_CASE_	)
							return ch







def 	lowerCAmelCase__			(      )  ->		List[Any]:


							'''simple docstring'''





							_UpperCAmelCase					=      get_raw_chars()
							if ord(SCREAMING_SNAKE_CASE_	) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
														return char

							elif ord(SCREAMING_SNAKE_CASE_	) == KEYMAP["esc"]:
														_UpperCAmelCase					=      get_raw_chars()
														if ord(SCREAMING_SNAKE_CASE_	) == KEYMAP["mod_int"]:
																					_UpperCAmelCase					=      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 	lowerCAmelCase__			(      a__:		int	)  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      generate_pascal_triangle(a__	)
							for row_idx in range(a__	):
														# Print left spaces
														for _ in range(num_rows - row_idx - 1	):
																					print(end=' '	)
														# Print row values
														for col_idx in range(row_idx + 1	):
																					if col_idx != row_idx:
																												print(triangle[row_idx][col_idx]      ,  end=' '	)
																					else:
																												print(triangle[row_idx][col_idx]      ,  end=''	)
														print()

def 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														raise TypeError('The input value of \'num_rows\' should be \'int\''	)

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'	)

							_UpperCAmelCase					=      []
							for current_row_idx in range(a__	):
														_UpperCAmelCase					=      populate_current_row(a__      ,  a__	)
														triangle.append(a__	)
							return triangle

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		int	)  ->		list[int]:


							'''simple docstring'''





							_UpperCAmelCase					=      [-1] * (current_row_idx + 1)
							# first and last elements of current row are equal to 1
							_UpperCAmelCase		,	_UpperCAmelCase					=      1, 1
							for current_col_idx in range(1      ,  a__	):
														calculate_current_element(
														    a__      ,  a__      ,  a__      ,  a__	)
							return current_row

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		list[int]      ,  a__:		int      ,  a__:		int      ,  )  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx - 1]
							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx]
							_UpperCAmelCase					=      above_to_left_elt + above_to_right_elt

def 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														raise TypeError('The input value of \'num_rows\' should be \'int\''	)

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    'The input value of \'num_rows\' should be greater than or equal to 0'	)

							_UpperCAmelCase					=      [[1]]

							for row_index in range(1      ,  a__	):
														_UpperCAmelCase					=      [0] + result[-1] + [0]
														_UpperCAmelCase					=      row_index + 1
														# Calculate the number of distinct elements in a row
														_UpperCAmelCase					=      sum(divmod(a__      ,  2	)	)
														_UpperCAmelCase					=      [
														    temp_row[i - 1] + temp_row[i] for i in range(1      ,  distinct_elements + 1	)
														]
														_UpperCAmelCase					=      row_first_half[: (row_index + 1) // 2]
														row_second_half.reverse()
														_UpperCAmelCase					=      row_first_half + row_second_half
														result.append(a__	)

							return result

def 	lowerCAmelCase__			(      )  ->		None:


							'''simple docstring'''





							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(a__:		Callable      ,  a__:		int	) -> None:
														_UpperCAmelCase					=      F'''{func.__name__}({value})'''
														_UpperCAmelCase					=      timeit(F'''__main__.{call}'''      ,  setup='import __main__'	)
														# print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
														print(F'''{call:38} -- {timing:.4f} seconds'''	)

							for value in range(1_5	):  # (1, 7, 14):
														for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
																					benchmark_a_function(a__      ,  a__	)
														print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()
