#include <bits/stdc++.h>
using namespace std;
long long int fact(long long int n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
int main() {
  int a[5][5];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> a[i][j];
  string s = "12345", t;
  int m = 0, sum = 0;
  t = s;
  while (t.size() >= 2) {
    for (int i = 0; i < t.size() - 1; i += 2) {
      sum += a[t[i] - 48 - 1][t[i + 1] - 48 - 1] +
             a[t[i + 1] - 48 - 1][t[i] - 48 - 1];
    }
    t.erase(t.begin());
  }
  if (sum > m) m = sum;
  sum = 0;
  while (next_permutation(s.begin(), s.end())) {
    t = s;
    while (t.size() >= 2) {
      for (int i = 0; i < t.size() - 1; i += 2) {
        sum += a[t[i] - 48 - 1][t[i + 1] - 48 - 1] +
               a[t[i + 1] - 48 - 1][t[i] - 48 - 1];
      }
      t.erase(t.begin());
    }
    if (sum > m) m = sum;
    sum = 0;
  }
  cout << m;
  return 0;
}
