#include <bits/stdc++.h>
using namespace std;
int g[5][5];
int a1, a2, a3, a4, a5;
long long res = 0;
long long p(int i, int j) { return (g[i][j] + g[j][i]); }
long long r(int i1, int i2, int i3, int i4, int i5) {
  return (p(i1, i2) + p(i2, i3) + 2 * (p(i3, i4) + p(i4, i5)));
}
int main() {
  for (int i = 0; i < 5; ++i)
    for (int j = 0; j < 5; ++j) cin >> g[i][j];
  for (int i1 = 0; i1 < 5; ++i1)
    for (int i2 = 0; i2 < 5; ++i2)
      if (i1 != i2)
        for (int i3 = 0; i3 < 5; ++i3)
          if (i3 != i1 && i3 != i2)
            for (int i4 = 0; i4 < 5; ++i4)
              if (i4 != i1 && i4 != i2 && i4 != i3)
                for (int i5 = 0; i5 < 5; ++i5)
                  if (i5 != i1 && i5 != i2 && i5 != i3 && i5 != i4)
                    if (r(i1, i2, i3, i4, i5) > res)
                      res = r(i1, i2, i3, i4, i5);
  cout << res;
  return 0;
}
