#include <bits/stdc++.h>
using namespace std;
const int N = 300, mod = 998244353;
int n, p[N], q[N], ans[N], f[N], g[N], h[N], t[N], tmp[N], len, cnt, A, B, C;
int s[N][N], c[N][N], fac[N], inv[N];
int head[N], deg[N], fp[N], vis[N], ce;
struct edge {
  int to, nxt;
} e[N];
void lnk(int a, int b) { e[++ce] = (edge){b, head[a]}, head[a] = ce; }
bool cycle(int u, int col) {
  if (vis[u] == col) return 1;
  if (vis[u]) return 0;
  vis[u] = col;
  for (int i = head[u]; i; i = e[i].nxt)
    if (cycle(e[i].to, col)) return 1;
  return 0;
}
bool dfs(int u) {
  if (!q[u]) return 0;
  if (!fp[q[u]]) return 1;
  return dfs(fp[q[u]]);
}
void mul(int *arr, int L) {
  for (int i = 0; i <= L + len; ++i) tmp[i] = 0;
  for (int i = 0; i <= L; ++i)
    for (int j = 0; j <= len; ++j)
      tmp[i + j] = (tmp[i + j] + 1ll * arr[i] * t[j]) % mod;
  len += L;
  for (int i = 0; i <= len; ++i) t[i] = tmp[i];
}
int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return ret;
}
int calc(int x, int y) {
  if (y == 0) return 1;
  if (x < y) return 0;
  return 1ll * fac[x] * inv[x - y] % mod;
}
void init() {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = qpow(fac[n], mod - 2);
  for (int i = n - 1; ~i; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  s[0][0] = c[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      s[i][j] = (s[i - 1][j - 1] + 1ll * (i - 1) * s[i - 1][j] % mod) % mod,
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
  }
}
int main() {
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), fp[p[i]] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]), ++deg[q[i]];
  for (int i = 1; i <= n; ++i)
    if (p[i] && q[i]) lnk(p[i], q[i]);
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      if (cycle(i, i)) ++cnt;
    }
  for (int i = 1; i <= n; ++i)
    if (p[i] == 0)
      if (dfs(i))
        ++B;
      else
        ++A;
    else if (!deg[p[i]] && !dfs(i))
      ++C;
  for (int i = 0; i <= B; ++i)
    for (int j = i; j <= B; ++j)
      f[i] = (f[i] + 1ll * c[B][j] * s[j][i] % mod *
                         calc(A + B - j - 1, B - j) % mod) %
             mod;
  for (int i = 0; i <= C; ++i)
    for (int j = i; j <= C; ++j)
      g[i] = (g[i] + 1ll * c[C][j] * s[j][i] % mod *
                         calc(A + C - j - 1, C - j) % mod) %
             mod;
  for (int i = 0; i <= A; ++i) h[i] = 1ll * s[A][i] * fac[A] % mod;
  len = 0, t[0] = 1;
  mul(f, B), mul(g, C), mul(h, A);
  for (int i = 0; i + cnt <= n; ++i) ans[n - i - cnt] = t[i];
  for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
  return 0;
}
