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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

vector<int> split(const string &str, char delim) {
	vector<int> res;
	string::size_type current = 0, found;
	while((found = str.find_first_of(delim, current)) != string::npos){
		res.push_back(toInt(string(str, current, found - current)));
		current = found + 1;
	}
	res.push_back(toInt(string(str, current, str.size() - current)));
	return res;
}

int main () {
	vector<int> pre;
	for (int i = 0; ; i++) {
		string line;
		getline(cin, line);
		vector<int> nums = split(line, ',');
		if (i != 0) {
			for (unsigned i = 0; i < nums.size(); i++) {
				if (pre.size() < nums.size()) {
					if (i == 0) nums[i] += pre[0];
					else if (i == pre.size()) nums[i] += pre[pre.size() - 1];
					else nums[i] += max(pre[i - 1], pre[i]);
				}
				else {
					nums[i] += max(pre[i], pre[i + 1]);
				}
			}
			if (nums.size() == 1) {
				cout << nums[0] << endl;
				break;
			}
		}
		pre = nums;
	}
	return 0;
}