#include <bits/stdc++.h>
using namespace std;
int g[6][6], v[125][6], t[6], id = 1, mx = -99999;
vector<int> a;
void back_track() {
  if (a.size() == 5) {
    for (int i = 1; i <= 5; i++) {
      v[id][i] = a[i - 1];
    }
    id += 1;
    return;
  } else {
    for (int i = 1; i <= 5; i++) {
      if (t[i] == 0) {
        t[i] = 1;
        a.push_back(i);
        back_track();
        a.pop_back();
        t[i] = 0;
      }
    }
  }
}
int main() {
  back_track();
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      scanf("%d", &g[i][j]);
    }
  }
  for (int i = 1; i <= 120; i++) {
    int s1, s2, s3, s4;
    s1 = g[v[i][1]][v[i][2]] + g[v[i][2]][v[i][1]] + g[v[i][3]][v[i][4]] +
         g[v[i][4]][v[i][3]];
    s2 = g[v[i][2]][v[i][3]] + g[v[i][3]][v[i][2]] + g[v[i][4]][v[i][5]] +
         g[v[i][5]][v[i][4]];
    s3 = g[v[i][3]][v[i][4]] + g[v[i][4]][v[i][3]];
    s4 = g[v[i][4]][v[i][5]] + g[v[i][5]][v[i][4]];
    mx = max(mx, s1 + s2 + s3 + s4);
  }
  printf("%d\n", mx);
  return 0;
}
