#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int main()
{
    int n;
    cin>>n;
    int c = 0;
    for(int i =1;i<=n;i++)
    {
        for(int j = 1;j<=i;j++)
        {
            cin >> a[i][j];
        }
    }
    // for(int i =1;i<=n;i++)
    // {
    //     for(int j = 1;j<=n;j++)
    //     {
    //         cout<< a[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    for(int i = n-1;i>=1;i--)
    {
        for(int j = 1;j<=i;j++)
        {
            if(a[i+1][j] > a[i+1][j+1])
            {
                a[i][j] = a[i][j] + a[i+1][j];
            }
            else
            {
                a[i][j] = a[i][j] + a[i+1][j+1];
            }
        }
    }
    //cout<<"cuhce";
    //cout<<endl;
    // for(int i =1;i<=n;i++)
    // {
    //     for(int j = 1;j<=n;j++)
    //     {
    //         cout<< a[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<a[1][1];
}
/**************************************************************
	Problem: 1216
	User: wuyichen
	Language: C++
	Result: Accepted
	Time:15 ms
	Memory:2116 kb
****************************************************************/