#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;
int dx[2][2] = {{0,1},{0,-1}};
int dy[2][2] = {{1,1},{1,1}};

int main(){
  vector<int> vec[110];
  string s;
  int inde = 0;
int mex_size=0;
  while(cin >> s){
    
    for(int i=0;i<s.length();i++)if(s[i] == ',')s[i] = ' ';
    stringstream ss;
    ss << s;
    int cnt = 0;
    while(cnt < (ss.str()).size()){
      int val;
      if((ss >> val).fail())break;
      
      vec[inde].push_back(val);
      cnt++;
    }
    mex_size = max(mex_size,(int)vec[inde].size());
    inde++;
  }
 
  ll dp[inde][mex_size];
  rep(i,inde)rep(j,mex_size)dp[i][j] = -1;
  dp[0][0] = vec[0][0];
  int change = 0;
  rep(i,inde){

    if(vec[i].size() == mex_size)
      change = 1;
          
    rep(j,vec[i].size()){

      for(int k=0;k<2;k++){
	int nx = j+dx[change][k],ny = i+dy[change][k];
	if(!(0<=nx && nx < vec[ny].size() && 0<= ny && ny < inde))
	  continue;
		
	   dp[ny][nx] = max(dp[ny][nx],dp[i][j]+vec[ny][nx]);
      }      

    }
 
  }


    cout << dp[inde-1][0] << endl;

return 0;
}