#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int b, res, g[55][55];
int main() {
  for (int i = 0; i < 5; ++i) {
    a.push_back(i);
    for (int j = 0; j < 5; ++j) {
      cin >> g[i][j];
    }
  }
  do {
    b = 0;
    b += g[a[0]][a[1]] + g[a[1]][a[0]] + g[a[2]][a[3]] + g[a[3]][a[2]] +
         g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[3]][a[4]] + g[a[4]][a[3]] +
         g[a[2]][a[3]] + g[a[3]][a[2]] + g[a[3]][a[4]] + g[a[4]][a[3]];
    if (b > res) {
      res = b;
    }
  } while (next_permutation(a.begin(), a.end()));
  cout << res;
}
