#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> v(5, vector<int>(5, 0));
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> v.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 5; k++) {
        for (int l = 0; l < 5; l++) {
          for (int m = 0; m < 5; m++) {
            if (i != j and i != k and i != l and i != m) {
              if (j != k and j != l and j != m) {
                if (k != l and k != m) {
                  if (l != m) {
                    int temp = v.at(i).at(j) + v.at(j).at(i) + v.at(k).at(l) +
                               v.at(l).at(k) + v.at(j).at(k) + v.at(k).at(j) +
                               v.at(l).at(m) + v.at(m).at(l) + v.at(k).at(l) +
                               v.at(l).at(k) + v.at(l).at(m) + v.at(m).at(l);
                    ans = max(temp, ans);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
