#include<iostream>
#include<sstream>
using namespace std;

int map[102][52];
int memo[4][52];
int maxDeep;
int getAns(int deep){
	int i,cur=1;
	for(i=1;i<(deep+1)/2;i++){
		for(int j=1;j<=i;j++){
			if(memo[2][j]<memo[1][j]+map[i+1][j])memo[2][j]=memo[1][j]+map[i+1][j];
			if(memo[2][j+1]<memo[1][j]+map[i+1][j+1])memo[2][j+1]=memo[1][j]+map[i+1][j+1];
		}
		for(int j=1;j<=2;j++){
			for(int k=1;k<=i+1;k++){
				memo[j][k]=memo[j+1][k];
			}
		}
	}
	for(;i<deep;i++){
		for(int j=1;j<=deep-i;j++){
			if(memo[1][j]<memo[1][j+1])memo[2][j]=memo[1][j+1]+map[i+1][j];
			else memo[2][j]=memo[1][j]+map[i+1][j];
		}
		for(int j=1;j<=2;j++){
			for(int k=1;k<=i+1;k++){
				memo[j][k]=memo[j+1][k];
			}
		}
	}
	return memo[1][1];
}
int
main(){
	string buf;
	for(int i=0;i<=101;i++){
		for(int j=0;j<=51;j++)map[i][j]=-1;
	}
	for(int i=0;i<=3;i++){
		for(int j=0;j<=51;j++)memo[i][j]=-1;
	}
	for(int i=1;cin>>buf;i++){
		stringstream ss(buf);
		for(int j=1;ss>>map[i][j];j++){
			char tmp;
			ss>>tmp;
			if(i==1&&j==1)memo[i][j]=map[i][j];
		}
		maxDeep=i;
	}
	cout<<getAns(maxDeep)<<endl;
	return 0;
}