#include <bits/stdc++.h>
using namespace std;
int mat[6][6];
int main() {
  string arr = "01234";
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      scanf("%d", &mat[i][j]);
    }
  }
  int maxi = INT_MIN;
  do {
    int add = 0;
    int i = arr[0] - '0', ii = arr[1] - '0', j = arr[2] - '0',
        jj = arr[3] - '0', ij = arr[4] - '0';
    add = add + mat[i][ii] + mat[ii][i] + mat[j][jj] + mat[jj][j];
    add = add + mat[ii][j] + mat[j][ii] + mat[jj][ij] + mat[ij][jj];
    add = add + mat[j][jj] + mat[jj][j];
    add = add + mat[jj][ij] + mat[ij][jj];
    if (add > maxi) maxi = add;
  } while (next_permutation(arr.begin(), arr.end()));
  cout << maxi;
}
