#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1e6 + 2;
constexpr int inf = 2e9;
long long int g[7][7];
int arr[] = {1, 2, 3, 4, 5, 6};
long long int ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  for (int c = 1; c <= 5; c++)
    for (int d = 1; d <= 5; d++) cin >> g[c][d];
  long long int maxi = 0;
  do {
    long long int maxi = 0;
    for (int c = 0; c < 5; c++) {
      for (int d = c; d < 5; d += 2) {
        maxi += g[arr[d]][arr[d + 1]] + g[arr[d + 1]][arr[d]];
      }
    }
    if (maxi > ans) {
      ans = maxi;
    }
  } while (next_permutation(arr, arr + 5));
  cout << ans;
  cout << "\n";
}
