#include <bits/stdc++.h>
using namespace std;
int g[6][6];
int a[7] = {0, 1, 2, 3, 4, 5};
int ans;
inline int tj() {
  int res = g[a[1]][a[2]] + g[a[3]][a[4]] + g[a[2]][a[3]];
  res += g[a[4]][a[5]] + g[a[3]][a[4]] + g[a[4]][a[5]];
  res += g[a[2]][a[1]] + g[a[4]][a[3]] + g[a[3]][a[2]];
  res += g[a[5]][a[4]] + g[a[4]][a[3]] + g[a[5]][a[4]];
  return res;
}
int main() {
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      cin >> g[i][j];
    }
  }
  ans = g[a[1]][a[2]] + g[a[3]][a[4]] + g[a[2]][a[3]] + g[a[4]][a[5]] +
        g[a[3]][a[4]] + g[a[4]][a[5]] + g[a[2]][a[1]] + g[a[4]][a[3]] +
        g[a[3]][a[2]];
  ans += g[a[5]][a[4]] + g[a[4]][a[3]] + g[a[5]][a[4]];
  while (next_permutation(a + 1, a + 6)) {
    ans = max(ans, tj());
  }
  cout << ans << endl;
  return 0;
}
