#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  int arr[6][6];
  int pm[5] = {1, 2, 3, 4, 5};
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < 6; j++) {
      cin >> arr[i][j];
    }
  }
  int ans = INT_MIN;
  do {
    int curr = 0;
    curr += arr[pm[0]][pm[1]];
    curr += arr[pm[1]][pm[0]];
    curr += arr[pm[2]][pm[3]];
    curr += arr[pm[3]][pm[2]];
    curr += arr[pm[1]][pm[2]];
    curr += arr[pm[2]][pm[1]];
    curr += arr[pm[3]][pm[4]];
    curr += arr[pm[4]][pm[3]];
    curr += arr[pm[2]][pm[3]];
    curr += arr[pm[3]][pm[2]];
    curr += arr[pm[3]][pm[4]];
    curr += arr[pm[4]][pm[3]];
    ans = max(ans, curr);
  } while (next_permutation(pm, pm + 5));
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) solve();
  return 0;
}
