#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
int A[25], B[25], lk[25], way[25], mn[25];
int w[25][25];
int a[25][25], b[25][25];
bool vis[25];
int ans;
inline void km(int x) {
  lk[0] = x;
  int j0 = 0;
  memset(vis, 0, sizeof(vis));
  memset(mn, 0x3f, sizeof(mn));
  do {
    vis[j0] = true;
    int i0 = lk[j0], num = 0x3f3f3f3f, j1;
    for (int j = 1; j <= n; j++) {
      if (!vis[j]) {
        int t = -w[i0][j] + A[i0] + B[j];
        if (t < mn[j]) mn[j] = t, way[j] = j0;
        if (mn[j] < num) num = mn[j], j1 = j;
      }
    }
    for (int j = 0; j <= n; j++) {
      if (vis[j])
        A[lk[j]] -= num, B[j] += num;
      else
        mn[j] -= num;
    }
    j0 = j1;
  } while (~lk[j0]);
  do {
    int j1 = way[j0];
    lk[j0] = lk[j1];
    j0 = j1;
  } while (j0);
}
inline void dfs(int x, int t) {
  if (x == n + 1) {
    ans = max(ans, -B[0]);
    return;
  }
  int oA[25], oB[25], m;
  if (t == (n >> 1)) {
    for (int i = 1; i <= n; i++) w[x][i] = a[x][i];
    km(x);
    dfs(x + 1, t);
    for (int i = 1; i <= n; i++) w[x][i] = 0;
  } else if (x - t - 1 == (n >> 1)) {
    for (int i = 1; i <= n; i++) w[x][i] = b[x][i];
    km(x);
    dfs(x + 1, t + 1);
    for (int i = 1; i <= n; i++) w[x][i] = 0;
  } else {
    int oa[25], ob[25], olk[25], oway[25];
    memcpy(oa, A, sizeof(A));
    memcpy(ob, B, sizeof(B));
    memcpy(olk, lk, sizeof(lk));
    memcpy(oway, way, sizeof(way));
    for (int i = 1; i <= n; i++) w[x][i] = a[x][i];
    km(x);
    dfs(x + 1, t);
    for (int i = 1; i <= n; i++) w[x][i] = 0;
    memcpy(A, oa, sizeof(oa));
    memcpy(B, ob, sizeof(ob));
    memcpy(lk, olk, sizeof(olk));
    memcpy(way, oway, sizeof(oway));
    for (int i = 1; i <= n; i++) w[x][i] = b[x][i];
    km(x);
    dfs(x + 1, t + 1);
    for (int i = 1; i <= n; i++) w[x][i] = 0;
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      a[i][j] = read();
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      b[i][j] = read();
    }
  }
  memset(lk, -1, sizeof(lk));
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
