#include <bits/stdc++.h>
using namespace std;
int m[5][5];
int ans = 0;
int solve(int a, int b, int c, int d, int e) {
  int p = 0;
  p += m[a][b] + m[b][a] + m[c][d] + m[d][c];
  p += m[b][c] + m[c][b] + m[d][e] + m[e][d];
  p += m[c][d] + m[d][c];
  p += m[d][e] + m[e][d];
  return p;
}
int main() {
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++) cin >> m[i][j];
  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 p = 0; p < 5; p++)
            if (i != j && i != k && i != l && i != p && j != k && j != l &&
                j != p && k != l && k != p && l != p)
              if (solve(i, j, k, l, p) > ans) ans = solve(i, j, k, l, p);
  cout << ans << endl;
}
