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