#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int a[10][10];
int func(int x[10], int i, int m) {
  if (i == 6) {
    int h = (a[x[1]][x[2]] + a[x[3]][x[4]] + a[x[2]][x[3]] + a[x[4]][x[5]] +
             a[x[3]][x[4]] + a[x[4]][x[5]]);
    h += a[x[2]][x[1]] + 2 * a[x[4]][x[3]] + a[x[3]][x[2]] + a[x[5]][x[4]] +
         a[x[5]][x[4]];
    return max(h, m);
  } else {
    int k;
    for (int j = 1; j <= 5; j++) {
      int l = 0;
      for (k = 1; k < i; k++) {
        if (x[k] == j) {
          l = 1;
          break;
        }
      }
      if (l == 1) {
        continue;
      }
      x[i] = j;
      int b = func(x, i + 1, m);
      if (b > m) {
        m = b;
      }
    }
    return m;
  }
}
int main() {
  int i, j, k, ans, n, m;
  int x[100];
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  ans = 0;
  ans = func(x, 1, 0);
  printf("%d\n", ans);
  return 0;
}
