#include<bits/stdc++.h>
using namespace std;

int bfs(int x,int y);
int len[] = {1,2,3,4,5,4,3,2,1};
int hyo[10][6]={0};

int main(){
  for(int i=0;i<9;i++){
    string str;
    cin >> str;
    istringstream iss(str);
    bool flg = false;
    char c;
    for(int j=0;j<len[i];j++){
      if(flg) iss >> c;
      iss >> hyo[i][j];
      flg = true;
    }
  }
  cout << bfs(0,0) << endl;
}

int bfs(int x,int y){
  if(x == 8) return hyo[x][y];
  int sum = 0;
  if(x < 4){
    for(int i=0;i<len[x];i++){
      for(int j=0;j<2;j++){
	sum = max(sum,hyo[x][y]+bfs(x+1,y+j));
      }
    }
  }
  else {
    for(int i=0;i<len[x];i++){
      for(int j=0;j<2;j++){
	if(y-j >= 0 && y-j < len[x]){
	  sum = max(sum,hyo[x][y]+bfs(x+1,y-j));
	}
      }
    }
  }
  return sum;
}