#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
const int mod = 998244353;
int n;
int p[maxn], q[maxn], head[maxn], num, od[maxn], id[maxn], vis[maxn], s,
    dfn[maxn], low[maxn], st[maxn], tp, tot;
int s00, s01, s10, s11;
long long f[maxn][maxn], f1[maxn], f2[maxn], f3[maxn], ans1[maxn], ans[maxn],
    g[maxn][maxn], mul[maxn], inv[maxn];
struct Le {
  int nt, to;
} edge[maxn];
void add(int f, int t) {
  edge[++num].nt = head[f];
  edge[num].to = t;
  head[f] = num;
}
void dfs(int u, int fa) {
  vis[u] = 1;
  if (od[u] == 0 && (u != fa)) {
    if (fa == 0) s01++;
    return;
  }
  for (int i = head[u]; ~i; i = edge[i].nt) {
    int v = edge[i].to;
    if (v == 0 && fa == 0) s11++;
    if (vis[v]) {
      if (v != 0) s++;
      if (v == 0 && fa != 0) s10++;
      continue;
    }
    dfs(v, fa);
  }
}
long long poww(long long x, long long k) {
  long long ans = 1;
  while (k) {
    if (k & 1) ans = ans * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return ans;
}
long long C(int a, int b) { return mul[a] * inv[b] % mod * inv[a - b] % mod; }
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  g[1][1] = 1;
  g[0][0] = 1;
  mul[0] = 1;
  for (int i = 1; i <= n; ++i) mul[i] = mul[i - 1] * i % mod;
  inv[n] = poww(mul[n], mod - 2);
  for (int i = n; i; i--) inv[i - 1] = inv[i] * i % mod;
  inv[0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      g[i][j] = (g[i - 1][j - 1] + (i - 1) * g[i - 1][j]) % mod;
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]);
  for (int i = 1; i <= n; ++i) {
    if (p[i] == 0 && q[i] == 0) {
      s11++;
      s00++;
      continue;
    }
    if (p[i] == q[i]) {
      s++;
      continue;
    }
    od[p[i]]++;
    id[q[i]]++;
    add(p[i], q[i]);
  }
  for (int i = 0; i <= n; ++i)
    if ((!vis[i] && id[i] == 0) || i == 0) dfs(i, i);
  for (int i = 0; i <= n; ++i)
    if (!vis[i]) dfs(i, i);
  for (int i = 0; i <= s01; ++i)
    for (int j = i; j <= s01; ++j) {
      if (j != s01 && s11 - 1 < 0) continue;
      long long x = 0;
      if (s11 - 1 < 0)
        x = 1;
      else
        x = mul[s11 - 1 + (s01 - j)] * inv[s11 - 1] % mod;
      f1[i] = (f1[i] + C(s01, j) * g[j][i] % mod * x) % mod;
    }
  for (int i = 0; i <= s10; ++i)
    for (int j = i; j <= s10; ++j) {
      if (j != s10 && s11 - 1 < 0) continue;
      long long x = 0;
      if (s11 - 1 < 0)
        x = 1;
      else
        x = mul[s11 - 1 + (s10 - j)] * inv[s11 - 1] % mod;
      f2[i] = (f2[i] + C(s10, j) * g[j][i] % mod * x) % mod;
    }
  for (int i = 0; i <= s11; ++i) f3[i] = g[s11][i];
  for (int i = 0; i <= s01; ++i) {
    for (int j = 0; j <= s10; ++j)
      ans1[i + j] = (ans1[i + j] + f1[i] * f2[j] % mod) % mod;
  }
  for (int i = 0; i <= s01 + s10; ++i) {
    for (int j = 0; j <= s11; ++j)
      ans[i + j] = (ans[i + j] + ans1[i] * f3[j] % mod) % mod;
  }
  for (int i = n; i >= 1; --i)
    cout << (i - s >= 0 ? ans[i - s] * mul[s11] % mod : 0) << " ";
  puts("");
  return 0;
}
