#include <iostream>
#include <deque>
#include <sstream>
#include <cstdio>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,t;
	string c;
	vector< vector<int> > dp;
	while(cin >> c){
		dp.resize(dp.size()+1);
		rep(i,c.length())if(c[i] == ',')c[i] = ' ';
		stringstream ss(c);
		while(ss >> t)dp.back().push_back(t);
	}
	for(int i=1;i<dp.size()/2+1;i++){
		rep(j,dp[i].size()){
			int ins = 0;
			if(j)ins = max(ins,dp[i-1][j-1]);
			if(j != dp[i].size()-1)ins = max(ins,dp[i-1][j]);
			dp[i][j] += ins;
		}
	}

	for(int i=dp.size()/2+1;i<dp.size();i++){
		rep(j,dp[i].size()){
			dp[i][j] += max(dp[i-1][j+1],dp[i-1][j]);
		}
	}
	cout << dp.back()[0] << endl;
		
	
}