#include <bits/stdc++.h>
using namespace std;
int main() {
  int g[7][7] = {0}, a[6] = {0, 1, 2, 3, 4, 5}, ans = 0, happiness = 0;
  for (int i = 1; i < 6; ++i)
    for (int j = 1; j < 6; ++j) cin >> g[i][j];
  while ((next_permutation(a + 1, a + 6))) {
    happiness = 0;
    happiness += g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[3]][a[4]] + g[a[4]][a[3]];
    happiness += g[a[2]][a[3]] + g[a[3]][a[2]] + g[a[4]][a[5]] + g[a[5]][a[4]];
    happiness += g[a[3]][a[4]] + g[a[4]][a[3]];
    happiness += g[a[4]][a[5]] + g[a[5]][a[4]];
    ans = max(happiness, ans);
  }
  for (int i = 1; i < 6; ++i) a[i] = i;
  happiness = 0;
  happiness += g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[3]][a[4]] + g[a[4]][a[3]];
  happiness += g[a[2]][a[3]] + g[a[3]][a[2]] + g[a[4]][a[5]] + g[a[5]][a[4]];
  happiness += g[a[3]][a[4]] + g[a[4]][a[3]];
  happiness += g[a[4]][a[5]] + g[a[5]][a[4]];
  ans = max(happiness, ans);
  cout << ans;
}
