#include <bits/stdc++.h>
using namespace std;
int g[20][20];
int ans;
int tmp;
int main() {
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &g[i][j]);
    }
  }
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      for (int k = 1; k <= 5; k++) {
        for (int l = 1; l <= 5; l++) {
          for (int m = 1; m <= 5; m++) {
            if (i != j && i != k && i != l && i != m && j != k && j != l &&
                j != m && k != l && k != m && l != m) {
              tmp = 0;
              tmp = tmp + g[i][j] + g[j][i] + g[k][l] + g[l][k] + g[j][k] +
                    g[k][j] + g[l][m] + g[m][l] + g[k][l] + g[l][k] + g[l][m] +
                    g[m][l];
              ans = max(ans, tmp);
            }
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
