#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
int g[10][10];
int main() {
  deque<int> a;
  for (int i = 0, _n = (5); i < _n; i++) a.push_back(i);
  for (int i = 0, _n = (5); i < _n; i++)
    for (int j = 0, _n = (5); j < _n; j++) {
      cin >> g[i][j];
    }
  int ma = -1;
  do {
    deque<int> b = a;
    int sum = 0;
    while ((int)b.size() > 1) {
      for (int i = 0; i < (int)b.size() - 1; i += 2) {
        int u = b[i];
        int v = b[i + 1];
        sum += g[u][v] + g[v][u];
      }
      b.pop_front();
    }
    if (ma < sum) ma = sum;
  } while (next_permutation(a.begin(), a.end()));
  cout << ma;
  return 0;
}
