#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    vvi dp(2, vi(52, 0));

    string line;
    int before_n = 0;
    bool latter = false;
    while (cin >> line) {
        int n = 1;
        size_t idx = 0, found;
        while ((found = line.find(',', idx)) != string::npos) {
            n++;
            idx = found + 1;
        }
        if (!latter && n < before_n) {
            latter = true;
        }
        before_n = n;
        stringstream ss(line);
        vi ns(n, 0);
        ss >> ns[0];
        FOR(i, 1, n) {
            char sep;
            ss >> sep >> ns[i];
        }

        REP(i, n) {
            if (latter) {
                dp[1][i+1] = max(dp[1][i+1], dp[0][i+1] + ns[i]);
                dp[1][i+1] = max(dp[1][i+1], dp[0][i+2] + ns[i]);
            } else {
                dp[1][i+1] = max(dp[1][i+1], dp[0][i] + ns[i]);
                dp[1][i+1] = max(dp[1][i+1], dp[0][i+1] + ns[i]);
            }
        }
        dp[0] = dp[1];

//        REP(i, 7) {
//            LOG("%d ", dp[0][i]);
//        }
//        LOG("\n");
    }
    cout << dp[0][1] << endl;
}