#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[] = {0, 1, 2, 3, 4};
  int lst[5][5];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) scanf("%d", &lst[i][j]);
  int ANS = 0;
  do {
    int sum = lst[a[0]][a[1]] + lst[a[1]][a[0]] + lst[a[1]][a[2]] +
              lst[a[2]][a[1]] +
              2 * (lst[a[3]][a[4]] + lst[a[4]][a[3]] + lst[a[2]][a[3]] +
                   lst[a[3]][a[2]]);
    ANS = max(sum, ANS);
  } while (next_permutation(a, a + 5));
  cout << ANS;
  return 0;
}
