#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int a[100][100], dp[100][100], n, m;
string s;
vector<int>v;
void f() {
	v.clear(); s += ','; s = '*' + s;
	int p = 0;
	for (char ch : s) {
		if (ch == ',') { v.push_back(p); p = 0; }
		else if (ch != '*') { p *= 10; p += (int)(ch - '0'); }
	}
	n = v.size();
}
signed main() {
	int k = 0;
	while (cin >> s) {
		f();
		if (k < n) {
			for1(i, n)a[i][v.size() - i + 1] = v[i - 1];
		}
		else {
			for0(i, n)a[m * 2 + 1 - n - (m - i)][m - i] = v[i];
		}
		k = v.size();
		m = max(m, k);
	}
	for1(i, m)for1(j, m)dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j];
	cout << dp[m][m] << endl;
}
