#include <bits/stdc++.h>
using namespace std;
long long g[10][10];
vector<int> arr, res;
long long calc() {
  int i, j;
  long long res = 0;
  for (i = 0; i < 5; i++) {
    for (j = i; j < 5; j += 2) {
      if (j + 1 < 5) {
        int u = arr[j];
        int v = arr[j + 1];
        res += g[u][v];
        res += g[v][u];
      }
    }
  }
  return res;
}
int main() {
  int i, j;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      cin >> g[i][j];
    }
  }
  for (i = 0; i < 5; i++) {
    arr.push_back(i);
  }
  long long happy = 0;
  do {
    long long th = calc();
    if (th > happy) {
      happy = th;
    }
  } while (next_permutation(arr.begin(), arr.end()));
  cout << happy;
  return 0;
}
