#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int a[50][50] = {};
	char c;
	int i = 0, j = 0;
	bool flag = false;
	while (cin >> c&&c != '$') {
		if (c == ',') {
			flag = false;
			j++;
		}
		else {
			if (flag) {
				i++;
				j = 0;
			}
			flag = true;
			a[i][j] = c - '0';
		}
	}

	int dp[50][50] = {};
	int k = 1;
	dp[0][0] = a[0][0];
	for (; k <= i / 2; k++) {
		dp[k][0] = dp[k - 1][0] + a[k][0];
		for (int l = 1; l <= k; l++) {
			dp[k][l] = max(dp[k - 1][l - 1], dp[k - 1][l]) + a[k][l];
		}
	}
	for (; k <= i; k++) {
		//cout << k << " " << dp[k - 1][j - k + 2] << endl;
		dp[k][i - k + 1] = dp[k - 1][i - k + 2] + a[k][i - k + 1];
		for (int l = 0; l < i - k + 1; l++) {
			dp[k][l] = max(dp[k - 1][l + 1], dp[k - 1][l]) + a[k][l];
		}
	}
	//for (int x = 0; x < 50; x++) {
	//	for (int y = 0; y < 50; y++) {
	//		cout << a[x][y] << " ";
	//	}
	//	cout << endl;
	//}
	//cout << endl;
	//for (int x = 0; x < 50; x++) {
	//	for (int y = 0; y < 50; y++) {
	//		cout << dp[x][y] << " ";
	//	}
	//	cout << endl;
	//}
	cout << dp[i][0] << endl;
	return 0;
}