#include <bits/stdc++.h>
using namespace std;
const int maxn = 400, p = 998244353;
int n, a, b, c, d;
int vis1[maxn], vis[maxn], nxt[maxn], a1[maxn], b1[maxn], ans[maxn],
    indgr[maxn], fac[maxn];
int f[maxn], g[maxn], h[maxn];
int s[maxn][maxn], C[maxn][maxn], D[maxn][maxn];
void dfs(int x) {
  if (!x) return;
  vis1[x] = 1;
  vis[x] = 1;
  if (nxt[x] != x) {
    if (vis1[nxt[x]])
      ++d;
    else {
      dfs(nxt[x]);
      nxt[x] = nxt[nxt[x]];
    }
  }
  vis1[x] = 0;
}
void pre() {
  s[0][0] = s[1][1] = 1;
  for (int i = 2; 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]) % p;
  C[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % p;
    C[i][0] = 1;
  }
  D[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    D[i][0] = 1;
    for (int j = 1; j <= i; ++j) D[i][j] = 1ll * D[i][j - 1] * (i - j + 1) % p;
  }
  fac[0] = fac[1] = 1;
  for (int i = 2; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
}
int main() {
  cin >> n;
  pre();
  for (int i = 1; i <= n; ++i) cin >> a1[i];
  for (int i = 1; i <= n; ++i) cin >> b1[i];
  for (int i = 1; i <= n; ++i) nxt[i] = i;
  for (int i = 1; i <= n; ++i) {
    if (a1[i]) {
      if (a1[i] == b1[i]) {
        ++d;
        vis[a1[i]] = 1;
      } else
        nxt[a1[i]] = b1[i];
    }
    if (b1[i]) ++indgr[b1[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) dfs(i);
  for (int i = 1; i <= n; ++i)
    if (!a1[i]) {
      if (nxt[b1[i]])
        ++b;
      else
        ++a;
    } else if (!indgr[a1[i]] && !nxt[b1[i]])
      ++c;
  for (int i = 0; i <= b; ++i)
    for (int j = i; j <= b; ++j)
      f[i] =
          (f[i] + 1ll * s[j][i] * C[b][j] % p *
                      (a + b - j - 1 >= 0 ? D[a + b - j - 1][b - j] : 1) % p) %
          p;
  for (int i = 0; i <= c; ++i)
    for (int j = i; j <= c; ++j)
      g[i] =
          (g[i] + 1ll * s[j][i] * C[c][j] % p *
                      (a + c - j - 1 >= 0 ? D[a + c - j - 1][c - j] : 1) % p) %
          p;
  for (int i = 0; i <= a; ++i) h[i] = 1ll * s[a][i] * fac[a] % p;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= i - j; ++k)
        ans[i] = (ans[i] + 1ll * h[j] * f[k] % p * g[i - j - k] % p) % p;
  for (int i = 0; i < n; ++i) {
    if (n - i - d < 0)
      printf("0 ");
    else
      printf("%d ", ans[n - i - d]);
  }
}
