#include <bits/stdc++.h>
using namespace std;
int i, j;
int g[6][6], a[120][6], mm = 0;
int main() {
  long long int s = 0, x = 0;
  ;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      if (j != i) {
        for (int k = 1; k <= 5; k++) {
          if (k != j && k != i) {
            for (int h = 1; h <= 5; h++) {
              if (h != i && h != k && h != j) {
                for (int y = 1; y <= 5; y++) {
                  if (y != i && y != j && y != k && y != h) {
                    a[mm][1] = i;
                    a[mm][2] = j;
                    a[mm][3] = k;
                    a[mm][4] = h;
                    a[mm][5] = y;
                    mm++;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= 5; j++) {
      scanf("%d", &g[i][j]);
    }
  }
  long long int ma = 0, mb = 0;
  for (i = 0; i < 120; i++) {
    mb = g[a[i][1]][a[i][2]] + g[a[i][2]][a[i][1]] +
         (2 * (g[a[i][3]][a[i][4]] + g[a[i][4]][a[i][3]])) +
         g[a[i][2]][a[i][3]] + g[a[i][3]][a[i][2]] +
         (2 * (g[a[i][4]][a[i][5]] + g[a[i][5]][a[i][4]]));
    if (mb > ma) {
      ma = mb;
    }
  }
  printf("%I64d\n", ma);
  return 0;
}
