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

int main() {
    vector<vector<int> > shape;
    for(string line; getline(cin, line); ) {
        for(char& c : line) if(c == ',') c = ' ';
        istringstream iss(line);
        vector<int> nums;
        for(int num; iss >> num; nums.push_back(num)) ;
        shape.push_back(nums);
    }

    vector<vector<int> > dp;
    for(const auto& vec : shape) {
        dp.push_back(vector<int>(vec.size(), 0));
    }

    dp[0][0] = shape[0][0];

    for(int i = 0; i < (int)shape.size() - 1; i++) {
        for(int j = 0; j < (int)shape[i].size(); j++) {
            int l, r;
            if(shape[i].size() < shape[i + 1].size()) {
                l = j, r = j + 1;
            }
            else {
                l = j - 1, r = j;
            }

            if(0 <= l) {
                dp[i+1][l] = max(dp[i+1][l], dp[i][j] + shape[i+1][l]);
            }

            if(r < (int)shape[i+1].size()) {
                dp[i+1][r] = max(dp[i+1][r], dp[i][j] + shape[i+1][r]);
            }
        }
    }

    cout << *dp.rbegin()->begin() << endl;
}