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

using namespace std;

vector< vector<int> > hyou(100, vector<int>(100, -1));

int main() {
	cin >> hyou[0][0];
	int dx[2] = {0, 1};
	string a;
	int counter = 1;
	int counter2 = 0;
	getline(cin, a);
	while (getline(cin, a)) {
		counter2 = 0;
		string b;
		while (a.find(',') != string::npos) {
			stringstream ss;
			b = a.substr(0, a.find(','));
			ss << b;
			ss >> hyou[counter][counter2];
			a = a.substr(a.find(',')+1);
			counter2++;
		}
		stringstream ss;
		ss << a;
		ss >> hyou[counter][counter2];
		counter++;
	}
	for (int i = 1; i <= counter/2; i++) {
		for (int j = 0; ; j++) {
			if (hyou[i][j] == -1) {
				break;
			} else if (j == 0){
				hyou[i][j] += hyou[i-1][j];
			} else {
				hyou[i][j] += max(hyou[i-1][j-1], hyou[i-1][j]);
			}
		}
	}
	for (int i = counter/2+1; i < counter; i++) {
		for (int j = 0; ; j++) {
			if (hyou[i][j] == -1) {
				break;
			} else {
				hyou[i][j] += max(hyou[i-1][j], hyou[i-1][j+1]);
			}
		}
	}
	cout << hyou[counter-1][0] << endl;
	return 0;
}