#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

vector<vi> v;



int main()
{
	string s;
	while (getline(cin, s))
	{
		vi t;
		REP(i, s.size())
		{
			if (isdigit(s[i]))
			{
				if (i + 1 == s.size() || s[i + 1] == ',') t.push_back(s[i]-'0');
				else
				{
					t.push_back((s[i]-'0') * 10 + (s[i + 1]-'0'));
					i++;
				}
				
			}
		}
		v.push_back(t);
	}

	int dp[105][105] = {};
	dp[0][0] = v[0][0];
	FOR(i, 1, v.size() / 2 + 1)
	{
		dp[i][0] = v[i][0] + dp[i - 1][0];
		dp[i][v[i].size() - 1] = v[i][v[i].size() - 1] + dp[i - 1][v[i - 1].size() - 1];
		FOR(j, 1, v[i].size() - 1) dp[i][j] = v[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j]);
	}
	FOR(i, v.size() / 2 + 1, v.size())
	{
		REP(j, v[i].size())
		{
			dp[i][j] = v[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
		}
	}
	cout << dp[v.size() - 1][0] << endl;
	return 0;
}