#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600
#define long long long

int main(){
  vector<vector<int> > vec(100, vector<int>(100, 0));

  int h=0, w=0;
  int n=0;
  int d; char c;
  while(scanf("%d%c", &d, &c)!=EOF){
    vec[h][w]=d;
    if(c==',') w++;
    if(c=='\n'){
      n = max(n, w+1);
      h++;w=0;
    }
  }

  repl(i,1,n*2-1){
    if(i<n){
      vec[i][0] += vec[i-1][0];
      repl(j,1,i+1){
        vec[i][j] += max(vec[i-1][j-1], vec[i-1][j]);
      }
    } else {
      rep(j, 2*n-i-1){
        vec[i][j] += max(vec[i-1][j], vec[i-1][j+1]);
      }
    }
  }

  cout << vec[n*2-2][0] << endl;

  return 0;
}