#include <bits/stdc++.h>
using namespace std;
int g[6][6];
int main() {
  int n = 5;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> g[i][j];
    }
  }
  int p[5] = {0, 1, 2, 3, 4}, ans = -1, temp;
  do {
    temp = g[p[0]][p[1]] + g[p[1]][p[0]];
    temp += g[p[2]][p[3]] + g[p[3]][p[2]];
    temp += g[p[1]][p[2]] + g[p[2]][p[1]];
    temp += g[p[3]][p[4]] + g[p[4]][p[3]];
    temp += g[p[2]][p[3]] + g[p[3]][p[2]];
    temp += g[p[3]][p[4]] + g[p[4]][p[3]];
    if (temp > ans) {
      ans = temp;
    }
  } while (next_permutation(p, p + n));
  cout << ans << "\n";
  return 0;
}
