#include <bits/stdc++.h>
using namespace std;
long long a[10][10];
int d[10], b[10];
long long kq;
void dequy(int k) {
  int i;
  long long sum;
  if (k == 6) {
    sum = a[d[1]][d[2]] + a[d[2]][d[1]] + a[d[3]][d[4]] + a[d[4]][d[3]];
    sum += a[d[2]][d[3]] + a[d[3]][d[2]] + a[d[4]][d[5]] + a[d[5]][d[4]];
    sum += a[d[3]][d[4]] + a[d[4]][d[3]];
    sum += a[d[4]][d[5]] + a[d[5]][d[4]];
    kq = max(kq, sum);
    return;
  }
  for (i = 1; i <= 5; i++)
    if (b[i] == 0) {
      b[i] = 1;
      d[k] = i;
      dequy(k + 1);
      b[i] = 0;
    }
}
void solve() {
  int i, j;
  memset(b, 0, sizeof(b));
  dequy(1);
  cout << kq << endl;
}
void input() {
  int i, j;
  for (i = 1; i <= 5; i++)
    for (j = 1; j <= 5; j++) cin >> a[i][j];
  solve();
}
int main() {
  input();
  fclose(stdin);
  fclose(stdout);
  return 0;
}
