#include<iostream>

#define MAX 104

using namespace std;

class CNum{
public:
	CNum():num(0),cost(0){}
	int num;
	int cost;
};

int main(void){
	int l = 0;
	int num = 0;
	CNum M[MAX][MAX];

	cin >> M[l++][num].num;
	M[0][0].cost = M[0][0].num;
	cin.ignore(MAX,'\n');
	while( true ){
		num = 0;
		while( true ){
			char c;
			cin >> M[l][num++].num;
			c = cin.get();
			if( c != ',' ) break;
		}
		if(cin.eof())break;
		l++;
	}

	for(int i = 1; i < l; i++){
		for(int j = 0; j < (i > l/2 ? l-i: i+1); j++){
			int d = M[i][j].num;
			
			if( i <= l / 2 ){
				if( j == 0 ) M[i][j].cost = M[i - 1][j].cost + d;
				else M[i][j].cost = max(M[i-1][j-1].cost + d, M[i-1][j].cost + d);
			}else M[i][j].cost = max(M[i-1][j].cost + d, M[i-1][j+1].cost + d);
		}
	}
	cout << M[l-1][0].cost << endl;
	return 0;
}