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

const int MAXN = 105;
int H;
int G[MAXN][MAXN];

int main() {
  string s;
  int pre = -1;
  int b = 0;
  fill(G[0], G[MAXN], -1);
  for(H = 0; cin >> s; ++H) {
    int num = count(s.begin(), s.end(), ',');
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);
    if(num < pre) ++b;
    pre = num;
    for(int i = 0; ss >> G[H][b+i]; ++i);

  }
  for(int i = 1; i < H; ++i) {
    for(int j = 0; j < H; ++j) {
      if(G[i][j] == -1) continue;
      int maxi = 0;
      if(j-1 >= 0) maxi = max(maxi, G[i-1][j-1]);
      maxi = max(maxi, G[i-1][j]);
      G[i][j] += maxi;
      if(i == H-1) cout << G[i][j] << endl;
    }
  }
  return 0;
}