#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;

int f[200][200];
int line;
int ans;

int s_to_i(string s){
	bool flag = false;
	int n = 0;

	for(unsigned int i=0 ; i < s.size() ; ++i ){
		if( i == 0 && s[i] == '-' ){
			flag = true;
		}else if( s[i] >= '0' && s[i] <= '9' ){
			n *= 10;
			n += s[i] - '0';
		}else{
			break;
		}
	}
	return (flag)? -n : n ;
}

vector<int> split(string s){
	vector<int> vc;

	//¶ñðJ}æØèÅª
	char_separator<char> sep(",");
	tokenizer< char_separator<char> > tokens( s , sep );
	
	//ªµ½¶ñð\¦
	typedef tokenizer< char_separator<char> >::iterator Iter;
	for(Iter it = tokens.begin() ; it != tokens.end() ; ++it )
		vc.push_back( s_to_i( *it ) );
	return vc;
}

void solve(int x,int y,int sum){
	sum += f[y][x];
	if( y == line - 1 ){
		ans = max( ans , sum );
		return;
	}else{
		if( f[y+1][x-1] != -1 )
			solve( x-1 , y+1 , sum );
		if( f[y+1][x+1] != -1 )
			solve( x+1 , y+1 , sum );
	}
}

int main(){
	string s;
	int a;
	for(int y=0 ; y<200 ; ++y )
		for(int x=0 ; x<200 ; ++x )
			f[y][x] = -1;

	int x = 100;
	int y = 0;
	int n = 1;
	line = 1;
	ans = 0;
	cin >> a;
	f[y][x] = a;

	while( cin >> s ){
		//if( s == "q" ) break;

		y++;
		line++;
		vector<int> vc = split( s );
		( n < vc.size() )? x-- : x++ ;
		n = vc.size();
		for(int i=0 ; i<vc.size() ; ++i ){
			f[y][x+i*2] = vc[i];
		}
	}
	/*for(int y=0 ; y<line ; ++y ){
		for(int x=50-line ; x<50+line ; ++x ){
			( f[y][x] == -1 )? cout << " " : cout << (int)f[y][x];
		}
		cout << endl;
	}*/
	solve( 100 , 0 , 0 );
	cout << ans << endl;
}