#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstdio>
using namespace std;

vector< vector<int> > con;
vector< vector<int>  > super;
vector<string> str;
string t,atoato;
int ret,MX;
vector<int>dp(201,1<<21);
void saiki(int y,int x,int now,int deep){
	now+=super[y][x];
	if(dp[deep+1]>now)dp[deep]=now;
	else return;
	
	if(y == con.size()-1 && x == MX){
		ret = max(now,ret);
		return;
	}
	if(super[y+1][x-1]!=-1)saiki(y+1,x-1,now,deep+1);
	if(super[y+1][x+1]!=-1)saiki(y+1,x+1,now,deep+1);
	return;
}

int main(){
	int loop = 0;
	while(cin >> t){
		con.resize(str.size()+1);
		str.push_back(t);
		t += ',';
		for(int i=0;i<t.length();i++){
			if(t[i] == ','){
				con[loop].push_back( atoi(atoato.c_str()) );
				atoato.clear();
			}else{
				atoato += t[i];
			}
		}
		MX = max<int>( MX , con[loop].size() );
		loop++;
	}
	super.resize(con.size());
	for(int i=0;i<con.size();i++){
		for(int j=0;j<MX-con[i].size()+1;j++){
			super[i].push_back(-1);
		}
		for(int j=0;j<con[i].size();j++){
			if(j)super[i].push_back(-1);
			super[i].push_back(con[i][j]);
		}
		for(int j=0;j<MX-con[i].size()+1;j++){
			super[i].push_back(-1);
		}
		
	}
	saiki(0,MX,0,0);
	cout << ret << endl;
	
}