#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long n, i, j, k, p[302], q[302], nxt[302], d[302], c[302][302],
    s[302][302], fac[302], inv, cnt1, cnt2, cnt3, cnt4, f[302], g[302], h[302],
    ans[302];
bool vis[302], vis1[302];
long long read() {
  char c = getchar();
  long long w = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') {
    w = w * 10 + c - '0';
    c = getchar();
  }
  return w;
}
void dfs(long long x) {
  if (!x) return;
  vis1[x] = vis[x] = 1;
  if (nxt[x] != x) {
    if (vis1[nxt[x]])
      cnt4++;
    else {
      dfs(nxt[x]);
      nxt[x] = nxt[nxt[x]];
    }
  }
  vis1[x] = 0;
}
long long poww(long long a, long long b) {
  long long ans = 1, base = a;
  while (b) {
    if (b & 1) ans = ans * base % mod;
    base = base * base % mod;
    b >>= 1;
  }
  return ans;
}
signed main() {
  n = read();
  for (i = 1; i <= n; i++) p[i] = read();
  for (i = 1; i <= n; i++) q[i] = read();
  for (i = 1; i <= n; i++) nxt[i] = i;
  for (i = 1; i <= n; i++) {
    if (p[i]) {
      if (p[i] == q[i])
        cnt4++, vis[p[i]] = 1;
      else
        nxt[p[i]] = q[i];
    }
    if (q[i]) d[q[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  for (i = 1; i <= n; i++) {
    if (!p[i]) {
      if (nxt[q[i]])
        cnt2++;
      else
        cnt3++;
    } else if (!d[p[i]] && !nxt[q[i]])
      cnt1++;
  }
  s[0][0] = c[0][0] = fac[0] = 1;
  for (i = 1; i <= n; i++) {
    c[i][0] = 1;
    for (j = 1; j <= i; j++) {
      s[i][j] = (s[i - 1][j - 1] + (i - 1) * s[i - 1][j] % mod) % mod;
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
    fac[i] = fac[i - 1] * i % mod;
  }
  inv = poww(fac[cnt3 - 1], mod - 2);
  for (i = 0; i <= cnt1; i++) {
    for (j = i; j <= cnt1; j++) {
      if (cnt1 + cnt3 - j - 1 >= 0)
        f[i] = (f[i] + s[j][i] * c[cnt1][j] % mod * fac[cnt1 + cnt3 - j - 1] %
                           mod * inv % mod) %
               mod;
      else
        f[i] = (f[i] + s[j][i] * c[cnt1][j] % mod) % mod;
    }
  }
  for (i = 0; i <= cnt2; i++) {
    for (j = i; j <= cnt2; j++) {
      if (cnt2 + cnt3 - j - 1 >= 0)
        g[i] = (g[i] + s[j][i] * c[cnt2][j] % mod * fac[cnt2 + cnt3 - j - 1] %
                           mod * inv % mod) %
               mod;
      else
        g[i] = (g[i] + s[j][i] * c[cnt2][j] % mod) % mod;
    }
  }
  for (i = 0; i <= cnt3; i++) h[i] = s[cnt3][i] * fac[cnt3] % mod;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= i; j++) {
      for (k = 0; j + k <= i; k++)
        ans[i] = (ans[i] + f[j] * g[k] % mod * h[i - j - k] % mod) % mod;
    }
  }
  for (i = 0; i < n; i++) {
    if (n - i - cnt4 < 0)
      printf("0 ");
    else
      printf("%lld ", ans[n - i - cnt4]);
  }
  puts("");
  return 0;
}
