#include <iostream>
#include <fstream>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
    ifstream in("triangle.txt");
    deque<int> line;
    
    int n = 0, tmp;

    while (in >> tmp)
    {
#ifndef NDEBUG
	cout << " [" << tmp << "] ";
#endif

	if (!line.empty())
	    tmp += line.front();
	line.push_front(tmp);

	for (deque<int>::iterator it = line.begin() + 1; it != line.end(); ++it)
	{
	    in >> tmp;
#ifndef NDEBUG
	    cout << " [" << tmp << "] ";
#endif

	    if (it + 1 != line.end() && *(it + 1) > *it)
		*it = *(it + 1) + tmp;
	    else
		*it += tmp;
	}

#ifndef NDEBUG
	for (deque<int>::const_iterator it = line.begin(); it != line.end(); ++it)
	    cout << *it << (it + 1 == line.end() ? "\n" : " ");
#endif
    }

    cout << *max_element(line.begin(), line.end()) << endl;

    in.close();

    return 0;
}
