#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	
	char str[128] = {0};
	int cnt = 1;
	int data[128][128] = {{0}};
	int q = 1;
	bool f = false;
	int hoge = 0;
	
	memset(data,-1,sizeof(data));
	
	while(scanf("%s",str) != EOF){
		
		if(strlen(str) == 1)hoge++;
		
		for(int i = 0;i < strlen(str); i++){
			if(str[i] == ',')continue;
			else{
				data[cnt][q] = str[i] - 48;
				q++;
			}
		}
		q = 1;
		cnt++;
		
		if(hoge == 2)f = true;

		if(f == true){
			q = 2;
			int dp[128][128] = {{0}};
			int x = (cnt/2);
			
			memset(dp,-1,sizeof(dp));
			
			dp[1][1] = data[1][1];
			bool flg = false;
			
			for(int i = 1;i < cnt; i++){
				for(int j = 1;j <= q; j++){
					if(q <= x && flg == false){
						if(j == 1){
							dp[i+1][j] = dp[i][j] + data[i+1][j];
						}
						else if(j == q+1){
							dp[i+1][j] = dp[i][j-1] + data[i+1][j];
						}
						
						else{
							dp[i+1][j] = max(dp[i][j-1]+data[i+1][j],dp[i][j]+data[i+1][j]);
						}
					}
					else if(flg == true){
						dp[i+1][j] = max(dp[i][j+1]+data[i+1][j],dp[i][j]+data[i+1][j]);
					}
				}
				//printf("q:%d\n",q);
				if(flg == false && q < x)q++;
				else if(q == x){flg = true;q--;}
				else q--;
			}
			
			printf("%d\n",dp[cnt-1][1]);
			hoge = 0;
			memset(data,-1,sizeof(data));
			cnt = 1;
			q = 1;	
		}
		f = false;
	}
	return 0;
}