//The Shortest Path on A Rhombic Path
#include<bits/stdc++.h>
using namespace std;

int stoi(string s){
  int ret=0;
  for(int i=0; i<s.length(); i++)
    ret=ret*10+(s[i]-'0');
  return ret;
}

int main(){
  vector<vector<int> > v;
  string s;
  int n=0;//行数
  while(getline(cin, s)){
    vector<int> tmp;
    string t;
    stringstream ss(s);
    while(getline(ss, t, ','))
      tmp.push_back(stoi(t));
    v.push_back(tmp);
    n++;
  }

  for(int i=0; i<n-1; i++){
    if(i<n/2){
      for(int j=0; j<v[i+1].size(); j++){
        if(j==0)v[i+1][j]+=v[i][j];
        else if(j==v[i+1].size()-1)v[i+1][j]+=v[i][j-1];
        else v[i+1][j]+=max(v[i][j-1], v[i][j]);
      }
    }
    else{
      for(int j=0; j<v[i+1].size(); j++){
        v[i+1][j]+=max(v[i][j], v[i][j+1]);
      }
    }
  }
  cout<<v[n-1][0]<<endl;
  return 0;
}