#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

void disp_t (vector <vector <int> > t )
{
	int size = t.size();
	int len  = t[0].size();
	int i,j;

	for (i = 0; i < size; ++i){
		for (j = 0; j < len; ++j){
			cout << setw(3) << t[i][j];
		} // end for
		cout << endl;
	} // end for
}

void trans_diagonal (vector <int> p, vector< vector<int> >& t )
{

	int i,j,k;
	int m = (int)(sqrt(p.size() ) );
	int n = 0;

	for (k = 1; k <= m; ++k){
		for (i = 1; i <= k + 1; ++i){
			for (j = k + 1 - i; j >= 1; --j){
				if (i + j == k + 1){
					t[i][j] = p[n];
					++n;
					//cout << '(' << i << ',' << j << ") ";
				} // end if
			} // end for
		} // end for
//		cout << endl;
	} // end for
	
	for (k = m + 1; k < 2*m; ++k){
		for (i = k - (m - 1); i <= 2*m + (m - 1) - k; ++i){
			for (j = k + 1 - i; j >= i - (2*m - 1 - k); --j){
				if (i + j == k + 1){
					//cout << '(' << i << ',' << j << ") ";
					t[i][j] = p[n];
					++n;
				} // end if
			} // end for
		} // end for
//		cout << endl;
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen("testcase.rho", "r", stdin);
	string str = "";
	vector <int> p;
	int n = 0;
	while (getline (cin, str ) ){
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		stringstream ss(str);
		while (ss >> n){
			p.push_back (n );
		} // end while
	} // end while


	int size = p.size();
	int len = (int)sqrt(size);
	vector <vector <int> > t (len+1, vector <int> ( len+1, 0 ) );
	int i,j;

	trans_diagonal (p, t );
	
//	disp_t (t );

	vector <vector <int> > dp (len+1, vector <int> ( len+1, 0 ) );
	
	dp[1][1] = t[1][1];
	for (j = 1; j <= len; ++j){
		dp[1][j] = dp[1][j-1] + t[1][j];
	} // end for
	
	for (i = 1; i <= len; ++i){
		dp[i][1] = dp[i-1][1] + t[i][1];
	} // end for

	
	for (i = 2; i <= len; ++i){
		for (j = 2; j <= len; ++j){
			dp[i][j] = max (dp[i-1][j], dp[i][j-1] ) + t[i][j];
		} // end for
	} // end for

//	disp_t (dp );

	cout << dp[len][len] << endl;
		
	return 0;
}