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