#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF_LL = 4e18;
const double pi = acos(-1.0);
template <class T>
T& smin(T& a, const T& b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T& smax(T& a, const T& b) {
  if (a < b) a = b;
  return a;
}
template <class T>
T sqr(const T& a) {
  return a * a;
}
template <typename Iterator>
void print(const char* fmt, Iterator begin, Iterator end,
           const char* separator = " ", const char* closing = "\n") {
  for (Iterator it = begin; it != end;
       printf(fmt, *it), printf("%s", ++it == end ? closing : separator))
    ;
}
const int N = 22;
int n;
int a[N][N], b[N][N];
int E[N][N];
int p2[N], way[N];
int u[N], v[N], minv[N];
bool used[N];
int ans;
void go(int i, int ka, int kb) {
  if (i == n) {
    smax(ans, v[0]);
    return;
  }
  for (int what(0), _b(2); what < _b; ++what) {
    if (what == 0 && ka == n / 2) continue;
    if (what == 1 && kb == n / 2) continue;
    int pp2[N], pway[N], pu[N], pv[N];
    for (int j(0), _b(n + 1); j < _b; ++j) {
      pp2[j] = p2[j];
      pway[j] = way[j];
      pu[j] = u[j];
      pv[j] = v[j];
    }
    for (int j(0), _b(n); j < _b; ++j) E[i][j] = what == 0 ? a[i][j] : b[i][j];
    fill_n(minv, n + 1, INF);
    fill_n(used, n + 1, 0);
    int j0 = 0;
    p2[0] = i + 1;
    do {
      used[j0] = true;
      int i0 = p2[j0], j1 = 0;
      int delta = INF;
      for (int j(1), _b(n + 1); j < _b; ++j)
        if (!used[j]) {
          int cur = E[i0 - 1][j - 1] - u[i0] - v[j];
          if (cur < minv[j]) minv[j] = cur, way[j] = j0;
          if (minv[j] < delta) delta = minv[j], j1 = j;
        }
      for (int j(0), _b(n + 1); j < _b; ++j) {
        if (used[j])
          u[p2[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      }
      j0 = j1;
    } while (p2[j0] != 0);
    do {
      p2[j0] = p2[way[j0]];
      j0 = way[j0];
    } while (j0);
    go(i + 1, ka + (what == 0), kb + (what == 1));
    for (int j(0), _b(n + 1); j < _b; ++j) {
      p2[j] = pp2[j];
      way[j] = pway[j];
      u[j] = pu[j];
      v[j] = pv[j];
    }
  }
}
int main() {
  cin.tie(NULL);
  scanf("%d", &n);
  for (int i(0), _b(n); i < _b; ++i)
    for (int j(0), _b(n); j < _b; ++j) scanf("%d", a[i] + j);
  for (int i(0), _b(n); i < _b; ++i)
    for (int j(0), _b(n); j < _b; ++j) scanf("%d", b[i] + j);
  for (int i(0), _b(n); i < _b; ++i)
    for (int j(0), _b(n); j < _b; ++j) {
      a[i][j] = -a[i][j];
      b[i][j] = -b[i][j];
    }
  go(0, 0, 0);
  printf("%d\n", ans);
  return 0;
}
