#include <bits/stdc++.h>
using namespace std;
int a[5] = {0, 1, 2, 3, 4};
int p[5][5];
int cal() {
  int res = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i; j + 1 < 5; j += 2)
      res += p[a[j]][a[j + 1]] + p[a[j + 1]][a[j]];
  }
  return res;
}
int main() {
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) scanf("%d", &p[i][j]);
  int ans = cal();
  while (next_permutation(a, a + 5)) {
    ans = max(ans, cal());
  }
  cout << ans << endl;
  return 0;
}
