#include <bits/stdc++.h>
int g[5][5];
int score(int arr[5]) {
  return g[arr[0]][arr[1]] + g[arr[1]][arr[0]] + g[arr[2]][arr[3]] +
         g[arr[3]][arr[2]] + g[arr[1]][arr[2]] + g[arr[2]][arr[1]] +
         g[arr[3]][arr[4]] + g[arr[4]][arr[3]] + g[arr[2]][arr[3]] +
         g[arr[3]][arr[2]] + g[arr[3]][arr[4]] + g[arr[4]][arr[3]];
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) std::cin >> g[i][j];
  int arr[5] = {0, 1, 2, 3, 4};
  int max_score = 0;
  do {
    if (score(arr) > max_score) max_score = score(arr);
  } while (std::next_permutation(arr, arr + 5));
  std::cout << max_score << '\n';
}
