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