#include <bits/stdc++.h>
using namespace std;
int n = 5;
int g[5][5];
int a[5] = {0, 1, 2, 3, 4};
int check() {
  int j = 0;
  int res = 0;
  while (j < n) {
    for (int i = j; i + 1 < n; i += 2)
      res += g[a[i]][a[i + 1]] + g[a[i + 1]][a[i]];
    j++;
  }
  return res;
}
int main() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> g[i][j];
  int res = 0;
  for (int i = 0; i < 5 * 4 * 3 * 2 * 1; i++) {
    res = max(check(), res);
    next_permutation(a, a + 5);
  }
  cout << res;
  return 0;
}
