#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<string> v;
  string s;

  while (getline(cin, s)) v.push_back(s);

  vector<vector<int>> a(v.size()), dp(v.size());
  for (int i = 0; i < v.size(); ++i) {
    int x = 0;
    v[i] += ',';
    for (int j = 0; j < v[i].size(); ++j) {
      if (v[i][j] == ',') {
        a[i].push_back(x);
        x = 0;
      } else {
        int t = v[i][j] - '0';
        x = 10 * x + t;
      }
    }

    dp[i].assign(a[i].size(), 0);
  }

  // for (int i = 0; i < a.size(); ++i) {
  //   for (int j = 0; j < a[i].size(); ++j) {
  //     cout << a[i][j] << (j + 1 == a[i].size() ? "\n" : " ");
  //   }
  // }

  dp[0][0] = a[0][0];
  for (int i = 1; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j) {
      if (dp[i].size() > dp[i - 1].size()) {
        if (j < dp[i - 1].size()) dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        if (j - 1 < dp[i - 1].size()) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]);
      }
      dp[i][j] += a[i][j];
    }
  }

  // for (int i = 0; i < dp.size(); ++i) {
  //   for (int j = 0; j < dp[i].size(); ++j) {
  //     cout << dp[i][j] << (j + 1 == dp[i].size() ? "\n" : " ");
  //   }
  // }

  cout << dp.back().back() << endl;
}