
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
#include <ctime>
#define INT long long
#define MOD 1000000007
#define oo 978654321
#define PP pair<INT, pair<INT, INT> >
#define OO 9999999987654321ll
using namespace std;
int n, h[210][210];
map<string, int> dt[210][210];
int dp(int x, int y, string st)
{
    if( x == n ) return 0;
    if( dt[x][y][st] ) return dt[x][y][st];
    int &ret = dt[x][y][st];
    string nt = "";
    for(int i = 0 ; i < st.size() ; i++ )
        if( st[i] > (h[x][y]-'0') ) nt += st[i], ret++;
    nt += h[x][y]-'0';
    return ret += max( dp(x+1, y, nt), dp(x+1, y+1, nt) );
}
int main()
{
	ios::sync_with_stdio(false);
	srand(time(NULL));
	freopen(".26.in","r",stdin);
	freopen(".26.out","w",stdout);
	//freopen(".25.in","w",stdout);
	cin>>n;
/*	cout<<n<<endl;
	for(int i = 0, p = 0 ; i < n ; i++, p--, cout<<endl ) for(int j = 0 ; j <= i ; j++)
    {
        if( p == 0 ) p = 10;
        cout<<(rand()%10+1)<<" ";
    }
    return 0;*/
	for(int i = 0 ; i < n ; i++ ) for(int j = 0 ; j <= i ; j++ ) cin>>h[i][j], h[i][j]--;
    cout<<dp(0, 0, "")<<endl;
    return 0;
}
