#include <bits/stdc++.h>
using namespace std;
int main() {
  int happy[5][5];
  int s[5];
  int scpy[5];
  long long soma, tmp;
  for (int i = 0; i < 5; i++) {
    s[i] = i;
    for (int j = 0; j < 5; j++) {
      cin >> happy[i][j];
    }
  }
  sort(s, s + 5);
  soma = 0;
  do {
    tmp = 0;
    for (int i = 0; i < 5; i++) scpy[i] = s[i];
    for (int ind = 0; ind < 4; ind++) {
      for (int i = ind; i < 4; i += 2) {
        tmp += happy[s[i]][s[i + 1]] + happy[s[i + 1]][s[i]];
      }
    }
    if (soma < tmp) soma = tmp;
  } while (next_permutation(s, s + 5));
  cout << soma << endl;
  return 0;
}
