#include <bits/stdc++.h>
using namespace std;
char s[int(1e+5)];
int va[10][10];
int pre[10];
int vis[10];
int ans;
void solve() {
  int num = 0;
  for (int i = 1; i <= 5; i++) {
    int j = i;
    while (j <= 4) {
      num += va[pre[j]][pre[j + 1]];
      num += va[pre[j + 1]][pre[j]];
      j += 2;
    }
  }
  ans = max(ans, num);
}
void dfs(int num) {
  if (num == 6) {
    solve();
  }
  for (int i = 1; i <= 5; i++) {
    if (!vis[i]) {
      vis[i] = 1;
      pre[num] = i;
      dfs(num + 1);
      vis[i] = 0;
    }
  }
}
int main() {
  memset(vis, 0, sizeof(vis));
  ans = -1;
  int a[10];
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) scanf("%d", &va[i][j]);
  for (int i = 1; i <= 5; i++) {
    vis[i] = 1;
    pre[1] = i;
    dfs(2);
    vis[i] = 0;
  }
  printf("%d\n", ans);
  return 0;
}
