#include <bits/stdc++.h>
using namespace std;
long long int input() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  long long int ans = 0;
  while (c >= '0' && c <= '9') {
    ans = (ans << 3) + (ans << 1) + c - '0';
    c = getchar();
  }
  return (ans);
}
int main() {
  long long int permut[5] = {0, 1, 2, 3, 4}, ans = 0;
  long long int g[5][5], i, j;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      g[i][j] = input();
    }
  }
  while (next_permutation(permut, permut + 5)) {
    ans = max(ans, 2 * (g[permut[2]][permut[3]] + g[permut[3]][permut[2]]) +
                       2 * (g[permut[3]][permut[4]] + g[permut[4]][permut[3]]) +
                       g[permut[0]][permut[1]] + g[permut[1]][permut[0]] +
                       g[permut[1]][permut[2]] + g[permut[2]][permut[1]]);
  }
  ans = max(ans, 2 * (g[permut[2]][permut[3]] + g[permut[3]][permut[2]]) +
                     2 * (g[permut[3]][permut[4]] + g[permut[4]][permut[3]]) +
                     g[permut[0]][permut[1]] + g[permut[1]][permut[0]] +
                     g[permut[1]][permut[2]] + g[permut[2]][permut[1]]);
  cout << ans << "\n";
  return 0;
}
