
'''simple docstring'''



import os


def A (__lowerCamelCase :str = "input.txt"						):

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

						_lowerCAmelCase    		=					len(__lowerCamelCase						)
						_lowerCAmelCase    		=					len(matrix[0]						)

						_lowerCAmelCase    		=					[[-1 for _ in range(__lowerCamelCase						)] for _ in range(__lowerCamelCase						)]
						for i in range(__lowerCamelCase						):
												_lowerCAmelCase    		=					matrix[i][0]

						for j in range(1					,      __lowerCamelCase						):
												for i in range(__lowerCamelCase						):
																		_lowerCAmelCase    		=					minimal_path_sums[i][j - 1] + matrix[i][j]

												for i in range(1					,      __lowerCamelCase						):
																		_lowerCAmelCase    		=					min(
																		    minimal_path_sums[i][j]					,      minimal_path_sums[i - 1][j] + matrix[i][j]						)

												for i in range(rows - 2					,      -1					,      -1						):
																		_lowerCAmelCase    		=					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() = }""")


'''simple docstring'''



import functools


def A (__lowerCamelCase :list[int]					,      __lowerCamelCase :list[int]						):

						# Validation
						if not isinstance(__lowerCamelCase					,      __lowerCamelCase						) or not all(isinstance(__lowerCamelCase					,      __lowerCamelCase						) for day in days						):
												raise ValueError("""The parameter days should be a list of integers"""						)

						if len(__lowerCamelCase						) != 3 or not all(isinstance(__lowerCamelCase					,      __lowerCamelCase						) for cost in costs						):
												raise ValueError("""The parameter costs should be a list of three integers"""						)

						if len(__lowerCamelCase						) == 0:
												return 0

						if min(__lowerCamelCase						) <= 0:
												raise ValueError("""All days elements should be greater than 0"""						)

						if max(__lowerCamelCase						) >= 366:
												raise ValueError("""All days elements should be less than 366"""						)

						_lowerCAmelCase    		=					set(__lowerCamelCase						)

						@functools.cache
						def dynamic_programming(__lowerCamelCase :int						) -> int:
												if index > 365:
																		return 0

												if index not in days_set:
																		return dynamic_programming(index + 1						)

												return min(
												    costs[0] + dynamic_programming(index + 1						)					,      costs[1] + dynamic_programming(index + 7						)					,      costs[2] + dynamic_programming(index + 30						)					,      )

						return dynamic_programming(1						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
