#include <bits/stdc++.h>
using namespace std;
int main() {
  int g[6][6];
  for (int i = 1; i <= 5; ++i)
    for (int j = 1; j <= 5; ++j) scanf("%d", &g[i][j]);
  vector<int> d;
  for (int i = 0; i <= 5; ++i) d.push_back(i);
  int k = 0;
  long long ans = 0;
  do {
    long long t =
        (g[d[1]][d[2]] + g[d[2]][d[1]] + g[d[3]][d[4]] + g[d[4]][d[3]]);
    t += (g[d[2]][d[3]] + g[d[3]][d[2]] + g[d[4]][d[5]] + g[d[5]][d[4]]);
    t += (g[d[3]][d[4]] + g[d[4]][d[3]]);
    t += (g[d[4]][d[5]] + g[d[5]][d[4]]);
    ans = max(ans, t);
  } while (next_permutation(d.begin() + 1, d.end()));
  cout << ans << endl;
  return 0;
}
