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