#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e6)


vector<string> split(string s,char ch){
    vector<string> ret;
    string tmp ="";
    rep(i,s.size()){
        if(s[i]==ch){
            ret.pb(tmp);
            tmp = "";
        }else tmp+=s[i];
    }
    if(tmp.size())ret.pb(tmp);
    return ret;
}

int main(){
    vector<string> vs;
    string s;
    while(cin>>s){
        vs.pb(s);
    }
    int h = vs.size();
    int w = (h+1)/2;
    vector<vector<int>> v(h,vector<int>(w,-INF));
    rep(i,vs.size()){
        vector<string> res = split(vs[i],',');
        rep(j,res.size()){
            v[i][j] = stoi(res[j]);
        }
    }
    
    vector<vector<int>> dp(h,vector<int>(w,-INF));
    dp[0][0] = v[0][0];
    
    for(int i=1;i<h;i++){
        if(i<=w-1){
            rep(j,w){
                int t = dp[i-1][j];
                if(j-1>=0)t = max(t,dp[i-1][j-1]);
                dp[i][j] = t+v[i][j];
            }
        }else{
            rep(j,w){
                int t = dp[i-1][j];
                if(j+1<w)t = max(t,dp[i-1][j+1]);
                dp[i][j] = t+v[i][j];
            }
        }
    }
    cout<<dp[h-1][0]<<endl;
}

