#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
long long a[10][10];
int d[10], f[10];
int main() {
  long long ans = 0;
  for (int i = 0; i <= 4; i++)
    for (int j = 0; j <= 4; j++) scanf("%I64d", &a[i][j]);
  for (int i = 1; i < 3125; i++) {
    int r = i;
    for (int j = 0; j <= 4; j++) {
      d[j] = r % 5;
      f[j] = r % 5;
      r /= 5;
    }
    sort(f, f + 5);
    int flag = 0;
    for (int j = 1; j <= 4; j++)
      if (f[j] == f[j - 1]) flag = 1;
    if (flag == 1) continue;
    long long tmp =
        a[d[0]][d[1]] + a[d[1]][d[2]] + 2 * a[d[2]][d[3]] + 2 * a[d[3]][d[4]];
    tmp +=
        a[d[1]][d[0]] + a[d[2]][d[1]] + 2 * a[d[3]][d[2]] + 2 * a[d[4]][d[3]];
    smax(ans, tmp);
  }
  printf("%I64d\n", ans);
}
