#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int area[9][5];
	int num[] = {
		0,0,0,0,0
	};
	char c;
	for(int i = 0; i < 5; i++){
		for(int j = 0; j <= i; j++){
			cin >> area[i][j];
			if(j != i) cin >> c;
		}
	}
	for(int i = 3; i >= 0; i--){
		for(int j = 0; j <= i; j++){
			cin >> area[8 - i][j];
			if(j != i) cin >> c;
		}
	}
	num[0] = area[0][0];
	for(int i = 1; i < 5; i++){
		num[i] = num[i-1] + area[i][i];
		for(int j = i - 1; j >= 1; j--){
			num[j] = max(num[j],num[j-1]) + area[i][j];
		}
		num[0] += area[i][0];
	}
	for(int i = 3; i >= 0; i--){
		for(int j = 0; j <= i; j++){
			num[j] = max(num[j],num[j+1]) + area[8 - i][j];
		}
	}
	cout << num[0] << endl;
	return 0;
}