#include <iostream>
#include <cctype>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    vector< vector<int> > l(100, vector<int>(0));
    string s;
    int r = 0, i = 0;
    while( cin >> s ){
        string::iterator it = s.begin();
        while( true ){
            if( isdigit( *it ) ){
                int a = 0;
                while( it != s.end() && *it != ',' ){
                    a *= 10;
                    a += *it - '0';
                    it++;
                }
                l[i].push_back( a );
            }
            if( it == s.end() ) break;
            it++;
        }
        if( !i || l[i].size() > l[i-1].size() ) r++;
        i++;
    }
    int m;
    for(m = 1; m <= i/2; m++){
        for(int n = 0; n < m; n++){
            if( !n ) l[m][0] += l[m-1][0];
            else if( m-n == 1 ) l[m][n] += l[m-1][n-1];
            else l[m][n] += max(l[m-1][n-1], l[m-1][n]);
        }
    }
    for(; m < i; m++){
        for(int n = 0; n < i-m; n++){
            l[m][n] += max(l[m-1][n], l[m-1][n+1]);
        }
    }
    cout << l[i-1][0] << endl;
    return 0;
}