#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int StringToInt(const string& str){
  int n;
  istringstream iss(str);
  iss >> n;
  return n;
}

vector<int> StringToVectorInt(string& str){
  vector<int> data;
  string::iterator i, j;
  i = str.begin();
  while(1){
    j = find(i, str.end(), ',');
    const string str_(i, j);
    data.push_back(StringToInt(str_));
    if(j == str.end()) return data;
    i = j+1;
  }
}

int GetMaxValue(vector< vector<int> > data){
  for(int i=1; i<data.size(); ++i){
    for(int j=0; j<data[i].size(); ++j){
      if(i <= data.size()/2){
	if(j == 0)
	  data[i][j] += data[i-1][j];
	else if(j == data[i].size()-1)
	  data[i][j] += data[i-1][j-1];
	else
	  data[i][j] += max(data[i-1][j-1], data[i-1][j]);
      }else{
	data[i][j] += max(data[i-1][j], data[i-1][j+1]);
      }
    }
  }
  return data[data.size()-1][0];
}

int main(){
  string str;
  vector< vector<int> > data;

  while(cin >> str)
    data.push_back(StringToVectorInt(str));

  cout << GetMaxValue(data) << endl;
  return 0;
}