#include <bits/stdc++.h>
using namespace std;
int g[5][5];
int main() {
  for (int i = 0; i < 5; ++i) {
    for (int j = 0; j < 5; ++j) {
      cin >> g[i][j];
    }
  }
  int ans = 0;
  int order[5];
  for (int i = 0; i < 5; ++i) order[i] = i;
  do {
    int res = 0;
    for (int i = -1; i < 5; ++i) {
      for (int j = i + 1; j + 1 < 5; j += 2) {
        int a = order[j];
        int b = order[j + 1];
        res += g[a][b] + g[b][a];
      }
    }
    ans = max(ans, res);
  } while (next_permutation(order, order + 5));
  cout << ans << endl;
  return 0;
}
