#include <bits/stdc++.h>
using namespace std;
int mt[6][6];
bool used[6];
int num[6];
int z = -10000000;
void permute(int at) {
  if (at == 6) {
    int mx = (mt[num[1]][num[2]] + 2 * mt[num[3]][num[4]] + mt[num[2]][num[3]] +
              2 * mt[num[4]][num[5]]) +
             (mt[num[2]][num[1]] + 2 * mt[num[4]][num[3]] + mt[num[3]][num[2]] +
              2 * mt[num[5]][num[4]]);
    z = max(z, mx);
    return;
  }
  for (int i = 1; i <= 5; i++)
    if (!used[i]) {
      used[i] = 1;
      num[at] = i;
      permute(at + 1);
      used[i] = 0;
    }
}
int main() {
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < 6; j++) {
      scanf("%d", &mt[i][j]);
    }
  }
  permute(1);
  cout << z;
}
