#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926535898;
const long long M = 1 << 30;
const int ss = 30;
int a[ss][ss];
int p[] = {0, 1, 2, 3, 4};
int n, k, x;
int main() {
  for (int i = 0; i < int(5); i++) {
    for (int j = 0; j < int(5); j++) {
      cin >> a[i][j];
    }
  }
  int mx = 0;
  do {
    int now = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = i; j < 4; j += 2) {
        now += a[p[j + 1]][p[j]];
        now += a[p[j]][p[j + 1]];
      }
    }
    mx = max(mx, now);
  } while (next_permutation(p, p + 5));
  cout << mx;
  return 0;
  ;
}
