#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<string> split(const string &str, char delim) {
    vector<string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != string::npos) {
        res.push_back(string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(string(str, current, str.size() - current));
    return res;
}

int main() {
    vector<vector<int> > v;
    vector<vector<int> > dp;
    string s;
    while(cin >> s) {
        vector<string> ret = split(s,',');
        vector<int> res(ret.size());

        rep(i,ret.size()) {
            stringstream ss;
            ss << ret[i];
            ss >> res[i];
        }

        v.push_back(res);
        dp.push_back(res);
    }

    int mid = v.size()/2;
    rep(i,mid) {
        rep(j,v[i].size()) {
            dp[i+1][j] = max(dp[i+1][j],dp[i][j] + v[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + v[i+1][j+1]);
        }
    }

    REP(i,mid,v.size()-1) {
        rep(j,v[i].size()) {
            if(j == 0) {
                dp[i+1][j] = max(dp[i+1][j],dp[i][j] + v[i+1][j]);
            } else if(j == v[i].size()-1) {
                dp[i+1][j-1] = max(dp[i+1][j-1], dp[i][j] + v[i+1][j-1]);
            } else {
                dp[i+1][j] = max(dp[i+1][j],dp[i][j] + v[i+1][j]);
                dp[i+1][j-1] = max(dp[i+1][j-1], dp[i][j] + v[i+1][j-1]);
            }
        }
    }

    cout << dp[v.size()-1][0] << endl;

    return 0;
}