#include <bits/stdc++.h>
int main(void) {
  int g[6][6];
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) scanf("%d", &g[i][j]);
  int max = -1;
  for (int a = 1; a <= 5; a++)
    for (int b = 1; b <= 5; b++)
      for (int c = 1; c <= 5; c++)
        for (int d = 1; d <= 5; d++)
          for (int e = 1; e <= 5; e++) {
            char s[6], buf[6] = "12345";
            int ok = 1;
            sprintf(s, "%d%d%d%d%d", a, b, c, d, e);
            for (int i = 0; i < 6; i++)
              if (strchr(s, buf[i]) == NULL) ok = 0;
            if (ok) {
              int x;
              x = g[a][b] + g[b][a] + 2 * g[c][d] + 2 * g[d][c] + g[b][c] +
                  g[c][b] + 2 * g[d][e] + 2 * g[e][d];
              if (x > max) max = x;
            }
          }
  printf("%d\n", max);
  return 0;
}
