#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  vector<int> vec1;

  string tmp;
  while (getline(cin, tmp)) {
    stringstream ss(tmp);
    string tmp2;
    while (getline(ss, tmp2, ','))
      vec1.push_back(atoi(tmp2.c_str()));
  }

  int n = sqrt(vec1.size());
  vector<vector<int>> vec2(n + 1, vector<int>(n + 1));
  int k = 0;
  for (int i = 0; i < 2 * n - 1; ++i)
    for (int j = 0; j < i + 1; ++j)
      if (i - j < n && j < n)
        vec2[i - j + 1][j + 1] = vec1[k++];

  vector<vector<int>> vec3(n + 1, vector<int>(n + 1, INT_MAX));
  for (int i = 0; i <= n; ++i)
    vec3[i][0] = vec3[0][i] = 0;

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      vec3[i][j] = max({vec3[i][j - 1], vec3[i - 1][j]}) + vec2[i][j];

  cout << vec3[n][n] << endl;
}
