#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[5][5], p[5], temp = 0, ans = 0, i, j;
  for (i = 0; i < 5; i++)
    for (j = 0; j < 5; j++) cin >> a[i][j];
  for (i = 0; i < 5; i++) p[i] = i;
  do {
    temp = a[p[0]][p[1]] + a[p[1]][p[0]];
    temp += a[p[2]][p[3]] + a[p[3]][p[2]];
    temp += a[p[1]][p[2]] + a[p[2]][p[1]];
    temp += a[p[3]][p[4]] + a[p[4]][p[3]];
    temp += a[p[2]][p[3]] + a[p[3]][p[2]];
    temp += a[p[3]][p[4]] + a[p[4]][p[3]];
    if (temp >= ans) ans = temp;
  } while (next_permutation(p, p + 5));
  cout << ans;
}
