#include <bits/stdc++.h>
using namespace std;
int n, Abuf[30][30], Bbuf[30][30], A[30][30], B[30][30];
int C[30][30];
int cntbit(int mask) { return mask ? (cntbit(mask & (mask - 1)) + 1) : 0; }
int u[40], v[40], p[40], way[40];
int minv[40], mn, order[40];
bool used[40];
int answer = 0;
void F(int deep, int cnt) {
  if (deep == n + 1) {
    int curanswer = 0;
    for (int i = 1; i <= n; i++) curanswer += C[p[i]][i];
    answer = max(answer, -curanswer);
    return;
  }
  int bufu[40], bufv[40], bufp[40];
  for (int i = 0; i <= n; i++) bufu[i] = u[i], bufv[i] = v[i], bufp[i] = p[i];
  if (cnt < n / 2) {
    for (int j = 1; j <= n; j++) C[deep][j] = -A[deep][j];
    p[0] = deep;
    int j0 = 0;
    for (int j = 0; j <= n; j++) minv[j] = 2e9, used[j] = false;
    do {
      used[j0] = true;
      int i0 = p[j0], delta = 2e9, j1;
      for (int j = 1; j <= n; ++j)
        if (!used[j]) {
          int cur = C[i0][j] - 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; j <= n; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      int j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
    F(deep + 1, cnt + 1);
  }
  for (int i = 0; i <= n; i++) u[i] = bufu[i], v[i] = bufv[i], p[i] = bufp[i];
  if (deep - cnt - 1 < n / 2) {
    for (int j = 1; j <= n; j++) C[deep][j] = -B[deep][j];
    p[0] = deep;
    int j0 = 0;
    for (int j = 0; j <= n; j++) minv[j] = 2e9, used[j] = false;
    do {
      used[j0] = true;
      int i0 = p[j0], delta = 2e9, j1;
      for (int j = 1; j <= n; ++j)
        if (!used[j]) {
          int cur = C[i0][j] - 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; j <= n; ++j)
        if (used[j])
          u[p[j]] += delta, v[j] -= delta;
        else
          minv[j] -= delta;
      j0 = j1;
    } while (p[j0] != 0);
    do {
      int j1 = way[j0];
      p[j0] = p[j1];
      j0 = j1;
    } while (j0);
    F(deep + 1, cnt);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) order[i] = i;
  random_shuffle(order + 1, order + n + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &Abuf[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &Bbuf[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      A[i][j] = Abuf[i][order[j]];
      B[i][j] = Bbuf[i][order[j]];
    }
  F(1, 0);
  cout << answer << endl;
  return 0;
}
