#include <bits/stdc++.h>
using namespace std;
int students[5] = {0, 1, 2, 3, 4};
int g[5][5];
int tempHappy;
int maxHappy;
void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
int maxHappyFunc(int level) {
  if (level >= 5) {
    tempHappy = 0;
    int i = students[0];
    int j = students[1];
    tempHappy += (g[i][j] + g[j][i]) * 1;
    i = students[1];
    j = students[2];
    tempHappy += (g[i][j] + g[j][i]) * 1;
    i = students[2];
    j = students[3];
    tempHappy += (g[i][j] + g[j][i]) * 2;
    i = students[3];
    j = students[4];
    tempHappy += (g[i][j] + g[j][i]) * 2;
    if (tempHappy > maxHappy) {
      maxHappy = tempHappy;
    }
    return maxHappy;
  }
  for (int i = level; i < 5; i++) {
    swap(&students[i], &students[level]);
    maxHappyFunc(level + 1);
    swap(&students[i], &students[level]);
  }
  return maxHappy;
}
int main() {
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> g[i][j];
    }
  }
  cout << maxHappyFunc(0) << endl;
}
