#include <bits/stdc++.h>
using namespace std;
void mohammed() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
int main() {
  mohammed();
  long long arr[5][5];
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) cin >> arr[i][j];
  }
  string perm = "01234";
  long long ans = 0;
  do {
    int i0 = perm[0] - '0', i1 = perm[1] - '0', i2 = perm[2] - '0',
        i3 = perm[3] - '0', i4 = perm[4] - '0';
    ans = max(ans, arr[i0][i1] + arr[i1][i0] + 2 * (arr[i2][i3] + arr[i3][i2]) +
                       arr[i1][i2] + arr[i2][i1] +
                       2 * (arr[i3][i4] + arr[i4][i3]));
  } while (next_permutation(perm.begin(), perm.end()));
  cout << ans << endl;
  return 0;
}
