#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int max(int a,int b)
{
	if(a>=b)return a;
	else return b;
}
int main()
{
	int i=0,j=0;
	string str;
	int in=0;
	int num[100][1000]={};
	vector<int>v[101];

	while(getline( cin, str ))
	{
		rep(i,str.size()+1)
		{
			if(str[i]==',' || i==str.size())v[j].push_back(in),in=0;
      		else if(str[i]!=',')in*=10,in+=str[i]-'0';
		}
		j++;
	}

	int count=0;
	int dp[101][101]={};
	rep(i,j)
	{
		rep(k,v[i].size())
		{
			if(i<=j/2)dp[i][k]=v[i][k]+max(dp[i-1][k],dp[i-1][k-1]);
			else dp[i][k]=v[i][k]+max(dp[i-1][k+1],dp[i-1][k]);
			//cout<<dp[i][k]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[j-1][0]<<endl;
	return 0;
}