



'''simple docstring'''



import os
def 					UpperCAmelCase   (						A  :				List[Any]				):
							SCREAMING_SNAKE_CASE					:      Dict     					=			len(grid[0]				)
							SCREAMING_SNAKE_CASE					:      Optional[int]     					=			len(A				)

							SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			0
							SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			0
							SCREAMING_SNAKE_CASE					:      Tuple     					=			0

							# Check vertically, horizontally, diagonally at the same time (only works
							# for nxn grid)
							for i in range(A				):
														for j in range(n_rows - 3				):
																					SCREAMING_SNAKE_CASE					:      List[Any]     					=			grid[j][i] * grid[j + 1][i] * grid[j + 2][i] * grid[j + 3][i]
																					SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			grid[i][j] * grid[i][j + 1] * grid[i][j + 2] * grid[i][j + 3]

																					# Left-to-right diagonal (\) product
																					if i < n_columns - 3:
																												SCREAMING_SNAKE_CASE					:      List[str]     					=			(
																												    grid[i][j]
																												    * grid[i + 1][j + 1]
																												    * grid[i + 2][j + 2]
																												    * grid[i + 3][j + 3]
																												)

																					# Right-to-left diagonal(/) product
																					if i > 2:
																												SCREAMING_SNAKE_CASE					:      int     					=			(
																												    grid[i][j]
																												    * grid[i - 1][j + 1]
																												    * grid[i - 2][j + 2]
																												    * grid[i - 3][j + 3]
																												)

																					SCREAMING_SNAKE_CASE					:      Tuple     					=			max(
																					    A					,		A					,		A					,		A				)
																					if max_product > largest:
																												SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			max_product

							return largest
def 					UpperCAmelCase   (						):
							SCREAMING_SNAKE_CASE					:      int     					=			[]
							with open(os.path.dirname(A				) + '''/grid.txt'''				) as file:
														for line in file:
																					grid.append(line.strip('''\n'''				).split(''' '''				)				)

							SCREAMING_SNAKE_CASE					:      Dict     					=			[[int(A				) for i in grid[j]] for j in range(len(A				)				)]

							return largest_product(A				)


if __name__ == "__main__":
							print(solution())









'''simple docstring'''



from bisect import bisect
from itertools import accumulate
def 					UpperCAmelCase   (						A  :				Tuple					,		A  :				Optional[Any]					,		A  :				Dict					,		A  :				Any				):
							SCREAMING_SNAKE_CASE					:      List[str]     					=			sorted(zip(A					,		A				)					,		key=lambda A				: x[0] / x[1]					,		reverse=A				)
							SCREAMING_SNAKE_CASE					,SCREAMING_SNAKE_CASE					:      Dict     					=			[i[0] for i in r], [i[1] for i in r]
							SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			list(accumulate(A				)				)
							SCREAMING_SNAKE_CASE					:      List[Any]     					=			bisect(A					,		A				)
							return (
							    0
							    if k == 0
							    else sum(vl[:k]				) + (w - acc[k - 1]) * (vl[k]) / (wt[k])
							    if k != n
							    else sum(vl[:k]				)
							)


if __name__ == "__main__":
							import doctest

							doctest.testmod()




