#include <bits/stdc++.h>
using namespace std;
long long gt[5][5];
long long call(int i, int visit[], int visit1[]) {
  if (i >= 5) {
    return gt[visit[0]][visit[1]] + 2 * gt[visit[2]][visit[3]] +
           gt[visit[1]][visit[2]] + 2 * gt[visit[3]][visit[4]];
  }
  long long ans = INT_MIN;
  for (int j = 0; j < 5; j++) {
    if (visit1[j] == -1) {
      visit1[j] = 1;
      visit[i] = j;
      ans = max(ans, call(i + 1, visit, visit1));
      visit1[j] = -1;
      visit[i] = -1;
    }
  }
  return ans;
}
int main() {
  long long g[5][5];
  int visit[5], visit1[5];
  memset(visit, -1, sizeof(visit));
  memset(visit1, -1, sizeof(visit1));
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) cin >> g[i][j];
  }
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) gt[i][j] = g[i][j] + g[j][i];
  }
  long long ans = call(0, visit, visit1);
  cout << ans;
}
