#include <bits/stdc++.h>
using namespace std;
int v[10 + 5][10 + 5];
int n = 5;
int main() {
  while (cin >> v[0][0]) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (i == 0 && j == 0) continue;
        cin >> v[i][j];
      }
    string s = "01234";
    for (int i = 0; i < n; i++) s[i] -= '0';
    sort(s.begin(), s.end());
    int ans = 0;
    do {
      int sum = 0;
      for (int i = 0; i <= 3; ++i) {
        for (int j = i; j + 1 < n; j += 2) {
          int a = s[j], b = s[j + 1];
          sum += v[a][b] + v[b][a];
        }
      }
      ans = max(ans, sum);
    } while (next_permutation(s.begin(), s.end()));
    cout << ans << endl;
  }
}
