#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> v;


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;
        }
        while(a.size() < 100) a.push_back(0);
        v.push_back(a);
    }
    int memo[110][110] = {0};
    memo[0][0] = v[0][0];
    for(int i = 1; i < v.size(); i++){
        for(int j = 0 ; j < v[i].size(); j++){
            memo[i][j] = max(memo[i][j], v[i][j] + memo[i-1][j]);
            if(j != 0) memo[i][j] = max(memo[i][j], v[i][j] + memo[i-1][j-1]);
        }
    }
    int ret = 0;
    for(int i=0; i < 110; i++){
        ret = max(ret, memo[v.size()-1][i]);
    }
    cout << ret << endl;
}