#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
int g[10][10];
int a[5];
int ans;
int cal() {
  int sum = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i; j < 4; j += 2) sum += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]];
  }
  return sum;
}
int main() {
  for (int i = 0; i < 5; ++i)
    for (int j = 0; j < 5; ++j) cin >> g[i][j];
  for (int i = 0; i < 5; ++i) a[i] = i;
  ans = -1;
  do {
    ans = max(ans, cal());
  } while (next_permutation(a, a + 5));
  cout << ans << endl;
}
