#include <bits/stdc++.h>
int x4[4] = {0, 0, -1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int xhorse[8] = {1, 2, 1, 2, -1, -2, -1, -2};
int yhorse[8] = {2, 1, -2, -1, 2, 1, -2, -1};
using namespace std;
int g[10][10];
int ar[6];
int ans;
int coba() {
  int res =
      g[ar[1]][ar[2]] + g[ar[2]][ar[1]] + g[ar[3]][ar[4]] + g[ar[4]][ar[3]];
  res += g[ar[2]][ar[3]] + g[ar[3]][ar[2]] + g[ar[4]][ar[5]] + g[ar[5]][ar[4]];
  res += g[ar[3]][ar[4]] + g[ar[4]][ar[3]];
  res += g[ar[4]][ar[5]] + g[ar[5]][ar[4]];
  return res;
}
int main() {
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) scanf("%d", &g[i][j]);
  }
  for (int i = 1; i <= 5; i++) ar[i] = i;
  ans = 0;
  do {
    int res = coba();
    ans = max(ans, res);
  } while (next_permutation(ar + 1, ar + 6));
  printf("%d\n", ans);
  return 0;
}
