#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int g[10][10];
  for (int i = 0; i < 5; ++i)
    for (int j = 0; j < 5; ++j) cin >> g[i][j];
  int ans = -1, tmp;
  int p[6] = {0, 1, 2, 3, 4};
  do {
    tmp = g[p[0]][p[1]] + g[p[1]][p[0]];
    tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
    tmp += g[p[1]][p[2]] + g[p[2]][p[1]];
    tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
    tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
    tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
    if (tmp > ans) {
      ans = tmp;
    }
  } while (next_permutation(p, p + 5));
  cout << ans;
  return 0;
}
