#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a[10][10];
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) cin >> a[i][j];
  }
  vector<long long int> v;
  for (int i = 1; i <= 5; i++) v.push_back(i);
  int n = v.size();
  long long int ans = -1e18;
  while (1) {
    long long int b[10];
    for (int i = 0; i < n; i++) b[i + 1] = v[i];
    long long int r = 0;
    r = a[b[1]][b[2]] + a[b[2]][b[1]] + a[b[2]][b[3]] + a[b[3]][b[2]] +
        (2 * (a[b[3]][b[4]] + a[b[4]][b[3]]) +
         (2 * (a[b[4]][b[5]] + a[b[5]][b[4]])));
    ans = max(ans, r);
    if (next_permutation(v.begin(), v.end()) == 0) break;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
