#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};
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;
  maxi += g[arr[0]][arr[1]] + g[arr[1]][arr[0]];
  maxi += g[arr[2]][arr[3]] + g[arr[3]][arr[2]];
  maxi += g[arr[1]][arr[2]] + g[arr[2]][arr[1]];
  maxi += g[arr[3]][arr[4]] + g[arr[4]][arr[3]];
  maxi += g[arr[2]][arr[3]] + g[arr[3]][arr[2]];
  maxi += g[arr[3]][arr[4]] + g[arr[4]][arr[3]];
  if (maxi > ans) ans = maxi;
  maxi = 0;
  while (next_permutation(arr, arr + 5)) {
    maxi += g[arr[0]][arr[1]] + g[arr[1]][arr[0]];
    maxi += g[arr[2]][arr[3]] + g[arr[3]][arr[2]];
    maxi += g[arr[1]][arr[2]] + g[arr[2]][arr[1]];
    maxi += g[arr[3]][arr[4]] + g[arr[4]][arr[3]];
    maxi += g[arr[2]][arr[3]] + g[arr[3]][arr[2]];
    maxi += g[arr[3]][arr[4]] + g[arr[4]][arr[3]];
    if (maxi > ans) {
      ans = maxi;
    }
    maxi = 0;
  }
  cout << ans;
  cout << "\n";
}
