#include <bits/stdc++.h>
using namespace std;
double _st;
void pre() {}
void doThis() {}
void end() {}
int main() {
  pre();
  vector<int> a, ans, temp;
  for (__typeof(5) i = 0; i < (5); i++) a.push_back(i + 1);
  ans = a;
  int arr[10][10];
  long long minans = 0, tempans = 0;
  for (__typeof(5) i = 0; i < (5); i++)
    for (__typeof(5) j = 0; j < (5); j++) cin >> arr[i + 1][j + 1];
  do {
    tempans = 0;
    tempans += arr[a[0]][a[1]] + arr[a[1]][a[0]] + arr[a[2]][a[3]] +
               arr[a[3]][a[2]] + arr[a[1]][a[2]] + arr[a[2]][a[1]] +
               2 * arr[a[3]][a[4]] + 2 * arr[a[4]][a[3]] + arr[a[2]][a[3]] +
               arr[a[3]][a[2]];
    if (minans < tempans) minans = tempans;
  } while (next_permutation(a.begin(), a.end()));
  cout << minans << endl;
  end();
  return 0;
}
