#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005, mod = 998244353;
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
int n, p[maxn], q[maxn], nxt[maxn], vis[maxn], deg[maxn], f[maxn], g[maxn],
    cnt[4], C[maxn][maxn], S[maxn][maxn], A[maxn][maxn];
void dfs(int u, int s) {
  vis[u] = 1;
  if (vis[nxt[u]] == 1 || !nxt[u]) {
    if (!s && u <= n && !nxt[u]) return;
    ++cnt[s | ((u > n) << 1)];
    return;
  }
  dfs(nxt[u], s);
}
void calc(int *f, int n, int m) {
  for (int i = 0; i <= n; ++i)
    for (int j = i; j <= n; ++j)
      f[i] = (f[i] + (long long)C[n][j] * S[j][i] % mod * A[m + n - j][n - j]) %
             mod;
  for (int i = 0; i <= n; ++i) {
    int t = 0;
    for (int j = i, d = 1; j <= n; ++j, d = mod - d)
      t = (t + (long long)d * C[j][i] % mod * f[j]) % mod;
    f[i] = t;
  }
}
void mul(int *a, int *b, int n, int m, int *c) {
  static int tmp[maxn];
  memset(tmp, 0, sizeof(int) * (n + m + 1));
  for (int i = 0; i <= n + m; ++i)
    for (int j = max(0, i - m); j <= i && j <= n; ++j)
      tmp[i] = (tmp[i] + (long long)b[i - j] * a[j]) % mod;
  memcpy(c, tmp, sizeof(int) * (n + m + 1));
}
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) p[i] = (p[i] = gi()) ? p[i] : i + n;
  for (int i = 1; i <= n; ++i) q[i] = (q[i] = gi()) ? q[i] : i + n;
  for (int i = 1; i <= n; ++i) nxt[p[i]] = q[i], ++deg[q[i]];
  for (int i = 1; i <= n + n; ++i)
    if (!vis[i] && !deg[i] && nxt[i]) dfs(i, i > n);
  for (int i = 1; i <= n + n; ++i)
    if (!vis[i] && nxt[i]) dfs(i, i > n);
  S[0][0] = C[0][0] = A[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    C[i][0] = 1;
    A[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      S[i][j] = (S[i - 1][j - 1] + (long long)(i - 1) * S[i - 1][j]) % mod,
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod,
      A[i][j] = (long long)A[i][j - 1] * (i - j + 1) % mod;
  }
  calc(f, cnt[1], cnt[3]);
  calc(g, cnt[2], cnt[3]);
  mul(f, g, cnt[1], cnt[2], f);
  mul(f, S[cnt[3]], cnt[1] + cnt[2], cnt[3], f);
  for (int i = 0; i <= n; ++i) f[i] = (long long)f[i] * A[cnt[3]][cnt[3]] % mod;
  for (int i = 0; i < n; ++i)
    printf("%d ", n - i - cnt[0] >= 0 ? f[n - i - cnt[0]] : 0);
  return 0;
}
