#include<iostream>
#include<algorithm>
#include<ctime>
using namespace std;
#define N 101
int D[N][N];
int MAX[N][N];
int n;
int getmax(int i,int j)
{
if (MAX[i][j] != -1)
{
return MAX[i][j];
}
if (i == n)
{
MAX[i][j] = D[i][j];
}
else
{
MAX[i+1][j] = getmax(i + 1, j);
MAX[i+1][j+1] = getmax(i + 1, j + 1);
return max(MAX[i + 1][j], MAX[i + 1][j + 1]) + D[i][j];
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
D[i][j] = rand() % 100;
MAX[i][j] = -1;
cout << D[i][j]<<" ";
}
cout << endl;
}
cout << getmax(1, 1) << endl;
return 0;
}