#include <bits/stdc++.h>
using namespace std;
int g[10][10], arr[10];
int main() {
  int i, j;
  long long sum, ma;
  for (i = 0; i < 5; i++) arr[i] = i;
  sort(arr, arr + 5);
  for (i = 0; i < 5; i++)
    for (j = 0; j < 5; j++) scanf("%d", &g[i][j]);
  ma = sum = (long long)g[arr[0]][arr[1]] + g[arr[1]][arr[0]] +
             2 * g[arr[2]][arr[3]] + 2 * g[arr[3]][arr[2]] + g[arr[1]][arr[2]] +
             g[arr[2]][arr[1]] + 2 * g[arr[3]][arr[4]] + 2 * g[arr[4]][arr[3]];
  ;
  while (next_permutation(arr, arr + 5)) {
    sum = (long long)g[arr[0]][arr[1]] + g[arr[1]][arr[0]] +
          2 * g[arr[2]][arr[3]] + 2 * g[arr[3]][arr[2]] + g[arr[1]][arr[2]] +
          g[arr[2]][arr[1]] + 2 * g[arr[3]][arr[4]] + 2 * g[arr[4]][arr[3]];
    ma = max(sum, ma);
  }
  printf("%I64d\n", ma);
  return 0;
}
