#include <bits/stdc++.h>
using namespace std;
int g[10][10];
int main() {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) cin >> g[i][j];
  }
  vector<int> p(5, 0);
  p[0] = 0;
  p[1] = 1;
  p[2] = 2;
  p[3] = 3;
  p[4] = 4;
  int sum = 0, sumfinal = -1;
  for (int i = 0; i <= 4; i++) {
    for (int j = i; j < 4; j += 2) sum += g[p[j]][p[j + 1]] + g[p[j + 1]][p[j]];
  }
  sumfinal = sum;
  while (next_permutation(p.begin(), p.end())) {
    sum = 0;
    for (int i = 0; i <= 4; i++) {
      for (int j = i; j < 4; j += 2)
        sum += g[p[j]][p[j + 1]] + g[p[j + 1]][p[j]];
    }
    if (sum > sumfinal) sumfinal = sum;
  }
  cout << sumfinal << endl;
}
