#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int f[100][100],dp[100][100];
int main()
{
	int n=0;
	for(int i = 0; i < 100; ++i)
	{
		for(int j = 0; j < 100; ++j)
		{
			f[i][j]=0;
		}
	}	
	string in;
	int x=1,y=1;
	while(getline(cin,in))
	{
		n++;
		x=1;
		for(int i = 0; i < in.size(); ++i)
		{
			while(i<in.size()&&in[i]!=',')
			{
				f[y][x]*=10;
				f[y][x]+=in[i]-'0';
				i++;
			}
			x++;
		}
		f[y][x]=-1;
		y++;
	}
	n=y-1;
	/*for(int i = 0; i < n+1; ++i)
	{
		for(int j = 0; j < n+1; ++j)
		{
			cout<<f[i][j];
		}
		cout<<endl;
	}*/
	dp[1][1]=f[1][1];
	for(int i = 2; i <= n ; ++i)
	{
		x=1;
		while(f[i][x]!=-1)
		{
			if(i<=y/2)
				dp[i][x]=max(dp[i-1][x-1],dp[i-1][x])+f[i][x];
			else
				dp[i][x]=max(dp[i-1][x],dp[i-1][x+1])+f[i][x];
			x++;
		}
	}
	/*for(int i = 0; i < n+1; ++i)
	{
		for(int j = 0; j < n+1; ++j)
		{
			cout<<" "<<dp[i][j];
		}
		cout<<endl;
	}*/
	cout<<dp[n][1]<<endl;
  return 0;
}