#include <iostream>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int dp[60];
  int line[60];
  string buf;
  int a = 1;
  char dummy;
  bool f = true;
  memset(dp, 0, sizeof(int)*60);
  while (getline(cin, buf)) {
    istringstream iss(buf);
    iss >> line[0];
    for (int i=1; i<a; i++) {
      iss >> dummy >> line[i];
    }
    if (iss.fail()) {
      f = false;
      a -= 2;
    }
    if (f) {
      for (int i=a-1; i; i--) {
        dp[i] = line[i] + max(dp[i-1], dp[i]);
      }
      dp[0] += line[0];
      ++a;
    } else {
      for (int i=0; i<a; i++) {
        dp[i] = line[i] + max(dp[i], dp[i+1]);
      }
      --a;
    }
  }
  cout << dp[0] << endl;
  return 0;
}