#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265;
const int INF = 1 << 30;
const int maxn = (1e5) + 50;
const int mod = (1e9) + 7;
const int lim = (1e5);
const char filename_in[] = "in.txt";
const char filename_ou[] = "ou.txt";
int hapmat[6][6];
int h(string s) {
  int total = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i; j < 5; j += 2) {
      if (j < 5 && j + 1 < 5) {
        int a = int(s[j] - '0');
        int b = int(s[j + 1] - '0');
        total += hapmat[a][b] + hapmat[b][a];
      }
    }
  }
  return total;
}
int main() {
  ios::sync_with_stdio(0);
  string s = "12345", aux;
  int maxhap = 0;
  for (int i = 1; i <= 5; ++i) {
    for (int j = 1; j <= 5; ++j) {
      cin >> hapmat[i][j];
    }
  }
  do {
    int v = h(s);
    if (v > maxhap) {
      maxhap = v;
      aux = s;
    }
  } while (next_permutation(s.begin(), s.end()));
  cout << maxhap << endl;
}
