#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[] = {0, 1, 2, 3, 4};
  long long g[5][5];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> g[i][j];
  long long max_enjoy = 0;
  do {
    long long enjoy =
        g[a[0]][a[1]] + 2 * g[a[2]][a[3]] + g[a[1]][a[2]] + 2 * g[a[3]][a[4]];
    enjoy +=
        g[a[1]][a[0]] + 2 * g[a[3]][a[2]] + g[a[2]][a[1]] + 2 * g[a[4]][a[3]];
    max_enjoy = max(max_enjoy, enjoy);
  } while (next_permutation(a, a + 5));
  printf("%d", max_enjoy);
  return 0;
}
