import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.array;

const int MAX_H = 45, MAX_W = 15;
int rhom[MAX_H][MAX_W];
int dp[MAX_H][MAX_W];
int w = 0, h = 0;

void toMap(string s){
	auto arr = array(s.split(",").map!(s => s.to!int())());
	int size = arr.length;
	w = max(w, size);

	if(size < w){
		arr.reverse;
		while(arr.length < w){
			arr ~= 0;
		}
		arr.reverse;
	}
	for(int i=0;i<w;i++){
		rhom[h][i] = arr[i];
	}
}



void main(){
	string s;
	for(;(s=readln()).length != 0;h++){
		s = chomp(s);
		toMap(s);
	}

	dp[0][0] = rhom[0][0];

	for(int i=1;i<h;i++){
		for(int j=0;j<w;j++){
			if(j-1 >= 0){
				dp[i][j] = dp[i-1][j-1] + rhom[i][j];
			}
			dp[i][j] = max(dp[i][j], dp[i-1][j] + rhom[i][j]);
		}
	}
	
	writeln(dp[h-1][w-1]);
}