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