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