include[HTML_REMOVED]
using namespace std;
const int INF=0x3f3f3f;
int res=-INF;
int f[550][550];
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i)
{
for(int j=0;j<=n;j)
f[i][j]=-INF;
}
for(int i=1;i<=n;i)
{
for(int j=1;j<=i;j)
cin>>f[i][j];
}
for(int i=2;i<=n;i)
{
for(int j=1;j<=i;j){
f[i][j]=max(f[i-1][j],f[i-1][j-1])+f[i][j];
if(i==n)
res=max(res,f[i][j]);
} }
cout<<res<<endl;
return 0;
}