#include<bits/stdc++.h>
using namespace std;


int main(){
	vector<vector<int> > dp;
	int count = 0,n=0;
	string s;
	while(1){
		cin>>s;
		n++;
		vector<int> tmp;
		int num = (s.size()+1)/2;
		int tmpn=0;
		for(int i=0;i<s.size();i++){
			
		if(s[i]!=','){
			tmpn*=10;
			tmpn+=(s[i]-'0');
		}
		else {
			tmp.push_back(tmpn);
			tmpn=0;
			}
		}
		tmp.push_back(tmpn);	
		dp.push_back(tmp);
		
		if(num==1)count++;
		if(count==2)break;
	}
	vector<vector<int> > u(n/2),d(n/2);
	vector<int> m(n/2+1);
	for(int i=0;i<n/2;i++){
		for(int j=0;j<=i;j++){
		u[i].push_back(dp[i][j]);
		d[i].push_back(dp[n-1-i][j]);
		}
	}
	for(int i=0;i<n/2+1;i++)m[i] = dp[n/2][i];
	
	for(int i=0;i<n/2-1;i++){
		u[i+1][0]+=u[i][0];
		u[i+1][i+1]+=u[i][i];
		d[i+1][0]+=d[i][0];
		d[i+1][i+1]+=d[i][i];
		for(int j=1;j<=i;j++){
			u[i+1][j]+=max(u[i][j-1],u[i][j]);
			d[i+1][j]+=max(d[i][j-1],d[i][j]);
		}
	}
	m[0]+=u[n/2-1][0]+d[n/2-1][0];
	m[n/2]+=u[n/2-1][n/2-1]+d[n/2-1][n/2-1];
	for(int i=1;i<n/2;i++){
	m[i]+=max(u[n/2-1][i],u[n/2-1][i-1]);
	m[i]+=max(d[n/2-1][i],d[n/2-1][i-1]);
	}

	int ans = 0;
	for(int i=0;i<=n/2;i++)ans=max(ans,m[i]);
	cout<<ans<<endl;


	return 0;
}

