#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
const int mod = 998244353;
int p[255], q[255], in[255], mp[255], out[255], H;
int f[255], g[255], h[255], ans[255];
bool vis[255];
int c1, c2, blk, cyl;
int dfs(int x) {
  vis[x] = 1;
  if (x == H) return H;
  if (x == 0) return 0;
  if (out[x] == 0) return x;
  return dfs(mp[x]);
}
int C[255][255], A[255][255], s[255][255];
void init() {
  C[0][0] = 1;
  A[0][0] = 1;
  s[0][0] = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    C[i][0] = 1;
    A[i][0] = 1;
    s[i][0] = 0;
    for (int j = 1; j <= i; j++) {
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
      A[i][j] = ((long long)A[i - 1][j - 1] * j % mod + A[i - 1][j]) % mod;
      s[i][j] =
          (s[i - 1][j - 1] + (long long)s[i - 1][j] * (i - 1) % mod) % mod;
    }
  }
}
void cal(int n, int *f) {
  for (int i = n; i >= 0; i--) {
    for (int j = 0; j <= n; j++) {
      addmod(f[i],
             (long long)C[n][j] * s[j][i] % mod * A[n - j + blk][n - j] % mod,
             mod);
    }
    for (int j = i + 1; j <= n; j++) {
      addmod(f[i], mod - (long long)f[j] * C[j][i] % mod, mod);
    }
  }
}
void fmain() {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", p + i);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    scanf("%d", q + i);
    in[q[i]]++;
    if (p[i]) {
      mp[p[i]] = q[i];
      out[p[i]]++;
    }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    if (p[i] == 0) {
      H = p[i];
      int x = dfs(q[i]);
      if (x == 0)
        blk++;
      else
        c2++;
    } else if (in[p[i]] == 0) {
      vis[p[i]] = 1;
      H = p[i];
      int x = dfs(q[i]);
      if (x == 0)
        c1++;
      else if (x == H)
        cyl++;
    }
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++)
    if (p[i] != 0 && in[p[i]] != 0 && !vis[p[i]]) {
      H = p[i];
      int x = dfs(q[i]);
      assert(x == H);
      cyl++;
    }
  init();
  cal(c1, f);
  cal(c2, g);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      addmod(h[i], (long long)f[j] * g[i - j] % mod, mod);
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      addmod(ans[i], (long long)h[j] * s[blk][i - j] % mod, mod);
    }
    ans[i] = (long long)A[blk][blk] * ans[i] % mod;
  }
  for (int i = 0; i < n; i++) {
    if (n - i < cyl)
      printf("0 ");
    else
      printf("%d ", ans[n - i - cyl]);
  }
}
int main() {
  fmain();
  return 0;
}
