#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;


vector<vector<int>> dia;
vector<vector<int>> dp = vector<vector<int>>();


void input(){
	string s;
	stringstream ss;
	while (cin >> s){
		replace(s.begin(), s.end(), ',', ' ');
		ss.clear();
		ss << s;

		int a;
		dia.push_back(vector<int>());
		while (ss >> a) dia.back().push_back(a);
	}
}


void makeDP(){
	dp = dia;
	for(int y = 1;y < (int)dp.size();y++){
		for(int x = 0;x < (int)dp[y].size();x++){
			if (y <= (int)dp.size() / 2){
				dp[y][x] = max(dp[y-1][max(0, x-1)], dp[y-1][min(x, (int)(dp[y-1].size()-1))]) + dia[y][x] ;
			}
			else {
				dp[y][x] = max(dp[y-1][x], dp[y-1][x+1]) + dia[y][x];
			}
		}
	}
}


int main(){
	input();

	makeDP();

	cout << dp.back().back() << endl;

	return 0;
}