#include <bits/stdc++.h>
using namespace std;
class Utl {
 public:
  template <class mixed>
  static void print(mixed value) {
    std::cout << value;
  }
  template <class mixed, class padd>
  static void print(mixed prefix, padd suffix) {
    std::cout << prefix << suffix;
  }
  template <class mixed>
  static void println(mixed value) {
    std::cout << value << std::endl;
  }
  static void println() { std::cout << endl; }
  template <class mixed>
  static void log(vector<mixed> arr, bool nl = false) {
    for (int i = 0; i <= arr.size() - 1; i++) Utl::print(arr[i], " ");
    if (nl) Utl::println();
  }
  template <class mixed>
  static void log(mixed arr[], int len, bool nl = false) {
    for (int i = 0; i <= len - 1; i++) Utl::print(arr[i], " ");
    if (nl) Utl::println();
  }
  template <class mixed>
  static vector<mixed> sort(vector<mixed> vec, int dir = 0) {
    if (dir == 1)
      std::sort(vec.begin(), vec.end(), greater<mixed>());
    else
      std::sort(vec.begin(), vec.end());
    return vec;
  }
  static vector<int> sort(vector<int> vec, std::function<bool(int, int)> dir) {
    std::sort(vec.begin(), vec.end(), dir);
    return vec;
  }
  static vector<char> split(string str) {
    vector<char> vec;
    for (int i = 0; i < str.size(); i++) vec.push_back(str[i]);
    return vec;
  }
  template <class mixed>
  static mixed min(vector<mixed> vec) {
    return *min_element(vec.begin(), vec.end());
  }
  template <class mixed>
  static mixed max(vector<mixed> vec) {
    return *max_element(vec.begin(), vec.end());
  }
  template <class mixed>
  static mixed sum(vector<mixed> vec) {
    return accumulate(vec.begin(), vec.end(), 0);
  }
  template <class mixed>
  static vector<mixed> reverse(vector<mixed> vec) {
    std::reverse(vec.begin(), vec.end());
    return vec;
  }
  template <class mixed>
  static bool every(vector<mixed> vec,
                    std::function<bool(const mixed)> callback) {
    return all_of(vec.begin(), vec.end(), callback);
  }
  template <class mixed>
  static bool some(vector<mixed> vec,
                   std::function<bool(const mixed)> callback) {
    return any_of(vec.begin(), vec.end(), callback);
  }
  template <class mixed>
  static vector<mixed> map(vector<mixed> vec,
                           std::function<mixed(const mixed)> callback) {
    vector<mixed> ret;
    for (auto &el : vec) ret.push_back(callback(el));
    return ret;
  }
  template <class mixed>
  static vector<mixed> filter(vector<mixed> vec,
                              std::function<mixed(const mixed)> callback) {
    vector<mixed> ret;
    for (auto &el : vec) {
      if (callback(el)) ret.push_back(el);
    }
    return ret;
  }
  static string toString(int num) { return to_string(num); }
  static int parseInt(string num) { return stoi(num); }
};
int happiness(vector<vector<int>> score, vector<int> line) {
  vector<pair<int, int>> g;
  g.push_back(make_pair(0, 1));
  g.push_back(make_pair(2, 3));
  g.push_back(make_pair(1, 2));
  g.push_back(make_pair(3, 4));
  g.push_back(make_pair(2, 3));
  g.push_back(make_pair(3, 4));
  int sum = 0;
  for (auto it = g.begin(); it != g.end(); ++it) {
    auto p = *it;
    sum += score[line[p.first]][line[p.second]];
    sum += score[line[p.second]][line[p.first]];
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<vector<int>> score(5, vector<int>(5));
  vector<int> line = {0, 1, 2, 3, 4};
  for (int i = 0; i <= 4; i++) {
    for (int j = 0; j <= 4; j++) {
      cin >> score[i][j];
    }
  }
  int mx = happiness(score, line);
  while (next_permutation(line.begin(), line.end())) {
    mx = max(mx, happiness(score, line));
  }
  Utl::println(mx);
  return 0;
}
