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