#include <bits/stdc++.h>
using namespace std;
int ha[6][6];
int vis[6];
int fa[6];
int ch[4] = {1, 1, 2, 2};
int dfs(int no, int ce) {
  vis[no] = 1;
  int maxn = 0;
  for (int i = 1; i < 6; i++) {
    if (!vis[i]) {
      maxn = max(maxn, ha[no][i] * ch[ce] + dfs(i, ce + 1));
    }
  }
  vis[no] = 0;
  return maxn;
}
int main() {
  for (int i = 1; i < 6; i++)
    for (int j = 1; j < 6; j++) scanf("%d", &ha[i][j]);
  for (int i = 1; i < 6; i++)
    for (int j = i + 1; j < 6; j++) {
      ha[i][j] = ha[j][i] = ha[i][j] + ha[j][i];
    }
  int ans = 0;
  for (int i = 1; i < 6; i++) ans = max(ans, dfs(i, 0));
  printf("%d\n", ans);
  return 0;
}
