if __name__=="__main__":
n=int(input())
res=[]
for x in range(0,n):
temp = [int(x) for x in input().split()]
res.append(temp)
m = len(res[-1])
dp = [[-0x3f3f3f3f for x in range(0,m+1)] for x in range(0,n+1)]
dp[1][1]=res[0][0]
for i in range(2,n+1):
for j in range(1,m+1):
if i>=j:
dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]) + res[i-1][j-1]
print(max(dp[-1]))