#include <iostream>
#include <string>
#include <string.h>
#include <sstream>

#define L 110

using namespace std;

int main(void)
{
	int i1,i2,i3;
	int c;
	string s;
	string temp;
	int f[L][L];
	int dp[L][L];

	c=0;
	memset(f,-1,sizeof(f));
	memset(dp,0,sizeof(dp));

	while(1){
		cin>>s;
		
		temp="";
		s=s+",";

		for(i1=0,i2=0;i1<s.size();i1++){
			if(s[i1]==','){
				istringstream istr(temp);
				istr >> f[c][i2];				
				temp="";
				i2++;
			}
			else temp+=s[i1];
		}
		c++;
		if(c!=1 && count(s.begin(),s.end(),',')==1) break;
	}

	dp[0][0]=f[0][0];
	
	for(i1=1;i1<=c/2;i1++){
		for(i2=0;i2<c/2+1;i2++){
			if(i2==0) dp[i1][i2]=dp[i1-1][i2]+f[i1][i2];
			else if(f[i1][i2]!=-1){
				dp[i1][i2]=max(dp[i1-1][i2],dp[i1-1][i2-1])+f[i1][i2];
			}
		}
	}

	for(i1;i1<c;i1++){
		for(i2=0;i2<c/2+1;i2++){
			if(f[i1][i2]!=-1){
				dp[i1][i2]=max(dp[i1-1][i2],dp[i1-1][i2+1])+f[i1][i2];
			}
		}
	}



	/*for(i1=0;i1<=c;i1++){
		for(i2=0;i2<c/2+1;i2++){
			cout<<f[i1][i2]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dp[c-1][0]<<endl;


	return 0;

}