#include <bits/stdc++.h>
using namespace std;
long long int a[10][10], per[10];
long long int otp;
int32_t main() {
  for (long long int i = 0; i < 5; ++i)
    for (long long int j = 0; j < 5; ++j) cin >> a[i][j];
  for (long long int i = 0; i < 5; ++i) per[i] = i;
  for (long long int i = 0; i < 120; ++i) {
    long long int cnt = 0;
    cnt += a[per[0]][per[1]] + a[per[1]][per[0]];
    cnt += a[per[2]][per[3]] + a[per[3]][per[2]];
    cnt += a[per[1]][per[2]] + a[per[2]][per[1]];
    cnt += a[per[3]][per[4]] + a[per[4]][per[3]];
    cnt += a[per[2]][per[3]] + a[per[3]][per[2]];
    cnt += a[per[3]][per[4]] + a[per[4]][per[3]];
    otp = max(otp, cnt);
    next_permutation(per, per + 5);
  }
  cout << otp << "\n";
  return 0;
}
