#include <bits/stdc++.h>
using namespace std;
int main() {
  int g[5][5], n = 5;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> g[i][j];
  int p[5], ans = -1, temp;
  for (int i = 0; i < 5; ++i) p[i] = i;
  do {
    temp = g[p[0]][p[1]] + g[p[1]][p[0]];
    temp += g[p[2]][p[3]] + g[p[3]][p[2]];
    temp += g[p[1]][p[2]] + g[p[2]][p[1]];
    temp += g[p[3]][p[4]] + g[p[4]][p[3]];
    temp += g[p[2]][p[3]] + g[p[3]][p[2]];
    temp += g[p[3]][p[4]] + g[p[4]][p[3]];
    if (temp > ans) {
      ans = temp;
    }
  } while (next_permutation(p, p + n));
  cout << ans << endl;
}
