#include <bits/stdc++.h>
using namespace std;
int g[105][105], ans;
int a[6] = {0, 1, 2, 3, 4, 5};
int alp() {
  int res = 0;
  res = 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]];
  res += g[a[2]][a[1]] + g[a[4]][a[3]] + g[a[3]][a[2]] + 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]];
  ans += g[a[2]][a[1]] + g[a[4]][a[3]] + g[a[3]][a[2]] + g[a[5]][a[4]] +
         g[a[4]][a[3]] + g[a[5]][a[4]];
  do {
    ans = max(ans, alp());
  } while (next_permutation(a + 1, a + 6));
  cout << ans;
}
