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

int main(){
    string in;
    vector<vector<int>> tree(0);
    while(cin >> in){
        vector<int> row(0);
        for(int i = 0;i<in.length();i++){
            if(in[i] == ',') continue;
            // cout << (in[i] - 48) << " ";
            row.push_back(in[i]-48);
            // cout << row[i/2] << " ";
        }
        tree.push_back(vector<int>(row));
        // for(int i = 0;i<tree.back().size();i++) cout << (tree.back())[i] << " ";
        // cout << endl;
    }
    int max_row[110];
    for(int i = 0;i<110;i++) max_row[i] = 0;
    max_row[0] = tree[0][0];
    for(int i = 0;i<tree.size()-1;i++){
        // cout << tree[i+1].size() << endl;
        vector<int> row(tree[i+1].size(), 0);
        if(tree[i].size() < tree[i+1].size()){
            row[tree[i].size()] = max_row[tree[i].size()] + tree[i+1][tree[i+1].size()-1];
            row[0] = max_row[0] + tree[i+1][0];
            for(int j = 1;j<tree[i+1].size()-1;j++){
                row[j] = max(max_row[j-1] + tree[i+1][j], max_row[j] + tree[i+1][j]);
            }
        }
        else{
            for(int j = 0;j<tree[i+1].size();j++){
                row[j] = max(max_row[j] + tree[i+1][j], max_row[j+1] + tree[i+1][j]);
            }
        }
        for(int k = 0;k<tree[i+1].size();k++) max_row[k] = row[k];
        // for(int k = 0;k<tree[i+1].size();k++) cout << max_row[k] << " ";
        // cout << endl;
    }
    cout << max_row[0] << endl;
    return 0;
}