#include <bits/stdc++.h>
using namespace std;
int g[10][10], a[10], ans;
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++) a[i] = i;
  do {
    int g1 = g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[3]][a[4]] + g[a[4]][a[3]];
    int g2 = g[a[2]][a[3]] + g[a[3]][a[2]] + g[a[4]][a[5]] + g[a[5]][a[4]];
    int g3 = g[a[3]][a[4]] + g[a[4]][a[3]];
    int g4 = g[a[4]][a[5]] + g[a[5]][a[4]];
    ans = max(g1 + g2 + g3 + g4, ans);
  } while (next_permutation(a + 1, a + 6));
  printf("%d\n", ans);
  return 0;
}
