#include <bits/stdc++.h>
using namespace std;
int f(int n) {
  if (n > 1) {
    long long int f = 1;
    for (int i = 2; i <= n; i++) f = f * i;
    return f;
  } else
    return 1;
}
bool isprime(long long int n) {
  if (n == 1)
    return false;
  else {
    for (long long int i = 2; i <= sqrt(n); i++)
      if (n % i == 0) return false;
    return true;
  }
}
bool is_int(long double d) {
  if (d == ceil(d)) return true;
  return false;
}
vector<pair<long long int, long long int> > primefac(long long int n) {
  vector<pair<long long int, long long int> > a;
  long long int temp, test = 1, count;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0 && isprime(i)) {
      temp = n;
      count = 0;
      while (temp % i == 0) {
        count++;
        temp = temp / i;
      }
      a.push_back({i, count});
      test = pow(i, count) * test;
    }
  }
  if (test != n) a.push_back({n / test, 1});
  return a;
}
vector<int> fac(int n) {
  vector<int> a;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      a.push_back(i);
      a.push_back(n / i);
    }
  }
  return a;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return b;
  else if (b == 0)
    return a;
  else
    return gcd(b % a, a);
}
void solve() {
  long long int a[6][6];
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) cin >> a[i][j];
  }
  vector<long long int> v = {1, 2, 3, 4, 5};
  long long int sum = 0;
  do {
    sum = max(sum, (a[v[0]][v[1]] + a[v[1]][v[0]]) +
                       (a[v[1]][v[2]] + a[v[2]][v[1]]) +
                       (2 * (a[v[2]][v[3]] + a[v[3]][v[2]])) +
                       2 * (a[v[4]][v[3]] + a[v[3]][v[4]]));
  } while (next_permutation(v.begin(), v.end()));
  cout << sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
