#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int f[1010][1010];
int maxint(int a,int b)
{
if (a>b)
return(a);
return(b);
}
int main(void)
{
freopen("numtri.in","r",stdin);
freopen("numtri.out","w",stdout);
int n,i,j;
cin>>n;
for (i=1;i<=n;i++)
for (j=1;j<=i;j++)
cin>>f[i][j];
for (i=n-1;i>=1;i--)
{
for (j=1;j<=i;j++)
f[i][j]+=maxint(f[i+1][j],f[i+1][j+1]);
}
cout<<f[1][1]<<endl;
return(0);
}