#include <bits/stdc++.h>
using namespace std;
const long long N = 2009, M = 998244353;
long long n, a[N], b[N], to[N], A, B, C, Ans, rev[N], S1[N][N], f[N], g[N],
    h[N], fac[N], inv_fac[N], ans[N], vis[N], F[N], G[N];
long long in[N], out[N];
struct Union {
  long long fa[N];
  void init() {
    for (long long i = 1; i <= n; i++) fa[i] = i;
  }
  long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
  void merge(long long x, long long y) { fa[find(y)] = find(x); }
  bool connected(long long x, long long y) { return find(x) == find(y); }
} U;
void init() {
  memset(rev, -1, sizeof(rev));
  memset(to, -1, sizeof(to));
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= n; i++)
    scanf("%lld", &b[i]), to[a[i]] = b[i], rev[b[i]] = a[i];
}
long long ksm(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % M;
    b >>= 1, a = a * a % M;
  }
  return res;
}
long long binom(long long n, long long m) {
  if (n < m) return 0;
  return fac[n] * inv_fac[m] % M * inv_fac[n - m] % M;
}
void work() {
  U.init();
  for (long long i = 1; i <= n; i++)
    if (a[i] && b[i]) {
      if (U.connected(a[i], b[i])) Ans++, C--;
      U.merge(a[i], b[i]);
    }
  for (long long i = 1; i <= n; i++)
    if (a[i] && !b[i])
      in[U.find(a[i])] = 1;
    else if (!a[i] && b[i])
      out[U.find(b[i])] = 1;
  for (long long i = 1; i <= n; i++)
    if (U.find(i) == i) {
      if (in[i] && !out[i])
        A++;
      else if (!in[i] && out[i])
        B++;
      else if (!in[i] && !out[i])
        C++;
    }
  S1[0][0] = 1;
  for (long long i = 1; i <= 2000; i++)
    for (long long j = 1; j <= i; j++)
      S1[i][j] = (S1[i - 1][j - 1] + S1[i - 1][j] * (i - 1) % M) % M;
  fac[0] = 1;
  for (long long i = 1; i <= 2000; i++) fac[i] = fac[i - 1] * i % M;
  inv_fac[2000] = ksm(fac[2000], M - 2);
  for (long long i = 1999; i >= 0; i--)
    inv_fac[i] = inv_fac[i + 1] * (i + 1) % M;
  for (long long i = 0; i <= A; i++)
    for (long long j = i; j <= A; j++)
      f[i] = (f[i] + binom(A, j) * S1[j][i] % M * fac[A + C - j] % M *
                         inv_fac[C] % M) %
             M;
  for (long long i = 0; i <= A; i++)
    for (long long j = i; j <= n; j++)
      F[i] = (F[i] + binom(j, i) * f[j] % M * (j - i & 1 ? -1 : 1)) % M;
  for (long long i = 0; i <= B; i++)
    for (long long j = i; j <= B; j++)
      g[i] = (g[i] + binom(B, j) * S1[j][i] % M * fac[B + C - j] % M *
                         inv_fac[C] % M) %
             M;
  for (long long i = 0; i <= B; i++)
    for (long long j = i; j <= n; j++)
      G[i] = (G[i] + binom(j, i) * g[j] % M * (j - i & 1 ? -1 : 1)) % M;
  for (long long i = 0; i <= A + B; i++)
    for (long long j = 0; j <= i; j++) h[i] = (h[i] + F[j] * G[i - j] % M) % M;
  for (long long i = 0; i <= A + B + C; i++)
    for (long long j = 0; j <= i; j++)
      ans[i] = (ans[i] + h[j] * S1[C][i - j] % M * fac[C] % M) % M;
  for (long long i = 0; i < n; i++)
    printf("%lld ", n - i - Ans >= 0 ? (ans[n - i - Ans] + M) % M : 0);
}
signed main() {
  init();
  work();
  return 0;
}
