#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	vector<string>inp;
	string foo;  while (cin >> foo) {
		replace(ALL(foo), ',', ' ');
		inp.push_back(foo);
	}
	vector<vector<ll>>num(inp.size());
	REP(i, inp.size()) {
		stringstream ss(inp[i]);
		ll bar; while (ss >> bar) {
			num[i].push_back(bar);
		}
	}
	REP1(i, num.size() / 2) {
		REP(j, num[i].size()) {
			num[i][j] = max({ num[i][j], num[i][j] + num[i - 1][max(0LL, j - 1)] ,num[i][j] + num[i - 1][min(i - 1,j)] });
		}
	}
	for (ll i = num.size() / 2 + 1; i < num.size(); ++i) {
		REP(j, num[i].size()) {
			num[i][j] = max({ num[i][j], num[i][j] + num[i - 1][j + 1] ,num[i][j] + num[i - 1][j] });
		}
	}
	cout << num.back().front() << endl;
}




