#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int data = 0, m = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') {
    m = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    data = (data << 1) + (data << 3) + (ch ^ 48);
    ch = getchar();
  }
  return (m) ? data : -data;
}
int CNT[5], Q[2][2005], pos[2][2005], g[2005], ox[2005], xo[2005], Ans1[2005],
    Ans[2005], ans[2005];
int n, m;
int S[2005][2005], A[2005][2005], C[2005][2005], Fac[2005], deg[2005];
bool vis[2005];
int nt[2005];
void dfs(int u, int ff) {
  vis[u] = true;
  if (nt[u]) {
    if (!vis[nt[u]])
      dfs(nt[u], ff);
    else
      CNT[3] += 1;
  } else {
    if (u > n && ff > n)
      CNT[0] += 1;
    else if (u <= n && ff > n)
      CNT[2] += 1;
    else if (u > n && ff <= n)
      CNT[1] += 1;
  }
}
inline void Init() {
  n = gi();
  for (int i = 1; i <= n; i++) Q[0][i] = gi(), pos[0][Q[0][i]] = i;
  for (int i = 1; i <= n; i++) Q[1][i] = gi(), pos[1][Q[1][i]] = i;
  memset(vis, true, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    if (!Q[0][i]) Q[0][i] = i + n;
    if (!Q[1][i]) Q[1][i] = i + n;
    vis[Q[0][i]] = vis[Q[1][i]] = false;
    if (Q[0][i] <= n || Q[1][i] <= n) nt[Q[0][i]] = Q[1][i], ++deg[Q[1][i]];
  }
  for (int i = 1; i <= n + n; ++i)
    if (!vis[i] && !deg[i]) dfs(i, i);
  for (int i = 1; i <= n + n; ++i)
    if (!vis[i]) dfs(i, i);
  return;
}
inline void Numb() {
  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] % 998244353) %
                998244353;
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 998244353;
    }
  }
  for (int i = 0; i <= n; i++) A[i][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= i; j++)
      A[i][j] = 1ll * A[i][j - 1] * (i - j + 1) % 998244353;
  Fac[0] = 1;
  for (int i = 1; i <= n; i++) Fac[i] = 1ll * i * Fac[i - 1] % 998244353;
  return;
}
inline void Calc(int *h, int op) {
  memset(g, 0, sizeof(g));
  memset(h, 0, sizeof(h));
  int nC = CNT[op];
  for (int i = 0; i <= nC; i++)
    for (int j = i; j <= nC; j++)
      g[i] = (g[i] + 1ll * C[nC][j] * S[j][i] % 998244353 *
                         A[CNT[0] + nC - j][nC - j] % 998244353) %
             998244353;
  for (int i = 0; i <= nC; i++)
    for (int j = i; j <= nC; j++)
      h[i] = (h[i] + 1ll * (((j - i) & 1) ? 998244353 - 1 : 1ll) * C[j][i] %
                         998244353 * g[j] % 998244353) %
             998244353;
  return;
}
int main() {
  Init();
  Numb();
  Calc(ox, 1);
  Calc(xo, 2);
  for (int i = 0; i <= CNT[1]; i++)
    for (int j = 0; j <= CNT[2]; j++)
      Ans1[i + j] = (Ans1[i + j] + 1ll * ox[i] * xo[j] % 998244353) % 998244353;
  for (int i = 0; i <= CNT[1] + CNT[2]; i++)
    for (int j = 0; j + i <= n; j++)
      Ans[i + j] =
          (Ans[i + j] + 1ll * Ans1[i] * S[CNT[0]][j] % 998244353) % 998244353;
  for (int i = 0; i <= n; i++)
    if (n - CNT[3] - i >= 0) ans[n - CNT[3] - i] = Ans[i];
  for (int i = 0; i < n; i++)
    cout << 1ll * Fac[CNT[0]] * ans[i] % 998244353 << " ";
  puts("");
  return 0;
}
