#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int const MAXN = 2e3 + 5;
double const EPS = 1e-8;
int g[6][6];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> g[i][j];
    }
  }
  long long res = 0;
  vector<int> perm = {1, 2, 3, 4, 5};
  do {
    long long tmp = 0;
    tmp += g[perm[0]][perm[1]] + g[perm[2]][perm[3]];
    tmp += g[perm[1]][perm[0]] + g[perm[3]][perm[2]];
    tmp += g[perm[1]][perm[2]] + g[perm[3]][perm[4]];
    tmp += g[perm[2]][perm[1]] + g[perm[4]][perm[3]];
    tmp += g[perm[2]][perm[3]] + g[perm[3]][perm[2]];
    tmp += g[perm[3]][perm[4]] + g[perm[4]][perm[3]];
    res = max(tmp, res);
  } while (next_permutation(begin(perm), end(perm)));
  cout << res << endl;
  return 0;
}
