#include <bits/stdc++.h>
using namespace std;
int g[6][6];
int p[121][5];
int num;
int A[5];
void create(int cur) {
  int i, j;
  if (cur == 5) {
    for (int i = 0; i < 5; i++) p[num][i] = A[i];
    num++;
  } else {
    for (i = 1; i <= 5; i++) {
      int ok = 1;
      for (j = 0; j < cur; j++)
        if (A[j] == i) ok = 0;
      if (ok) {
        A[cur] = i;
        create(cur + 1);
      }
    }
  }
}
int main() {
  num = 0;
  for (int i = 0; i < 5; i++) A[i] = 0;
  create(0);
  while (cin >> g[1][1] >> g[1][2] >> g[1][3] >> g[1][4] >> g[1][5]) {
    for (int i = 2; i <= 5; i++)
      for (int j = 1; j <= 5; j++) cin >> g[i][j];
    long long sum = 0;
    for (int i = 0; i < num; i++) {
      int n1 = p[i][0], n2 = p[i][1], n3 = p[i][2], n4 = p[i][3], n5 = p[i][4];
      long long temp = (g[n1][n2] + g[n2][n1]) + 2 * (g[n3][n4] + g[n4][n3]) +
                       (g[n2][n3] + g[n3][n2]) + 2 * (g[n4][n5] + g[n5][n4]);
      sum = max(sum, temp);
    }
    cout << sum << endl;
  }
  return 0;
}
