https://www.acmicpc.net/problem/1932
import sys
input = sys.stdin.readline
n = int(input())
tri = []
for _ in range(n):
tri.append(list(map(int, input().split())))
res = [tri[0]]
for i in range(1, n):
temp = []
for j in range(len(tri[i])):
if j == 0:
temp.append(tri[i][j]+res[-1][0])
elif j == len(tri[i])-1:
temp.append(tri[i][j]+res[-1][-1])
else:
temp.append(tri[i][j]+max(res[-1][j], res[-1][j-1]))
res.append(temp)
print(max(res[-1]))