#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX = 100;

int data[MAX][MAX];
int rev = 0;

void make(string s){
  s+=',';
  int p = 0;
  int sum = 0;

  for(int i = 0; i < s.size(); i++){
    if(s[i] < '0' || s[i] > '9'){ 
      data[rev][p++] = sum;
      sum = 0;
    }else{
      sum *= 10;
      sum += s[i]-'0';
    }
  }
  rev++;
}

void solve(){
  for(int i = 0; i <= rev/2; i++)
    for(int j = 0; data[i+1][j] != -1;j++)
      if(j-1>=0) data[i+1][j] += max(data[i][j],data[i][j-1]);
      else data[i+1][j] += data[i][j];


  for(int i = rev/2+1; i < rev; i++){
    for(int j = 0; data[i+1][j] != -1;j++)
      data[i+1][j] += max(data[i][j],data[i][j+1]);
  
  }
}

int main(){
  string in;
  memset(data,-1,sizeof(data));

  while(getline(cin,in)) make(in);
  solve();
  cout << data[rev-1][0] << endl;
  return 0;
}