#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct Hungary {
  int nx, ny, cost[21][21], fx[21], fy[21], maty[21], which[21], dist[21];
  bool used[21];
  void init(int _nx, int _ny) {
    nx = _nx;
    ny = _ny;
    memset(fx, 0, sizeof(fx));
    memset(fy, 0, sizeof(fy));
    memset(maty, 0, sizeof(maty));
    memset(which, 0, sizeof(which));
    for (int i = 0; i <= nx; i++)
      for (int j = 0; j <= ny; j++) cost[i][j] = 1000000000;
  }
  void add(int x, int y, int c) { cost[x][y] = c; }
  void update(int x) {
    int y0 = 0;
    maty[0] = x;
    for (int y = 0; y <= ny; y++) {
      dist[y] = 1000000000 + 1;
      used[y] = false;
    }
    do {
      used[y0] = true;
      int x0 = maty[y0], delta = 1000000000 + 1, y1;
      for (int y = 1; y <= ny; y++)
        if (!used[y]) {
          int curdist = cost[x0][y] - fx[x0] - fy[y];
          if (curdist < dist[y]) {
            dist[y] = curdist;
            which[y] = y0;
          }
          if (dist[y] < delta) {
            delta = dist[y];
            y1 = y;
          }
        }
      for (int y = 0; y <= ny; y++)
        if (used[y]) {
          fx[maty[y]] += delta;
          fy[y] -= delta;
        } else
          dist[y] -= delta;
      y0 = y1;
    } while (maty[y0] != 0);
    do {
      int y1 = which[y0];
      maty[y0] = maty[y1];
      y0 = y1;
    } while (y0);
  }
} hungary;
int n;
int a[21][21];
int b[21][21];
int ans = 0;
void go(int pos, int bit, int cnt) {
  Hungary tmp;
  tmp.nx = hungary.nx;
  tmp.ny = hungary.ny;
  for (int i = (0); i < (21); i++) {
    tmp.fx[i] = hungary.fx[i];
    tmp.fy[i] = hungary.fy[i];
    tmp.maty[i] = hungary.maty[i];
    tmp.which[i] = hungary.which[i];
    tmp.dist[i] = hungary.dist[i];
  }
  for (int i = (0); i < (n); i++)
    if (bit == 1)
      hungary.add(pos + 1, i + 1, -a[pos][i]);
    else
      hungary.add(pos + 1, i + 1, -b[pos][i]);
  hungary.update(pos + 1);
  if (pos == n - 1) {
    if (cnt == (n >> 1)) {
      int tot = 0;
      for (int y = 1; y <= hungary.ny; y++) {
        int x = hungary.maty[y];
        if (hungary.cost[x][y] < 1000000000) tot -= hungary.cost[x][y];
      }
      ans = max(ans, tot);
    }
    hungary.nx = tmp.nx;
    hungary.ny = tmp.ny;
    for (int i = (0); i < (21); i++) {
      hungary.fx[i] = tmp.fx[i];
      hungary.fy[i] = tmp.fy[i];
      hungary.maty[i] = tmp.maty[i];
      hungary.which[i] = tmp.which[i];
      hungary.dist[i] = tmp.dist[i];
    }
    for (int i = (0); i < (n); i++)
      if (bit == 1)
        hungary.add(pos + 1, i + 1, 1000000000);
      else
        hungary.add(pos + 1, i + 1, 1000000000);
    return;
  }
  if (cnt + n - pos - 1 >= (n >> 1)) go(pos + 1, 0, cnt);
  if (cnt + 1 <= (n >> 1)) go(pos + 1, 1, cnt + 1);
  hungary.nx = tmp.nx;
  hungary.ny = tmp.ny;
  for (int i = (0); i < (21); i++) {
    hungary.fx[i] = tmp.fx[i];
    hungary.fy[i] = tmp.fy[i];
    hungary.maty[i] = tmp.maty[i];
    hungary.which[i] = tmp.which[i];
    hungary.dist[i] = tmp.dist[i];
  }
  for (int i = (0); i < (n); i++) hungary.add(pos + 1, i + 1, 1000000000);
}
void solve() {
  scanf("%d", &n);
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (n); j++) scanf("%d", &a[i][j]);
  for (int i = (0); i < (n); i++)
    for (int j = (0); j < (n); j++) scanf("%d", &b[i][j]);
  hungary.init(n, n);
  Hungary tmp;
  tmp.nx = hungary.nx;
  tmp.ny = hungary.ny;
  for (int i = (0); i < (21); i++) {
    tmp.fx[i] = hungary.fx[i];
    tmp.fy[i] = hungary.fy[i];
    tmp.maty[i] = hungary.maty[i];
    tmp.which[i] = hungary.which[i];
    tmp.dist[i] = hungary.dist[i];
  }
  for (int i = (0); i < (n); i++) hungary.add(1, i + 1, -a[0][i]);
  go(0, 0, 0);
  for (int i = (0); i < (21); i++) {
    hungary.fx[i] = tmp.fx[i];
    hungary.fy[i] = tmp.fy[i];
    hungary.maty[i] = tmp.maty[i];
    hungary.which[i] = tmp.which[i];
    hungary.dist[i] = tmp.dist[i];
  }
  for (int i = (0); i < (n); i++) hungary.add(1, i + 1, 1000000000);
  go(0, 1, 1);
  cout << ans;
}
int main() {
  solve();
  return 0;
}
