#include <bits/stdc++.h>
using namespace std;
const int maxn = 261;
const int mod = (7 * 17 << 23) + 1;
int n, p[maxn], q[maxn];
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", p + i);
  for (int i = 1; i <= n; ++i) scanf("%d", q + i);
}
int A = 0, B = 0, C = 0, D = 0, K = 0;
void preset() {
  static int wp[maxn], wq[maxn];
  memset(wp, 0, sizeof(wp));
  memset(wq, 0, sizeof(wq));
  for (int i = 1; i <= n; ++i)
    if (p[i]) wp[p[i]] = i;
  for (int i = 1; i <= n; ++i)
    if (q[i]) wq[q[i]] = i;
  static bool vis[maxn];
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      int a = p[i], b = q[i];
      vis[i] = 1;
      while (b && wp[b] && !vis[wp[b]]) vis[wp[b]] = 1, b = q[wp[b]];
      while (a && wq[a] && !vis[wq[a]]) vis[wq[a]] = 1, a = p[wq[a]];
      if ((wp[b] && vis[wp[b]]) || (wq[a] && vis[wq[a]])) {
        ++K;
        continue;
      }
      if (!a && b) ++A;
      if (a && !b) ++B;
      if (a && b) ++C;
      if (!a && !b) ++D;
    }
}
int fac[maxn], in_fac[maxn];
int power(int a, int t) {
  int res = 1;
  for (; t; t >>= 1, a = 1LL * a * a % mod)
    if (t & 1) res = 1LL * res * a % mod;
  return res;
}
void preset_fact() {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
  in_fac[n] = power(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; --i) in_fac[i] = in_fac[i + 1] * (i + 1LL) % mod;
}
int c(int n, int m) {
  if (!m) return 1;
  return 1LL * fac[n] * in_fac[m] % mod * in_fac[n - m] % mod;
}
void work() {
  preset();
  preset_fact();
  static int f[maxn][maxn];
  memset(f, 0, sizeof(f));
  f[0][0] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= i; ++k)
        f[i][j] =
            (f[i][j] + 1LL * f[i - k][j - 1] * c(i, k) % mod * fac[k - 1]) %
            mod;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) f[i][j] = (1LL * f[i][j] * in_fac[j]) % mod;
  static int g[maxn][maxn][maxn];
  memset(g, 0, sizeof(g));
  for (int i = 0; i <= A; ++i)
    for (int j = 0; j <= B; ++j)
      for (int k = 0; k <= i + j; ++k)
        for (int x = 0; x <= k; ++x)
          g[i][j][k] = (g[i][j][k] + 1LL * f[i][x] * f[j][k - x]) % mod;
  static int ans[maxn];
  memset(ans, 0, sizeof(ans));
  for (int k = 0; k <= n - K; ++k)
    for (int a = 0; a <= A; ++a)
      for (int b = 0; b <= B; ++b) {
        int Q = min(a + b, k), tmp = 1LL * c(A - a + D - 1, A - a) *
                                     c(B - b + D - 1, B - b) % mod *
                                     fac[A - a] % mod * fac[B - b] % mod *
                                     c(A, a) % mod * c(B, b) % mod;
        for (int kk = 0; kk <= Q; ++kk) {
          int Dk = k - kk;
          if (Dk > D) continue;
          ans[k + K] =
              (ans[k + K] + 1LL * g[a][b][kk] * f[D][Dk] % mod * tmp) % mod;
        }
      }
  for (int i = n; i >= 1; --i)
    printf("%d ", (int)(1LL * ans[i] * fac[D] % mod));
  puts("");
}
int main() {
  init();
  work();
  return 0;
}
