#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<vector<int>> arr(5 + 1, vector<int>(5 + 1, 0));
  int i, j;
  for (i = 1; i <= 5; ++i) {
    for (j = 1; j <= 5; ++j) {
      cin >> arr[i][j];
    }
  }
  int i1, i2, i3, i4, i5;
  unsigned long long int happiness;
  unsigned long long int max_happiness = 0;
  for (i1 = 1; i1 <= 5; ++i1) {
    for (i2 = 1; i2 <= 5; ++i2) {
      if (i2 == i1) continue;
      for (i3 = 1; i3 <= 5; ++i3) {
        if (i3 == i1 || i3 == i2) continue;
        for (i4 = 1; i4 <= 5; ++i4) {
          if (i4 == i1 || i4 == i2 || i4 == i3) continue;
          for (i5 = 1; i5 <= 5; ++i5) {
            if (i5 == i1 || i5 == i2 || i5 == i3 || i5 == i4) continue;
            happiness = (arr[i1][i2] + arr[i2][i1]);
            happiness += (arr[i2][i3] + arr[i3][i2]);
            happiness += (2 * (arr[i3][i4] + arr[i4][i3]));
            happiness += (2 * (arr[i4][i5] + arr[i5][i4]));
            if (happiness > max_happiness) max_happiness = happiness;
          }
        }
      }
    }
  }
  cout << max_happiness << "\n";
  cout << std::flush;
  return 0;
}
