#include <bits/stdc++.h>
using namespace std;
void solve() {
  int64_t v[6][6];
  for (int64_t i = 1; i < 6; i++) {
    for (int64_t j = 1; j < 6; j++) {
      cin >> v[i][j];
    }
  }
  int64_t arr[5] = {1, 2, 3, 4, 5};
  int64_t ans = 0;
  do {
    int64_t curr_sum = 0;
    int64_t j = 0;
    for (int64_t i = 1; i <= 5; i++) {
      j = i;
      while (j < 5) {
        curr_sum += (v[arr[i - 1]][arr[i]] + v[arr[i]][arr[i - 1]]);
        j += 2;
      }
    }
    ans = max(ans, curr_sum);
  } while (next_permutation(arr, arr + 5));
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
