#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[5][5];
  for (int i = 0; i < 5; ++i)
    for (int j = 0; j < 5; ++j) cin >> A[i][j];
  int order[5] = {0, 1, 2, 3, 4};
  int ans = 0;
  do {
    int possible = 0;
    for (int j = 0; j < 5; ++j) {
      for (int i = j; i + 1 < 5; i += 2) {
        possible += A[order[i]][order[i + 1]] + A[order[i + 1]][order[i]];
      }
    }
    ans = max(possible, ans);
  } while (next_permutation(order, order + 5));
  cout << ans;
  return 0;
}
