#include <bits/stdc++.h>
int mx[(5) + 1][(5) + 1];
int best;
int max(int x, int y) { return x > y ? x : y; }
int h(int* xs) {
  int i, j, acc;
  for (i = acc = 0; i < (5); ++i) {
    for (j = i; j < (5) - 1; j += 2) {
      acc += mx[xs[j]][xs[j + 1]];
      acc += mx[xs[j + 1]][xs[j]];
    }
  }
  return acc;
}
void perm(int* xs, int mask, int d) {
  int i;
  if (d == (5)) {
    best = max(h(xs), best);
    return;
  }
  for (i = 0; i < (5); ++i) {
    if (!(mask & (1 << i))) {
      xs[d] = i + 1;
      perm(xs, mask | (1 << i), d + 1);
    }
  }
}
int main() {
  int i, j;
  int xs[(5)];
  for (i = 0; i < (5); ++i)
    for (j = 0; j < (5); ++j) scanf("%d", &mx[i + 1][j + 1]);
  perm(xs, 0, 0);
  printf("%d\n", best);
  return EXIT_SUCCESS;
}
