#include <iostream>
#include <string>

using namespace std;
int dp[101][51];
int data[101][51];

void solve()
{
	string str;
	string sdata[51];
	int temp;
	int line = 0;
	int pos = 0;
	while(cin >> str)
	{
		pos = 0;
		int size = str.size();
		for(int i = 0; i < size; ++i)
		{
			if(str[i] == ',')
			{
				pos++;
				continue;
			}
			sdata[pos] += str[i];
		}
		pos++;
		
		for(int i = 0; i < pos; ++i)
		{
			int temp = 1;
			size = sdata[i].size();
			for(int j = size - 1; j >= 0; --j)
			{
				data[line][i] += (sdata[i][j] - '0') * temp;
				temp *= 10;
			}
		}
		line++;
		for(int i = 0;i < pos; ++i)
		{
			sdata[i].clear();
		}
	}
	dp[0][0] = data[0][0];
	for(int i = 1; i < line / 2 + 1; ++i)
	{
		for(int j = 0; j <= i; ++j)
		{
			if(j == 0)
			{
				dp[i][j] = dp[i - 1][j] + data[i][j];
			}
			else if(j == i)
			{
				dp[i][j] = dp[i - 1][j - 1] + data[i][j];
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + data[i][j];
			}
		}
	}
	for(int i = line / 2 + 1; i < line; ++i)
	{
		for(int j = 0; j < line - i; ++j)
		{
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + data[i][j];
		}
	}
	cout << dp[line - 1][0] << endl;
}

int main()
{
	solve();
	return(0);
}