#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> v;
  for (int i = 1; i <= 5; i++) v.push_back(i);
  long long a[6][6], cnt = 0;
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) cin >> a[i][j];
  }
  long long ans = 0;
  do {
    long long cnt = 0;
    for (int i = 0; i <= 3; i++) {
      for (int j = i; j < 4; j += 2) {
        cnt += a[v[j + 1]][v[j]] + a[v[j]][v[j + 1]];
      }
      ans = max(ans, cnt);
    }
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << endl;
}
