#include <bits/stdc++.h>
using namespace std;
int a[5] = {0, 1, 2, 3, 4};
int f[6][6];
long long int x, y;
int main() {
  int i = 0, j = 0, k;
  while (scanf("%d", &k) != EOF) {
    for (i = 0; i < 5; i++) a[i] = i;
    x = 0;
    y = 0;
    f[0][0] = k;
    for (i = 0; i < 5; i++) {
      for (j = 0; j < 5; j++) {
        if (i == 0 && j == 0) continue;
        cin >> f[i][j];
      }
    }
    x = f[0][1] + f[1][0] + f[2][3] + f[3][2] + f[1][2] + f[2][1] + f[3][4] +
        f[4][3] + f[2][3] + f[3][2] + f[3][4] + f[4][3];
    while (next_permutation(a, a + 5)) {
      y = f[a[0]][a[1]] + f[a[1]][a[0]] + f[a[2]][a[3]] + f[a[3]][a[2]] +
          f[a[1]][a[2]] + f[a[2]][a[1]] + f[a[3]][a[4]] + f[a[4]][a[3]] +
          f[a[2]][a[3]] + f[a[3]][a[2]] + f[a[3]][a[4]] + f[a[4]][a[3]];
      if (y > x) x = y;
    }
    cout << x << endl;
  }
  return 0;
}
