#include <bits/stdc++.h>
using namespace std;
int r,f[1005][1005];
int main(){
ios::sync_with_stdio(false);
cin>>r;
for(int i=1;i<=r;i++){
for(int j=1;j<=i;j++){
cin>>f[i][j];
}
}
for(int i=4;i>=1;i--){
for(int j=1;j<=i;j++){
if(f[i+1][j]>f[i+1][j+1]){
f[i][j]+=f[i+1][j];
}
else{
f[i][j]+=f[i+1][j+1];
}
}
}
cout<<f[1][1];
}
谢谢