#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int cnt[100];
int d[100][100];
int dp[100][100];

int main() {
	string s;
	int n;
	for (n = 0;; n++) {
		cin >> s;
		s += ',';
		stringstream ss(s);
		char c;
		for (; ss >> d[n][cnt[n]] >> c; cnt[n]++);
		if (n&&cnt[n] == 1)break;
	}
	n++;
	dp[0][0] = d[0][0];
	for (int i = 1; i < n; i++) {
		rep(j, cnt[i]) {
			if ((n & 1 && i <= n / 2) || (!(n & 1) && i < n / 2)) {
				if (!j)dp[i][j] = dp[i - 1][j] + d[i][j];
				else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + d[i][j];
			}
			else {
				if (j == cnt[i] - 1)dp[i][j] = dp[i - 1][j] + d[i][j];
				else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + d[i][j];
			}
		}
	}
	printf("%d\n", dp[n - 1][0]);
}