#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int maxv = -1e5;
int dp[105][105];

int main()
{

    rep(i, 105) rep(j, 105) dp[i][j] = -1e5;

    vector<int> k(100);
    iota(ALL(k), 1);
    string s;
    int i = 0, b;
    while (cin >> s)
    {
        rep(j, s.size()) if (s[j] == ',') s[j] = ' ';
        stringstream ss(s);
        vector<int> t;
        while (ss >> s)
            t.push_back(stoi(s));
        if (i < t.size())
            b = i + 1;

        for (int j = 1; j <= t.size(); j++)
        {
            i < t.size() ? dp[i][j] = t[j - 1] : dp[i][j + k[i - b]] = t[j - 1];
        }
        i++;
    }

    for (int k = 1; k < i; k++)
    {
        for (int j = 1; j < i; j++)
        {
            dp[k][j] += max(dp[k - 1][j], dp[k - 1][j - 1]);
        }
    }
    OP(dp[i - 1][b]);

    return 0;
}
