


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


A   :					List[str]	=      False
try:
				A   :					List[Any]	=      _is_package_available("google.colab")
except ModuleNotFoundError:
				pass







@input.register
class     _lowercase				:


							"""simple docstring"""




							def __init__(     self							:    str      ,   __lowerCamelCase							:    Optional[Any] = None      ,   __lowerCamelCase							:    Dict = [] ):


													'''simple docstring'''



													lowerCamelCase__	:       Union[str, Any]					=						0
													lowerCamelCase__	:       Any					=						choices
													lowerCamelCase__	:       int					=						prompt
													if sys.platform == "win32":
																			lowerCamelCase__	:       str					=						"*"
													else:
																			lowerCamelCase__	:       Optional[Any]					=						"➔ "





							def 		lowerCAmelCase  (     self							:    Optional[Any]      ,   __lowerCamelCase							:    List[str]      ,   __lowerCamelCase							:    Union[str, Any] = "" ):


													'''simple docstring'''



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





							def 		lowerCAmelCase  (     self							:    List[str]      ,   __lowerCamelCase							:    Dict ):


													'''simple docstring'''



													if index == self.position:
																			forceWrite(f" {self.arrow_char} " )
																			self.write_choice(__a )
													else:
																			forceWrite(f"    {self.choices[index]}" )
													reset_cursor()





							def 		lowerCAmelCase  (     self							:    str      ,   __lowerCamelCase							:    int      ,   __lowerCamelCase							:    List[str] = 1 ):


													'''simple docstring'''



													lowerCamelCase__	:       str					=						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(__a )
													move_cursor(__a      ,   direction.name )
													self.print_choice(self.position )





							@input.mark(KEYMAP["up"] )
							def 		lowerCAmelCase  (     self							:    Dict ):


													'''simple docstring'''



													self.move_direction(Direction.UP )





							@input.mark(KEYMAP["down"] )
							def 		lowerCAmelCase  (     self							:    List[str] ):


													'''simple docstring'''



													self.move_direction(Direction.DOWN )





							@input.mark(KEYMAP["newline"] )
							def 		lowerCAmelCase  (     self							:    Any ):


													'''simple docstring'''



													move_cursor(len(self.choices ) - self.position      ,   "DOWN" )
													return self.position





							@input.mark(KEYMAP["interrupt"] )
							def 		lowerCAmelCase  (     self							:    Any ):


													'''simple docstring'''



													move_cursor(len(self.choices ) - self.position      ,   "DOWN" )
													raise KeyboardInterrupt





							@input.mark_multiple(*[KEYMAP[str(__a )] for number in range(10 )] )
							def 		lowerCAmelCase  (     self							:    Optional[int] ):


													'''simple docstring'''



													lowerCamelCase__	:       Any					=						int(chr(self.current_selection ) )
													lowerCamelCase__	:       int					=						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      ,   __a )
																			else:
																									return
													else:
																			return





							def 		lowerCAmelCase  (     self							:    List[str]      ,   __lowerCamelCase							:    List[str] = 0 ):


													'''simple docstring'''



													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" )
													lowerCamelCase__	:       str					=						default_choice
													for i in range(len(self.choices ) ):
																			self.print_choice(__a )
																			forceWrite("\n" )
													move_cursor(len(self.choices ) - self.position      ,   "UP" )
													with cursor.hide():
																			while True:
																									if in_colab:
																															try:
																																					lowerCamelCase__	:       Optional[int]					=						int(builtins.input() )
																															except ValueError:
																																					lowerCamelCase__	:       Optional[int]					=						default_choice
																									else:
																															lowerCamelCase__	:       Dict					=						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(__a      ,   "\n" )
																															return choice






import os

def    lowercase_	(	_A    :					str = "input.txt"		):

      """simple docstring"""




      with open(os.path.join(os.path.dirname(_A		)					,      _A		)		) as input_file:
            lowerCamelCase__	:       List[Any]					=						[
                [int(_A		) for element in line.split(","		)]
                for line in input_file.readlines()
            ]

      lowerCamelCase__	:       Optional[Any]					=						len(_A		)
      lowerCamelCase__	:       Union[str, Any]					=						len(matrix[0]		)

      lowerCamelCase__	:       Union[str, Any]					=						[[-1 for _ in range(_A		)] for _ in range(_A		)]
      for i in range(_A		):
            lowerCamelCase__	:       Optional[Any]					=						matrix[i][0]

      for j in range(1					,      _A		):
            for i in range(_A		):
                  lowerCamelCase__	:       int					=						minimal_path_sums[i][j - 1] + matrix[i][j]

            for i in range(1					,      _A		):
                  lowerCamelCase__	:       Tuple					=						min(
                      minimal_path_sums[i][j]					,      minimal_path_sums[i - 1][j] + matrix[i][j]		)

            for i in range(rows - 2					,      -1					,      -1		):
                  lowerCamelCase__	:       str					=						min(
                      minimal_path_sums[i][j]					,      minimal_path_sums[i + 1][j] + matrix[i][j]		)

      return min(minimal_path_sums_row[-1] for minimal_path_sums_row in minimal_path_sums		)


if __name__ == "__main__":
    print(f'{solution() = }')


