#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[5][5], x[] = {0, 1, 2, 3, 4}, ans = 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> a[i][j];
  do {
    int res = 0;
    for (int i = 0; i < 5; i++) {
      for (int j = i; j < 4; j += 2)
        res += a[x[j]][x[j + 1]] + a[x[j + 1]][x[j]];
    }
    ans = max(ans, res);
  } while (next_permutation(x, x + 5));
  cout << ans << '\n';
  return 0;
}
