#include<iostream>
#include<vector>
using namespace std;

int stoi(string str){
  int k = 1,res = 0;
  for(int i=(int)str.size()-1;i>=0;i--){
    res += (str[i]-'0') * k;
    k *= 10;
  }
  return res;
}
int main(){
  int map[100][100];
  int dp[100][100];
  string tmp;
  int n;
  int prv = 0;
  int cnt = 0;

  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++)map[i][j] = 0;
  }

  n = 0;
  while(cin >> tmp){
    int pos = 0;
    vector<int> row;
    while(pos < (int)tmp.size()){
      string digit;
      while(pos < (int)tmp.size() && tmp[pos] != ','){
	digit.push_back(tmp[pos]);
	pos++;
      }
      row.push_back(stoi(digit));
      pos++;
    }

    int s = row.size();
    if(prv > s)cnt++;
    for(int i=0;i<s;i++)map[n-cnt-i][i+cnt] = row[i];

    n++;
    prv = row.size();
  }

  for(int i=0;i<=n/2;i++){
    for(int j=0;j<=n/2;j++){
      if(!i){
	if(!j)dp[i][j] = map[i][j];
	else dp[i][j] = dp[i][j-1] + map[i][j];
      }else{
	if(!j)dp[i][j] = dp[i-1][j] + map[i][j];
	else dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + map[i][j];
      }
    }
  }

  cout << dp[n/2][n/2] << endl;
  
}