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

vector<vector<int> >vec;
int an=0;
void dfs(int c,int i,int j,string s){
    if(i==vec.size()-1){
        an=max(an,c);
        return;
    }
    if(j>0&&i>=vec.size()/2)dfs(c+vec[i+1][j-1],i+1,j-1,s+','+to_string(vec[i+1][j-1]));
    if(vec[i+1].size()>j)dfs(c+vec[i+1][j],i+1,j,s+','+to_string(vec[i+1][j]));
    if(vec[i+1].size()>j+1&&i<vec.size()/2)dfs(c+vec[i+1][j+1],i+1,j+1,s+','+to_string(vec[i+1][j+1]));
}
int main(){
    string str;
    while(cin>>str){
        vector<int>v;
        int k=0;
        for(int i=0;i<str.length();i++){
            if(str[i]==','){
                v.push_back(k);
                k=0;
            }
            else{
                k*=10;
                k+=str[i]-'0';
            }
        }
        v.push_back(k);
        vec.push_back(v);
    }
    dfs(vec[0][0],0,0,to_string(vec[0][0]));
    cout<<an<<endl;
}