#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int c2i(char c) { return c-'0'; }

string in;
int prev[100], next[100], prevN, num[100], tmp;

int main() {
  prev[0] = 0;
  prevN = 1;
  while (getline(cin,in)) {
    vector<int> v;
    rep(i,in.size()) if (in[i] == ',') in[i] = ' ';
    stringstream ss(in);
    while (ss >> tmp) v.push_back(tmp);
    const int N = v.size();
    rep(i,N) next[i] = v[i];
    if (prevN < N) {
      rep(i,prevN) {
        next[i] = max(next[i], v[i] + prev[i]);
        next[i+1] = max(next[i+1], v[i+1] + prev[i]);
      }
    } else if (prevN > N) {
      rep(i,prevN) {
        if (i-1 >= 0) next[i-1] = max(next[i-1], v[i-1] + prev[i]);
        if (i < N) next[i] = max(next[i], v[i] + prev[i]);
      }
    }
    //rep(i,N) printf("[%4d]",next[i]); puts("");
    rep(i,N) prev[i] = next[i];
    prevN = N;
  }
  printf("%d\n",prev[0]);
  return 0;
}