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