#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "12345";
  int x;
  int G[5][5];
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> x;
      G[i][j] = x;
    }
  }
  int maxima = 0;
  do {
    int si = 0, sum = 0;
    while (si < 4) {
      for (int i = si; i < 4; i += 2) {
        int X = s[i] - '0';
        int Y = s[i + 1] - '0';
        sum += (G[X - 1][Y - 1] + G[Y - 1][X - 1]);
      }
      si++;
    }
    if (sum > maxima) maxima = sum;
  } while (std::next_permutation(s.begin(), s.end()));
  cout << maxima << endl;
  return 0;
}
