#include <bits/stdc++.h>
using namespace std;
int a[5][5];
int b[] = {0, 1, 2, 3, 4};
long long sol() {
  int p0 = b[0];
  int p1 = b[1];
  int p2 = b[2];
  int p3 = b[3];
  int p4 = b[4];
  long long p = a[p0][p1] + a[p1][p0] + a[p2][p3] + a[p3][p2];
  p += a[p1][p2] + a[p2][p1] + a[p3][p4] + a[p4][p3];
  p += a[p2][p3] + a[p3][p2];
  p += a[p3][p4] + a[p4][p3];
  return p;
}
int main() {
  for (long long i = 0; i < 5; i++)
    for (long long j = 0; j < 5; j++) cin >> a[i][j];
  long long m = 0;
  do {
    m = max(sol(), m);
  } while (next_permutation(b, b + 5));
  cout << m;
}
