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