#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long a[5][5], b[5][5] = {0}, i, j;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      cin >> b[i][j];
    }
  }
  long long mx = -1;
  vector<long long> v;
  for (i = 0; i <= 4; i++) {
    v.push_back(i);
  }
  do {
    long long tp = b[v[0]][v[1]] + b[v[1]][v[0]] + b[v[1]][v[2]] +
                   b[v[2]][v[1]] + 2 * (b[v[3]][v[4]]) + 2 * (b[v[4]][v[3]]) +
                   2 * (b[v[3]][v[2]]) + 2 * (b[v[2]][v[3]]);
    if (tp > mx) mx = tp;
  } while (next_permutation(v.begin(), v.end()));
  cout << mx;
  return 0;
}
