#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

vector<int> splitChar(const std::string &s,char c)
{
    std::vector<int> v;
    std::istringstream iss(s);
    std::string next;
    while (std::getline(iss, next, c))
        v.push_back(stoi(next));
    return v;
}

int main(void){
string s;
	vector<vector<int>>w;
	vector<vector<int>>sumw;
	int st=0;int prev=0;
	while(getline(cin,s)){
		vector<int> v=splitChar(s,',');
		w.push_back(v);
		vector<int>v1;
		int tmp;
		if(st==0){v1.push_back(v[0]);sumw.push_back(v1);}
		
		if(st>0 && v.size()>prev){
			for(int j=0;j<v.size();j++){
				if(j==0){v1.push_back((sumw[st-1])[0]+(w[st])[0]);}
				if(j==v.size()-1){v1.push_back((sumw[st-1])[st-1]+(w[st])[st]);}
				if(j>0 && j<v.size()-1){v1.push_back(max(  (sumw[st-1])[j-1]+(w[st])[j],(sumw[st-1])[j]+(w[st])[j] ));}
			}
			sumw.push_back(v1);
		}
			
		if(st>0 && v.size()<prev){
			for(int j=0;j<v.size();j++){
				v1.push_back(max(  (sumw[st-1])[j]+(w[st])[j],(sumw[st-1])[j+1]+(w[st])[j] ));
			}
			sumw.push_back(v1);
		}
		prev=v.size();
		if(st>0 && prev==1)break;
		st++;
	}

	cout<<(sumw[sumw.size()-1])[0]<<endl;
	
return 0;
}


