#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
int n;
vector< vector<int> > vvi;
int maxsize = 0;

int changei(string s){
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

vector<int> changevi(string s){
	vector<int> vi;
	int res;
	string t;
	REP(i, s.size()){
		if (i == s.size() - 1){
			t += s[i];
			res = changei(t);
			vi.push_back(res);
			t.clear();
		}
		else {
			if (s[i] == ','){
				res = changei(t);
				vi.push_back(res);
				t.clear();
			}
			else{
				t += s[i];
			}
		}
	}
	return vi;
}

int dp[100][100];

int main(){
	while (cin >> s){
		vector<int> vi = changevi(s);
		maxsize = max((int)(vi.size()), maxsize);
		vvi.push_back(vi);
	}
	dp[0][0] = vvi[0][0];
	REP(i, 2 * maxsize - 1){
		REP(j, vvi[i + 1].size()){
			if (i <= maxsize - 1){
				if (j == 0){
					dp[i + 1][j] = dp[i][j] + vvi[i + 1][j];
				}
				//else if (j == vvi[i + 1].size() - 1){
				//	dp[i + 1][j] = dp[i][j - 1] + vvi[i + 1][j];
				//}
				else {
					dp[i + 1][j] = max(dp[i][j - 1], dp[i][j]) + vvi[i + 1][j];
				}
			}
			else{
				dp[i + 1][j] = max(dp[i][j], dp[i][j + 1]) + vvi[i + 1][j];
			}
		}
		/*REP(j, vvi[i].size()){
			cout << dp[i][j] << " ";
			}
			cout << endl;*/
	}
	//REP(i, 2 * maxsize-1){
	//	REP(j, vvi[i].size()){
	//		cout << dp[i][j] << " ";
	//	}
	//	cout << endl;
	//}
	cout << dp[2 * maxsize - 1 - 1][0] << endl;
}