#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

int main(){
    vvi G;
    string s;
    while(cin>>s){
        replace(all(s), ',', ' ');
        vi v;
        stringstream ss(s);
        int i=0;
        while(ss>>i) v.push_back(i);
        G.push_back(v);
    }

    rep(i,G.size()-1){
        vi & next=G[i+1];
        vi & cur=G[i];

        if(next.size() > cur.size()){
            rep(j,next.size()){
                if(j==0) next[j] += cur[j];
                else if(j==next.size()-1) next[j] += cur[j-1];
                else next[j] += max(cur[j], cur[j-1]);
            }
        } else {
            rep(j,next.size()){
                next[j] += max(cur[j], cur[j+1]);
            }
        }
    }
    cout << G.back().back() << endl;
}