#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
  long long a[5][5], maxi, sum = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) cin >> a[i][j];
  }
  int ar[5] = {0, 1, 2, 3, 4};
  maxi =
      (a[ar[0]][ar[1]] + a[ar[1]][ar[0]] + a[ar[2]][ar[3]] + a[ar[3]][ar[2]] +
       a[ar[1]][ar[2]] + a[ar[2]][ar[1]] + a[ar[3]][ar[4]] + a[ar[4]][ar[3]] +
       a[ar[2]][ar[3]] + a[ar[3]][ar[2]] + a[ar[3]][ar[4]] + a[ar[4]][ar[3]]);
  while (next_permutation(ar, ar + 5)) {
    sum =
        (a[ar[0]][ar[1]] + a[ar[1]][ar[0]] + a[ar[2]][ar[3]] + a[ar[3]][ar[2]] +
         a[ar[1]][ar[2]] + a[ar[2]][ar[1]] + a[ar[3]][ar[4]] + a[ar[4]][ar[3]] +
         a[ar[2]][ar[3]] + a[ar[3]][ar[2]] + a[ar[3]][ar[4]] + a[ar[4]][ar[3]]);
    if (sum >= maxi) maxi = sum;
  }
  cout << maxi;
  return 0;
}
