#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int n, ans, co[2][N][N];
struct node {
  int matl[N], matr[N];
  int w[N][N], from[N];
  int vx[N], vy[N], v[N];
  int lx[N], ly[N], q[N];
  void extend(int x) {
    for (; x; swap(x, matr[from[x]])) matl[x] = from[x];
  }
  void KM(int id) {
    for (int i = (int)(1); i <= (int)(n); i++)
      lx[id] = max(lx[id], w[id][i] - ly[i]);
    memset(vx, 0, sizeof(vx));
    memset(vy, 0, sizeof(vy));
    memset(v, 30, sizeof(v));
    int h = 0, t = 1;
    q[1] = id;
    vx[id] = 1;
    for (;;) {
      for (; h != t;) {
        int x = q[++h];
        for (int i = (int)(1); i <= (int)(n); i++)
          if (!vy[i]) {
            int tmp = lx[x] + ly[i] - w[x][i];
            if (tmp > v[i]) continue;
            from[i] = x;
            if (!tmp) {
              if (!matl[i]) return extend(i);
              vy[i] = vx[matl[i]] = 1;
              q[++t] = matl[i];
            } else
              v[i] = tmp;
          }
      }
      int val = 1 << 30, p;
      for (int i = (int)(1); i <= (int)(n); i++)
        if (!vy[i] && val > v[i]) val = v[i], p = i;
      for (int i = (int)(1); i <= (int)(n); i++) {
        if (vx[i]) lx[i] -= val;
        if (vy[i])
          ly[i] += val;
        else
          v[i] -= val;
      }
      if (!matl[p]) return extend(p);
      h = 0;
      t = 1;
      vy[p] = vx[matl[p]] = 1;
      q[1] = matl[p];
    }
  }
  int VAL() {
    int ans = 0;
    for (int i = (int)(1); i <= (int)(n); i++) ans += lx[i] + ly[i];
    return ans;
  }
} D[N];
void dfs(int x, int cnt) {
  if (x > n) {
    ans = max(ans, D[n].VAL());
    return;
  }
  for (int c = (int)(0); c <= (int)(1); c++) {
    cnt += c;
    if (cnt * 2 > n || (x - cnt) * 2 > n) continue;
    D[x] = D[x - 1];
    for (int j = (int)(1); j <= (int)(n); j++) D[x].w[x][j] = co[c][x][j];
    D[x].KM(x);
    dfs(x + 1, cnt);
  }
}
int main() {
  scanf("%d", &n);
  for (int T = (int)(0); T <= (int)(1); T++)
    for (int i = (int)(1); i <= (int)(n); i++)
      for (int j = (int)(1); j <= (int)(n); j++) scanf("%d", &co[T][i][j]);
  dfs(1, 0);
  printf("%d\n", ans);
}
