#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
#define LATTE 1000000000

const int d[2][2]={{0,1},{-1,0}};

int main(){
	int num[200][200];
	char c;
	int w[200]={},dp[200][200]={};
	for(int i=0;;i++){
		int latte=0;
		for(int j=0;;){
			int r = scanf("%c",&c);
			if(r==EOF) goto NEXT;
			if(c==',' || c=='\n'){
				num[i][j] = latte;
				latte = 0;
				w[i] = ++j;
				if(c=='\n') break;
			}
			else{
				latte = latte*10+(c-'0');
			}
		}//puts("");
	}
	NEXT:
	dp[0][0] = num[0][0];
	for(int i=0;;i++){
		if(w[i+1]==0){
			printf("%d\n",dp[i][0]); break;
		}
		for(int j=0;j<w[i];j++){
			int latte;
			if(w[i]<w[i+1]) latte=0;
			else latte=1;
			for(int k=0;k<2;k++){
				if(j+d[latte][k]<0 || w[i+1]<=j+d[latte][k]) continue;
				dp[i+1][j+d[latte][k]] = max(dp[i+1][j+d[latte][k]],dp[i][j]+num[i+1][j+d[latte][k]]);
			}
		}
	}
	return 0;
}