#include <bits/stdc++.h>
using namespace std;
long long const delta = 1000000007;
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long table[5][5];
  for (long long i = 0; i < 5; i++) {
    for (long long j = 0; j < 5; j++) {
      cin >> table[i][j];
    }
  }
  vector<long long> a;
  a.push_back(1);
  ;
  a.push_back(2);
  ;
  a.push_back(3);
  ;
  a.push_back(4);
  ;
  a.push_back(5);
  ;
  long long ans = 0;
  do {
    vector<long long> q;
    long long temp = 0;
    for (long long i = 4; i >= 0; i--) {
      q.push_back(a[i]);
      ;
    }
    while (q.size()) {
      for (long long i = q.size() - 1; i >= 0; i -= 2) {
        if (i == 0) continue;
        temp += table[q[i] - 1][q[i - 1] - 1];
        temp += table[q[i - 1] - 1][q[i] - 1];
      }
      q.pop_back();
    }
    ans = max(ans, temp);
  } while (next_permutation(a.begin(), a.end()));
  cout << ans;
  return 0;
}
