#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<string> split(const string &s, char sep) {
  vector<string> res;
  int pos = 0, find_pos;
  while ((size_t)(find_pos = (int)s.find(sep, pos)) != string::npos) {
    res.emplace_back(s.substr(pos, find_pos - pos));
    pos = find_pos + 1;
  }
  if (pos < (int)s.size()) res.emplace_back(s.substr(pos, s.size() - pos));
  return res;
}

int n;
string s;
vector<int> a[100], az;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> s) {
    auto ss = split(s, ',');
    for (auto i : ss) {
      a[n].emplace_back(stoi(i));
    }
    az.emplace_back((int)a[n].size());
    n++;
  }

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < az[i]; j++) {
      if (i <= n / 2) {
        int add = 0;
        if (j != 0) add = max(add, a[i - 1][j - 1]);
        if (j + 1 != az[i]) add = max(add, a[i - 1][j]);
        a[i][j] += add;
      } else {
        a[i][j] += max(a[i - 1][j], a[i - 1][j + 1]);
      }
    }
  }
  cout << a[n - 1][0] << endl;

  return 0;
}
