# Baekjoon-12100-2048 (Easy)

N = int(input())
board = []
for _ in range(N):
board.append(list(map(int,input().split())))

def rot(arr):
new_arr = []
for j in reversed(range(N)):
line = []
for i in range(N):
line.append(arr[i][j])
new_arr.append(line)
return new_arr

# 최대 5번 -> 4^5 = 2^10 = 1000개
def moveBlocks(board, dirs):
new_board = []
for _ in range(dirs):
board = rot(board)

for i in range(N):
new_line = [0] * N
new_idx = 0
for j in range(N):
if board[i][j] != 0:
if new_line[new_idx] == board[i][j]:
new_line[new_idx] *= 2
new_idx += 1
elif new_line[new_idx]==0:
new_line[new_idx] = board[i][j]
else:
new_idx += 1
new_line[new_idx] = board[i][j]
new_board.append(new_line)

max_num = 0
for i in range(N):
max_num = max(max_num, *new_board[i])

return new_board, max_num

def solve(count, board):
if count == 4:
max_result = 0
for dirs in range(4):
new_board, max_num = moveBlocks(board, dirs)
max_result = max(max_result, max_num)
return max_result
else:
max_result = 0
for dirs in range(4):
new_board, max_num = moveBlocks(board, dirs)
max_ = solve(count+1, new_board)
max_result = max(max_result, max_, max_num)
return max_result

print(solve(0,board))