#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const double pi = acos(-1.0);
void cp();
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fact(long long n) {
  if (n <= 1) return n;
  return n * fact(n - 1);
}
bool prime[100001];
void sieve() {
  int n = 10000;
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
void solve() {
  int n = 5, g[5][5];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) cin >> g[i][j];
  int p[6], ans = -1, tmp;
  for (int i = 0; i < n; ++i) p[i] = i;
  do {
    tmp = g[p[0]][p[1]] + g[p[1]][p[0]];
    tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
    tmp += g[p[1]][p[2]] + g[p[2]][p[1]];
    tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
    tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
    tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
    ans = max(ans, tmp);
  } while (next_permutation(p, p + n));
  cout << ans << "\n";
}
int main() {
  cp();
  solve();
  return 0;
}
void cp() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
