#include <fstream.h>

int total = 0;
int max_total = 0;

int triangle[100][100];

int N;

void get_input()
{
   ifstream in("input.txt");

   in >> N;

   for(int row = 0; row < N; row++)
      for(int col = 0; col <= row; col++)
         in >> triangle[row][col];
}

void main()
{
   get_input();

   // Work through each row, adding the largest of the two numbers
   // below to this. Eventually the total will be at the top of the
   // triangle.
   for(int row = N - 2; row >=0; row--)
      for (int col = 0; col <= row; col++)
         if (triangle[row+1][col] > triangle[row+1][col+1])
            triangle[row][col] += triangle[row+1][col];
         else
            triangle[row][col] += triangle[row+1][col+1];

   cout << triangle[0][0] << endl;
}
