#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[3][maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
      a[i][j]--;
    }
  }
  return true;
}

int a0[3][maxn];
int fen[maxn];
int b[maxn];

void update(int i, int val) {
  for (; i < n; i |= i + 1) {
    fen[i] += val;
  }
}

int get(int i) {
  int res = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) {
    res += fen[i];
  }
  return res;
}

void solve() {
  for (int i = 0; i < n; i++) {
    if (a[1][i] % 3 != 1) {
      printf("No\n");
      return;
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      int x = a[i][j] % 3, y = a[i][j] / 3;
      if (((i + j) & 1) != ((x + y) & 1)) {
        printf("No\n");
        return;
      }
    }
  }
  for (int t = 0; t < 2; t++) {
    memset(fen, 0, sizeof(fen));
    memset(b, 0, sizeof(b));
    vector<pair<int, int>> tosort;
    int x = 0;
    for (int i = 0; i < n; i++) {
      if ((i & 1) == t) {
        int cur = a[1][i] / 3;
        tosort.push_back(make_pair(cur, i));
        int cnt = i / 2 - get(cur);
        b[i] ^= (cnt & 1);
        x ^= (cnt & 1);
        update(cur, 1);
      }
    }
    memset(fen, 0, sizeof(fen));
    for (int i = n - 1; i >= 0; i--) {
      if ((i & 1) == t) {
        int cur = a[1][i] / 3;
        b[i] ^= (get(cur) & 1);
        update(cur, 1);
      }
    }
    sort(tosort.begin(), tosort.end());
    if (x) {
      swap(a[0][t + 1], a[2][t + 1]);
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < n; j++) {
        a0[i][j] = a[i][j];
      }
    }
    for (int i = 0; i < sz(tosort); i++) {
      int x = tosort[i].second;
      int y = t + (2 * i);
      for (int j = 0; j < 3; j++) {
        a[j][y] = a0[j][x];
      }
      if (b[x]) {
        swap(a[0][y], a[2][y]);
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j + 1 < n; j++) {
      if (a[i][j] > a[i][j + 1]) {
        printf("No\n");
        return;
      }
    }
  }
  int msk = 0;
  for (int i = 0; i < n; i++) {
    if (a[0][i] % 3) {
      if (i + 4 > n) {
        msk ^= (1 << (n - 1 - i));
      } else {
        for (int j = 0; j < 4; j++) {
          swap(a[0][i + j], a[2][i + j]);
        }
      }
    }
  }
  if (msk == 5 && n >= 5) {
    printf("Yes\n");
    return;
  }
  if (msk) {
    printf("No\n");
    return;
  }
  printf("Yes\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 4336