#include <bits/stdc++.h>
using namespace std;
int g[6][6], a[6];
long long ans;
long long eval() {
  long long ans =
      g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[2]][a[3]] + g[a[3]][a[2]] +
      2 * (g[a[3]][a[4]] + g[a[4]][a[3]] + g[a[4]][a[5]] + g[a[5]][a[4]]);
  return ans;
}
void swap(int *a, int *b) {
  int t = *a;
  *a = *b;
  *b = t;
}
long long max(long long a, long long b) { return a > b ? a : b; }
void perm(int i, int n) {
  if (i == n) {
    ans = max(ans, eval());
  } else {
    for (int j = i; j <= n; j++) {
      swap(a[j], a[i]);
      perm(i + 1, n);
      swap(a[j], a[i]);
    }
  }
}
int main() {
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) cin >> g[i][j];
  }
  for (int i = 1; i <= 5; i++) a[i] = i;
  perm(1, 5);
  cout << ans << endl;
}
