#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<vector>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  string scan;
  vector<vector<int> > mas;
  int dp[128][128];
  while(getline(cin,scan)){
    vector< int >  v;
    for(int i = 0 , t = 0 ; i < scan.size() ; i++ ){
      if(isdigit(scan[i])) t = t * 10 + scan[i] - '0';
      if(scan[i] == ',' || i == scan.size() - 1){
        v.push_back(t);
        t = 0;
      }
    }
    mas.push_back(v);
  }
  dp[0][0] = mas[0][0];
  int center = mas.size() / 2;
  for(int i = 1 ; i < mas.size() ; i++){
    for(int j = 0 ; j < mas[i].size() ; j++){
      if( i <= center ) dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]);
      else dp[i][j] = max(dp[i-1][j],dp[i-1][j+1]);
      dp[i][j] += mas[i][j];
    }
  }
  cout << dp[mas.size()-1][mas[mas.size()-1].size()-1] << endl;
}