#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
const int N = 101;
int dp[N][N], a[N][N];
vector<int> split(string s)
{
	vector<int> res;
	for (int i=0; i<s.size(); ++i) if (s[i] == ',') s[i] = ' ';
	istringstream is(s);
	int t;
	while (is >> t) res.push_back(t);
	return res;
}
int main()
{
	string in;
	int pn = 0;
	int n = 0, m = 0;
	while (cin >> in) {
		vector<int> t = split(in);
		for (int i=0; i<t.size(); ++i) a[n][i] = t[i];
		n++;
		m = max(m, (int)t.size());
	}
	dp[0][0] = a[0][0];
	for (int i=1; i<m; ++i)
		for (int j=0; j<m; ++j)
			dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + a[i][j];
	for (int i=m; i<n; ++i)
		for (int j=0; j<m; ++j)
			dp[i][j] = max(dp[i-1][j], dp[i-1][j+1]) + a[i][j];
	cout << dp[n-1][0] << endl;
	return 0;
}