#include <bits/stdc++.h>
using namespace std;
long long int b[10][10], a[10][10];
int main() {
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) cin >> b[i][j];
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) a[i][j] = b[i][j] + b[j][i];
  long long int res = 0, sum, arr[10] = {0, 1, 2, 3, 4, 5};
  do {
    res =
        max(res, a[arr[1]][arr[2]] + a[arr[3]][arr[4]] + a[arr[2]][arr[3]] +
                     a[arr[4]][arr[5]] + a[arr[3]][arr[4]] + a[arr[4]][arr[5]]);
  } while (next_permutation(arr + 1, arr + 6));
  cout << res << endl;
}
