#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> points(5, vector<int>(5));
int checkScore(vector<int> s) {
  int score = 0;
  score += points[s[0] - 1][s[1] - 1] + points[s[1] - 1][s[0] - 1] +
           points[s[2] - 1][s[3] - 1] + points[s[3] - 1][s[2] - 1];
  score += points[s[1] - 1][s[2] - 1] + points[s[2] - 1][s[1] - 1] +
           points[s[3] - 1][s[4] - 1] + points[s[4] - 1][s[3] - 1];
  score += points[s[2] - 1][s[3] - 1] + points[s[3] - 1][s[2] - 1];
  score += points[s[3] - 1][s[4] - 1] + points[s[4] - 1][s[3] - 1];
  return score;
}
int main() {
  vector<int> numbers = {1, 2, 3, 4, 5};
  int i = 0;
  vector<vector<int>> permutations(120, vector<int>(5));
  do {
    for (int j = 0; j < 5; j++) permutations[i][j] = numbers[j];
    i++;
  } while (next_permutation(numbers.begin(), numbers.end()));
  for (int j = 0; j < 5; j++)
    for (int k = 0; k < 5; k++) cin >> points[j][k];
  int maxScore = -1;
  for (int j = 0; j < 120; j++) {
    int temp = checkScore(permutations[j]);
    if (temp > maxScore) {
      maxScore = temp;
    }
  }
  cout << maxScore;
  return 0;
}
