#include <bits/stdc++.h>
using namespace std;
int main() {
  int g[5][5], line[5] = {0, 1, 2, 3, 4}, max = 0, reg;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) scanf("%d", &g[i][j]);
  do {
    reg = (g[line[0]][line[1]] + g[line[1]][line[0]]) +
          2 * (g[line[3]][line[2]] + g[line[2]][line[3]]) +
          2 * (g[line[4]][line[3]] + g[line[3]][line[4]]) +
          (g[line[2]][line[1]] + g[line[1]][line[2]]);
    if (reg > max) max = reg;
  } while (next_permutation(&line[0], &line[5]));
  printf("%d\n", max);
  return 0;
}
