#include <bits/stdc++.h>
inline int read() {
  int data = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
  return data * w;
}
const int N(505), Mod(998244353);
int n, a[N], b[N], deg[N], f[N], g[N], h[N], fac[N];
int ans[N], vis[N], cnt[4], nxt[N], s[N][N], inv[N];
inline int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
inline int A(int n, int m) { return 1ll * fac[n] * inv[n - m] % Mod; }
void dfs(int x, int f) {
  vis[x] = 1;
  if (nxt[x]) {
    if (!vis[nxt[x]])
      dfs(nxt[x], f);
    else
      ++cnt[3];
  } else if (x > n && f > n)
    ++cnt[2];
  else if (x <= n && f > n)
    ++cnt[1];
  else if (x > n && f <= n)
    ++cnt[0];
}
int fastpow(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = 1ll * x * x % Mod)
    if (y & 1) ans = 1ll * ans * x % Mod;
  return ans;
}
void calc(int *f, int n) {
  for (int i = 0; i <= n; i++)
    for (int j = i; j <= n; j++)
      f[i] = (f[i] + 1ll * C(n, j) * s[j][i] % Mod * A(n - j + cnt[2], n - j)) %
             Mod;
  for (int i = 0, t = 0; i <= n; f[i] = t, t = 0, i++)
    for (int j = i, o = 1; j <= n; j++, o = Mod - o)
      t = (t + 1ll * o * f[j] % Mod * C(j, i)) % Mod;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) b[i] = read();
  for (int i = 1; i <= (n << 1); i++) vis[i] = 1;
  for (int i = 1; i <= n; i++) {
    if (!a[i]) a[i] = i + n;
    if (!b[i]) b[i] = i + n;
    vis[a[i]] = vis[b[i]] = 0;
    if (a[i] <= n || b[i] <= n) nxt[a[i]] = b[i], ++deg[b[i]];
  }
  for (int i = 1; i <= (n << 1); i++)
    if (!vis[i] && !deg[i]) dfs(i, i);
  for (int i = 1; i <= (n << 1); i++)
    if (!vis[i]) dfs(i, i);
  s[0][0] = fac[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
  inv[n] = fastpow(fac[n], Mod - 2);
  for (int i = n - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      s[i][j] = (s[i - 1][j - 1] + 1ll * (i - 1) * s[i - 1][j]) % Mod;
  calc(f, cnt[0]), calc(g, cnt[1]);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++) h[i] = (h[i] + 1ll * f[j] * g[i - j]) % Mod;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= i; j++)
      ans[i] = (ans[i] + 1ll * h[j] * s[cnt[2]][i - j]) % Mod;
  for (int i = 0; i <= n; i++) ans[i] = 1ll * ans[i] * fac[cnt[2]] % Mod;
  for (int i = 0; i < n; i++)
    printf("%d%c", n - i - cnt[3] >= 0 ? ans[n - i - cnt[3]] : 0,
           " \n"[i == n - 1]);
  return 0;
}
