#include <bits/stdc++.h>
using namespace std;
bool b[10];
int a[10], maxx, v[10][10];
void calc() {
  int t[10];
  for (int i = 1; i <= 5; i++) t[i] = a[i];
  int s = 0;
  for (int i = 5; i >= 1; i--) {
    for (int j = 1; j <= i / 2; j++)
      s += v[t[2 * j - 1]][t[2 * j]] + v[t[2 * j]][t[2 * j - 1]];
    for (int j = 1; j <= 5; j++) t[j] = t[j + 1];
  }
  if (s > maxx) maxx = s;
  return;
}
void tryy(int l) {
  if (l > 5) {
    calc();
    return;
  }
  for (int i = 1; i <= 5; i++)
    if (!b[i]) {
      a[l] = i;
      b[i] = true;
      tryy(l + 1);
      b[i] = false;
    }
  return;
}
int main() {
  maxx = -1;
  memset(a, 0, sizeof(a));
  memset(b, false, sizeof(b));
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) scanf("%d", &v[i][j]);
  tryy(1);
  printf("%d\n", maxx);
  return 0;
}
