#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<vector<int>> g(5, vector<int>(5));
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> g[i][j];
    }
  }
  vector<int> b(5);
  iota(b.begin(), b.end(), 0);
  long long mx = 0;
  do {
    long long sum = 0;
    vector<int> a = b;
    int n = 5;
    for (int it = 0; it < 5; it++) {
      for (int i = 0; i + 1 < n; i += 2) {
        sum += g[a[i]][a[i + 1]] + g[a[i + 1]][a[i]];
      }
      n--;
      reverse(a.begin(), a.end());
      a.pop_back();
      reverse(a.begin(), a.end());
    }
    mx = max(sum, mx);
  } while (next_permutation(b.begin(), b.end()));
  cout << mx << '\n';
  return 0;
}
