#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[] = {1, 2, 3, 4, 5};
  int V[5][5];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> V[i][j];
  int sum, summax = 0;
  do {
    sum =
        V[A[0] - 1][A[1] - 1] + V[A[1] - 1][A[0] - 1] + V[A[2] - 1][A[3] - 1] +
        V[A[3] - 1][A[2] - 1] + V[A[1] - 1][A[2] - 1] + V[A[2] - 1][A[1] - 1] +
        V[A[3] - 1][A[4] - 1] + V[A[4] - 1][A[3] - 1] + V[A[2] - 1][A[3] - 1] +
        V[A[3] - 1][A[2] - 1] + V[A[3] - 1][A[4] - 1] + V[A[4] - 1][A[3] - 1];
    summax = max(sum, summax);
  } while (next_permutation(A, A + 5));
  cout << summax;
}
