#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[6][6];
  int b[6];
  int m = 0;
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) cin >> a[i][j];
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++)
      for (int q = 1; q <= 5; q++)
        for (int s = 1; s <= 5; s++)
          for (int d = 1; d <= 5; d++) {
            if (i != j && i != q && i != s && i != s && i != d && j != q &&
                j != s && j != d && q != s && q != d && s != d) {
              for (int f = 1; f <= 5; f++) {
                int ans = a[i][j] + a[j][i] + a[q][s] + a[s][q] + a[j][q] +
                          a[q][j] + a[s][d] + a[d][s] + a[q][s] + a[s][q] +
                          a[s][d] + a[d][s];
                if (ans > m) {
                  m = ans;
                  b[1] = i;
                  b[2] = j;
                  b[3] = q;
                  b[4] = s;
                  b[5] = d;
                }
              }
            }
          }
  cout << m;
}
