#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}


int main()
{
	vector< vector<int> > a;
	string s;
	while(cin>>s){
		a.push_back(vector<int>());
		replace(s.begin(),s.end(),',',' ');
		splitstr(s,a.back());
	}
	for (int i = 0; i < ((int)a.size() - 1) /2 ; i++){
		for (int j = 0; j <= i + 1; j++){
			if(j == 0) a[i+1][j] += a[i][j];
			else if(j == i+1) a[i+1][j] += a[i][j-1];
			else a[i+1][j] += max(a[i][j],a[i][j-1]);
		}
	}
	for (int i = ((int)a.size() - 1) /2 ; i < a.size() - 1; i++){
		for (int j = 0; j < (int)a[i].size() - 1; j++){
			a[i+1][j] += max(a[i][j],a[i][j+1]);
		}
	}

	cout << a.back()[0] << endl;

	return 0;
}