/*
ID:superlo1
LANG:C++
TASK:numtri
*/
#include <stdio.h>
#include <string.h>
int triangle[1001][1001], r;
inline int getmax(int a, int b){
return a > b ? a : b;
}
int main(){
freopen("numtri.in","r",stdin);
freopen("numtri.out","w",stdout);
scanf("%d", &r);
for(int i = 0; i < r; i ++){
for(int j = 0; j <= i; j ++){
scanf("%d", &triangle[i][j]);
}
}
for(int i = 1; i < r; i ++){
for(int j = 0; j <= i; j ++){
if(j == 0)
triangle[i][j] += triangle[i-1][j];
else if(j == i)
triangle[i][j] += triangle[i-1][j-1];
else
triangle[i][j] += getmax(triangle[i-1][j], triangle[i-1][j-1]);
}
}
int ans = 0;
for(int i = 0; i < r; i ++){
ans = getmax(ans, triangle[r-1][i]);
}
printf("%d\n", ans);
}