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