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

int main ()
{
    string str;
    vector<vector<int> > v;
    while (getline(cin, str)) {
        v.push_back(vector<int>(1));
        for (int i = 0; i < str.size(); i++)
            if (str[i] == ',') str[i] = ' ';
        int n;
        stringstream ss;
        ss << str;
        while (ss >> n) {
            v[v.size()-1].push_back(n);
        }
        v[v.size()-1].push_back(0);
    }

    int i = 1;
    while (i <= ((int)v.size() / 2)) {
        for (int j = 1; j < v[i].size()-1; j++) {
            v[i][j] += max(v[i-1][j], v[i-1][j-1]);
        }
        i++;
    }
    while (i < v.size()) {
        for (int j = 1; j < v[i].size() - 1; j++) {
            v[i][j] += max(v[i-1][j], v[i-1][j+1]);
        }
        i++;
    }
    cout << v[v.size()-1][1] << endl;

    return 0;
}