#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> v;

int ret = 0;

void f(int n, int x, int y){
    if(x == v.size()-1) ret = max(ret, n+v[x][y]);
    else {
        for(int i=0; i <= 1; i++){
            if(0 <= y+i && y+i < v[x+1].size()) f(n+v[x][y], x+1, y+i);
        }
    }
}

int main(){
    string s;
    int m = 0;
    while(cin >> s){
        vector<int> a;
        while(s.size() != 0){
            if(s.find(",") == -1){a.push_back(stoi(s)); break;}
            else {a.push_back(stoi(s.substr(0, s.find(",")))); s = s.substr(s.find(",")+1);}
        }
        m = max(m, (int)a.size());
        if(a.size() < m){
            int p = a.size();
            for(int i=0; i < m-p; i++) a.push_back(0);
            for(int i=p-1; 0 <= i; i--) a[i+(m-p)] = a[i];
            for(int i=0; i < m-p; i++) a[i] = 0;
        }
        v.push_back(a);
    }
    f(0, 0, 0);
    cout << ret << endl;
}