#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

vector<int> split(string delim,string str){
	vector<int> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				int num;
				sscanf(str.substr(i,j-1).c_str(),"%d",&num);
				if(0 < str.substr(i,j-1).size()) res.push_back(num);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

int main(){
	string str;
	vector<vector<int> > table;
	
	while(getline(cin,str)){
		vector<int> tmp = split(",",str);
		table.push_back(tmp);
	}
	
	for(int i=0; i+1 < table.size(); i++){
		if(table[i].size() < table[i+1].size()){
			for(int j = 0; j < table[i+1].size(); j++){
				if(j == 0){
					table[i+1][j] = table[i][j] + table[i+1][j];
				}
				else if(j == table[i+1].size()-1){
					table[i+1][j] = table[i][j-1] + table[i+1][j];
				}
				else{
					table[i+1][j] = max(table[i][j-1]+table[i+1][j], table[i][j]+table[i+1][j]);
				}			
			}
		}
		else{
			for(int j = 0; j < table[i+1].size(); j++){
				table[i+1][j] = max(table[i][j]+table[i+1][j], table[i][j+1]+table[i+1][j]);
			}
		}
	}

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