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

int a[110][100], dp[110][100];

int main() {
	for(int i = 0; i < 110; i++) {
		for(int j = 0; j < 100; j++) {
			a[i][j] = dp[i][j] = 0;
		}
	}
	string s;
	int line = 0;
	while(getline(cin, s)) {
		s += ",";
		int j = 0, b = 0;
		for(int i = 0; i < s.size(); i++) {
			if(s[i] == ',') {
				a[line][j] = b;
				j++;
				b = 0;
			}
			else {
				b *= 10;
				b += s[i] - '0';
			}
		}
		line++;
	}

	dp[0][1] = a[0][0];
	for(int i = 0; i < line; i++) {
		if(i < line / 2 + 1) {
			for(int j = 1; j < 90; j++) {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]) + a[i][j-1];
			}
		}
		else {
			for(int j = 1; j < 90; j++) {
				dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]) + a[i][j-1];
			}
		}
	}

	int res = 0;
	for(int i = 0; i < 90; i++)
		res = max(dp[line-1][i], res);
	cout << res << endl;
}