#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N =0;
int res[501][501]={-1,};
void func(int n, int j, int *tri[501]){
if (n==0){
res[n][j] = tri[n][j];
}
else if ((n < N) && (n>0)){
if ((j>0) && (j <= (n-1))){
if ((res[n-1][j-1]+ tri[n][j]) < (res[n-1][j]+ tri[n][j])){
res[n][j] = res[n-1][j]+ tri[n][j];
}
else{
res[n][j] = res[n-1][j-1]+ tri[n][j];
}
}
else if (j==0){
res[n][j] = res[n-1][j]+ tri[n][j];
}
else if (j==n){
res[n][j] = res[n-1][j-1]+ tri[n][j];
}
}
else{
return;
}
}
int main(){
cin >> N;
vector <int> v;
int** tri = new int*[N+1];
for (int i = 0; i < N; i++) {
tri[i] = new int[N+1];
fill_n(tri[i], N, 0);
for (int j = 0; j <= i; j++) {
cin >> tri[i][j];
}
}
for (int i = 0; i <= N-1; i++) {
for (int j = 0; j <= i; j++) {
func(i,j,tri);
}
}
int max = -1;
for (int j = 0; j < N; j++) {
if (max < res[N-1][j]) max=res[N-1][j];
}
cout << max << endl;
return 0;
}