#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int a[100][100];
int b[100];
int n;
int dp[100][100];
int solve(int i, int j) {
	int sum = a[i][j];
	if (i == n) return 0;
	if (i + 1 < (n + 1) / 2) {
		if (dp[i + 1][j + 1]!=-1)
			sum = max(sum, a[i][j] + dp[i + 1][j + 1]);
		else sum = max(sum, a[i][j] + (dp[i + 1][j + 1] = solve(i + 1, j + 1)));
		if (dp[i + 1][j] != -1)
			sum = max(sum, a[i][j] + dp[i + 1][j]);
		else sum = max(sum, a[i][j] + (dp[i + 1][j] = solve(i + 1, j)));
	}
	else {
		if (i == n - 1) {
			int o = 0;
		}
		if (j < b[i + 1]) {
			if (dp[i + 1][j] != -1)
				sum = max(sum, a[i][j] + dp[i + 1][j]);
			else
				sum = max(sum, a[i][j] + (dp[i + 1][j] = solve(i + 1, j)));
		}
		if (j - 1 >= 0) {
			if (dp[i + 1][j - 1] != -1)
				sum = max(sum, a[i][j] + dp[i + 1][j - 1]);
			else
				sum = max(sum, a[i][j] + (dp[i + 1][j - 1] = solve(i + 1, j - 1)));
		}
	}
	return sum;
}
int main() {
	string s;
	int i = 0;
	int sum = 0;
	while (cin>>s) {
		s = s + ",";
		string h = "";
		sum = 0;
		for (int j = 0; j < s.length(); j++) {
			if (s[j] == ',') {
				a[i][sum] = stoi(h);
				sum++;
				h = "";
			}
			else h += s[j];
		}
		b[i] = sum;
		if (sum == 1 && i != 0) break;
		i++;
	}
	n = i+1;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++)
			dp[i][j] = -1;
	}
	cout << solve(0, 0) << endl;
}