#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

vector<string> split(string &s) {
    vector<string> splitted;
    string buf;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != ',') buf.push_back(s[i]);
        else {
            splitted.push_back(buf);
            buf.clear();
        }
    }
    if (!buf.empty()) splitted.push_back(buf);
    return splitted;
}

int to_i(string &s) {
    istringstream is(s);
    int i; is >> i;
    return i;
}

int main() {
    string str;
    vector< vector<int> > rhombic;
    while (getline(cin, str)) {
        vector<string> l = split(str);
        vector<int> r(l.size());
        transform(l.begin(), l.end(), r.begin(), to_i);
        rhombic.push_back(r);
    }

    vector< vector<int> > cost(rhombic.size());
    cost[0].resize(1);
    cost[0][0] = rhombic[0][0];

    int m = rhombic.size() / 2;
    for (int i = 1; i <= m; i++) {
        cost[i].resize(rhombic[i].size());
        for (int j = 0; j < rhombic[i].size(); j++) {
            if (j > 0) {
                cost[i][j] = max(cost[i-1][j-1], cost[i-1][j]) + rhombic[i][j];
            } else {
                cost[i][j] = cost[i-1][j] + rhombic[i][j];
            }
        }
    }
    for (int i = m+1; i < rhombic.size(); i++) {
        cost[i].resize(rhombic[i].size());
        for (int j = 0; j < rhombic[i].size(); j++) {
            cost[i][j] = max(cost[i-1][j], cost[i-1][j+1]) + rhombic[i][j];
        }
    }

    cout << cost[rhombic.size()-1][0] << endl;

//    for (int i = 0; i < cost.size(); i++) {
//        for (int j = 0; j < cost[i].size(); j++) {
//            cout << cost[i][j] << ' ';
//        }
//        cout << endl;
//    }
    return 0;
}