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

int parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
vector<int> split(string a) {
	vector<int>s;
	string b="";
	for (int c = 0; c < a.length(); c++) {
		if (a[c] == ',') { s.push_back(parse(b)); b = ""; }
		else b += a[c];
	}
	s.push_back(parse(b));
	return s;
}
int main() {
	vector<vector<int>>s;
	string a;
	cin >> a;
	s.push_back(split(a));
	int b = 1;
	for (;;b++) {
		cin >> a;
		s.push_back(split(a));
		if (split(a).size() == 1)break;
	}
	b++;
	for (int o = 1; o < (b + 1) / 2; o++) {
		s[o][0] += s[o - 1][0];
		s[o][o] += s[o - 1][o-1];
		for (int x = 1; x < o; x++) {
			(s[o-1][x-1]>s[o-1][x]) ? (s[o][x] += s[o - 1][x-1]) : (s[o][x] += s[o - 1][x]);
		}
	}
	for (int y = (b + 1) / 2; y < b; y++) {
		for (int z = 0; z < (b - y); z++) {
			(s[y-1][z]>s[y - 1][z+1]) ? (s[y][z] += s[y-1][z]) : (s[y][z] += s[y - 1][z+1]);
		}
	}
	cout << s[b - 1][0] << endl;
}