#include <bits/stdc++.h>
using namespace std;
long long qpow(long long x, long long y = 998244353 - 2) {
  long long r = 1;
  for (; y; y >>= 1, x = x * x % 998244353)
    if (y & 1) r = r * x % 998244353;
  return r;
}
int n;
int p[2505], q[2505];
long long fac[2505], ifac[2505];
long long s[2505][2505];
void initCs() {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % 998244353;
  ifac[n] = qpow(fac[n]);
  for (int i = n - 1; i >= 0; --i) ifac[i] = ifac[i + 1] * (i + 1) % 998244353;
  s[0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j)
      s[i][j] = (s[i - 1][j - 1] + (i - 1) * s[i - 1][j]) % 998244353;
}
long long C(int m, int n) {
  return fac[m] * ifac[n] % 998244353 * ifac[m - n] % 998244353;
}
int a, b, c, o;
int dsu[2505];
int getdsu(int x) { return dsu[x] == x ? x : dsu[x] = getdsu(dsu[x]); }
void initabc() {
  for (int i = 1; i <= n; ++i) dsu[i] = i;
  for (int i = 1; i <= n; ++i) {
    int u = getdsu(p[i]), v = getdsu(q[i]);
    if (u && v) o += (dsu[u] == dsu[v]), dsu[u] = v;
  }
  static int bz[2505];
  for (int i = 1; i <= n; ++i) {
    int u = getdsu(p[i]), v = getdsu(q[i]);
    if (!u && !v)
      c++;
    else if (!u && v) {
      if (bz[v] == 1)
        c++, b--;
      else
        bz[v] = -1, a++;
    } else if (u && !v) {
      if (bz[u] == -1)
        c++, a--;
      else
        bz[u] = 1, b++;
    }
  }
}
int f[2505], g[2505], h[2505], pro[2505];
void rev(int a, int f[]) {
  static int F[2505];
  for (int i = 0; i <= a; ++i) {
    long long sum = 0;
    for (int j = i; j <= a; ++j)
      (sum += f[j] * C(j, i) * (j - i & 1 ? -1 : 1)) %= 998244353;
    F[i] = (sum + 998244353) % 998244353;
  }
  memcpy(f, F, sizeof(int) * (a + 1));
}
void calcfg(int a, int f[]) {
  for (int i = 0; i <= a; ++i) {
    long long sum = 0;
    for (int j = i; j <= a; ++j)
      (sum += C(a, j) * s[j][i] % 998244353 * fac[a - j + c] % 998244353 *
              ifac[c]) %= 998244353;
    f[i] = sum;
  }
  rev(a, f);
}
void multi(int c[], int a[], int b[]) {
  static int t[2505];
  for (int i = 0; i <= n; ++i) {
    long long sum = 0;
    for (int j = 0; j <= i; ++j)
      sum = (sum + (long long)a[j] * b[i - j]) % 998244353;
    t[i] = sum;
  }
  memcpy(c, t, sizeof(int) * (n + 1));
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]);
  initCs();
  initabc();
  calcfg(a, f);
  calcfg(b, g);
  for (int i = 0; i <= c; ++i) h[i] = s[c][i];
  multi(pro, f, g);
  multi(pro, pro, h);
  for (int i = 0; i < n; ++i)
    printf("%d ", (n - o - i >= 0 ? pro[n - o - i] : 0) * fac[c] % 998244353);
  return 0;
}
