#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int a[6][6], mx = 0, sum;
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < 6; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i < 6; i++) {
    for (int j = 1; j < 6; j++) {
      for (int k = 1; k < 6; k++) {
        for (int l = 1; l < 6; l++) {
          sum = 0;
          for (int m = 1; m < 6; m++) {
            if (i != j && i != k && i != l && i != m && j != k && j != l &&
                j != m && k != l && k != m && l != m) {
              sum += a[i][j] + a[j][i] + a[k][l] + a[l][k] + a[j][k] + a[k][j] +
                     a[l][m] + a[m][l] + a[k][l] + a[l][k] + a[l][m] + a[m][l];
              mx = max(sum, mx);
            }
          }
        }
      }
    }
  }
  cout << mx << '\n';
  return 0;
}
