import sys
input = sys.stdin.readline
N = int(input())
inp_lst = list(map(int, input().split()))
if N == 1:
print(inp_lst[0])
exit()
for i in range(2, N+1):
new_inp = list(map(int, input().split()))
new_inp[0] += inp_lst[0]
for j in range(1, i-1):
new_inp[j] += max(inp_lst[j-1], inp_lst[j])
new_inp[-1] += inp_lst[-1]
inp_lst = new_inp
print(max(new_inp))