#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s,temp;
	int str[128][52];
	memset(str,-1,sizeof(str));
	int len = 0,cnt=0;
	while(cin >> s){
		temp = "";
		for(int i = 0,j = 0; i < s.size(); i++){
			if(s[i] == ','){
				j++;temp="";
			}
			else {
				temp += s[i];
				str[cnt][j] = atoi(temp.c_str());
			}
		}
		cnt++;
	}
	len = cnt/2+1;
	int dp[51][51] = {{0}};
	for(int i = 0; i < cnt; i++){
		int x = i+1;
		int y = i-len+2;
		for(int j = 0; j < len; j++){
			if(str[i][j] == -1){
				continue;
			}
			if(i < len){
				dp[x--][j+1] = str[i][j];
			}
			else{
				dp[len-j][y++] = str[i][j];
			}
		}
	}
	for(int i = 1; i <= len; i++){
		for(int j = 1; j <= len; j++){
			printf("%2d",dp[i][j]);
		}
		puts("");
	}

	for(int i = 1; i <= len; i++){
		for(int j = 1; j <= len; j++){
			dp[i][j]+=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	cout << dp[len][len] << endl;
	return 0;
}