#include <bits/stdc++.h>

using namespace std;

vector<int> split(string* str, char sep) {
    vector<int> v;
    stringstream ss(*str);
    string buffer;
    while (getline(ss, buffer, sep))
        v.push_back(atoi(buffer.c_str()));
    return v;
}

int main() {
    string s;
    int a, sz;
    vector<int> dp[100];
    for (sz = 0; getline(cin, s); sz++)
        dp[sz] = split(&s, ',');

    for (int i = 1; i < sz; i++)
        for (int j = 0; j < dp[i].size(); j++) {
            int l, r;
            if (i <= sz / 2) l = j - 1, r = j;
            else l = j, r = j + 1;

            if (l < 0) dp[i][j] += dp[i - 1][r];
            else if (r >= i) dp[i][j] += dp[i - 1][l];
            else dp[i][j] += max(dp[i - 1][l], dp[i - 1][r]);
        }

    cout << dp[sz - 1][0] << endl;

    return 0;
}
