#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int a;
int num(string s){
	int out=0;
	while(s.size()!=a&&isdigit(s[a])){out*=10;out+=s[a]-'0';a++;}
	return out;
}
int main(){
	vector<string>in;
	string s;
	while(cin>>s)in.pb(s);
	int n=in.size();
	int tmp[200][200]={0};
	rep(i,n){
		a=0;
		int b=in[i].size();
		int co=0;
		tmp[i][0]=num(in[i]);
		while(1){	
			if(a==b)break;
			a++;
			co++;
			tmp[i][co]=num(in[i]);
		}
	}
	int out[200][200]={0};
	out[0][0]=tmp[0][0];
	loop(i,1,n/2+1){
		out[i][0]=tmp[i][0]+out[i-1][0];
		loop(j,1,i)out[i][j]=tmp[i][j]+max(out[i-1][j-1],out[i-1][j]);
		out[i][i]=tmp[i][i]+out[i-1][i-1];
	}
	loop(i,n/2+1,n)rep(j,n-i)out[i][j]=tmp[i][j]+max(out[i-1][j],out[i-1][j+1]);
	cout<<out[n-1][0]<<endl;
	//rep(i,10){rep(j,10)cout<<" "<<out[i][j];cout<<endl;}
}