#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	char c; int d,x=1,y=0;

	int dt[128][128]={0};
	while(cin >> d)
	{
		c=cin.get();

		dt[y][x]=d;
		if(c=='\n')
		{
			x=1; y++;
		}
		else
		{
			x++;
		}
	}

	int h=y;
	for(y=1; y<(h+1)/2; y++)
	for(x=1; x<y+2; x++)
	{
		dt[y][x] += max(dt[y-1][x-1],dt[y-1][x]);
	}

	for(; y<h; y++)
	for(x=1; x<h-y+1; x++)
	{
		dt[y][x] += max(dt[y-1][x],dt[y-1][x+1]);
	}
	
	cout << dt[h-1][1] << endl;
}