#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string word;
  int field[100][100] = {0},x = 0,c = 0;
  while(getline(cin,word)){
    int a = 0,b = 0;
    for(int i=0; i<word.size(); i++){
      if(word[i] == ','){
	field[a][x] = b;
	b = 0;
	a++;
      }
      else{b = b*10+word[i]-'0';}
    }
    field[a][x] = b;a++;
    if(c<a){c = a;}
    x++;
  }
  for(int i=1; i<c; i++){
    for(int j=0; j<i+1; j++){
      if(j == 0){field[j][i]+=field[j][i-1];}
      else if(j == i){field[j][i]+=field[j-1][i-1];}
      else{field[j][i]+=max(field[j-1][i-1],field[j][i-1]);}
    }
  }
  for(int i=c; i<c*2; i++){
    for(int j=0; j<c*2-i-1; j++){
      field[j][i]+=max(field[j][i-1],field[j+1][i-1]);
    }
  }
  cout <<field[0][c*2-2]<<endl;
  return 0;
}