#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	VVI nums;
	int N;

	{
		vector< queue<int> > ques;
		string buf;
		while ( cin >> buf )
		{
			ques.PB( queue<int>() );
			replace( ALL( buf ), ',', ' ' );

			ISS iss( buf );
			int tmp;
			while ( iss >> tmp )
			{
				ques.back().push( tmp );
			}
		}

		N = ques.size() / 2 + 1;

		REP( i, 0, N )
		{
			while ( ques[0].empty() )
			{
				ques.erase( ques.begin() );
			}

			nums.PB( VI() );
			REP( j, 0, N )
			{
				nums.back().PB( ques[j].front() );
				ques[j].pop();
			}
		}
	}

	VVI dp( nums );
	REP( i, 0, N )
	{
		REP( j, 0, N )
		{
			if ( i )
			{
				dp[i][j] = max( dp[i][j], dp[ i - 1 ][j] + nums[i][j] );
			}

			if ( j )
			{
				dp[i][j] = max( dp[i][j], dp[i][ j - 1 ] + nums[i][j] );
			}
		}
	}

	cout << dp.back().back() << endl;

	return 0;
}