#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

	int dp[100][200],row = 0,tmp,index,width[100],max_width = 0, max_width_row;
	char buf[55];

	while(scanf("%s",buf)!=EOF){
		index = tmp = 0;
		for(int i=0;buf[i] != '\0'; i++){
			if(buf[i] >= '0' && buf[i] <= '9'){
				tmp = tmp*10 + (buf[i] - '0');
				if(buf[i+1] == '\0'){
					dp[row][index++] = tmp;
				}
			}else{
				dp[row][index++] = tmp;
				tmp = 0;
			}
		}
		if(max_width < index){
			max_width = index;
			max_width_row = row;
		}

		width[row] = index;
		row++;
	}

	for(int i=1; i <= max_width_row; i++){
		for(int k=0; k < width[i]; k++){
			if(k == 0){
				dp[i][0] += dp[i-1][0];
			}else if(k == width[i]-1){
				dp[i][k] += dp[i-1][width[i-1]-1];
			}else{
				dp[i][k] += max(dp[i-1][k-1],dp[i-1][k]);
			}
		}
	}

	for(int i = max_width_row+1;i < row; i++){
		for(int k=0; k < width[i]; k++){
			dp[i][k] += max(dp[i-1][k],dp[i-1][k+1]);
		}
	}

	printf("%d\n",dp[row-1][0]);

    return 0;
}