#include <bits/stdc++.h>
const int N = 250, MOD = 998244353;
int n, a[N + 5], b[N + 5], pre[N + 5], nxt[N + 5], fac[N + 5], c[N + 5][N + 5],
    s[N + 5][N + 5];
bool fst[N + 5], lst[N + 5], vis[N + 5];
inline void add(int &x, const int &y) { (x += y) >= MOD && (x -= MOD); }
void init(int n) {
  c[0][0] = s[0][0] = fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    c[i][0] = 1;
    fac[i] = (long long)fac[i - 1] * i % MOD;
    for (int j = 1; j <= i; j++) {
      add(c[i][j] = c[i - 1][j], c[i - 1][j - 1]);
      add(s[i][j] = s[i - 1][j - 1], (long long)s[i - 1][j] * (i - 1) % MOD);
    }
  }
}
inline std::vector<int> operator*(const std::vector<int> &F,
                                  const std::vector<int> &G) {
  std::vector<int> H(F.size() + G.size() - 1, 0);
  for (int i = 0; i < (int)F.size(); i++) {
    for (int j = 0; j < (int)G.size(); j++) {
      add(H[i + j], (long long)F[i] * G[j] % MOD);
    }
  }
  return H;
}
int main() {
  scanf("%d", &n);
  init(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  int cxy = 0, cx0 = 0, c0y = 0, c00 = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] > 0 && b[i] > 0) {
      pre[b[i]] = a[i];
      nxt[a[i]] = b[i];
    } else if (a[i] > 0) {
      lst[a[i]] = true;
    } else if (b[i] > 0) {
      fst[b[i]] = true;
    } else {
      c00++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      vis[i] = true;
      int s = i, t = i;
      for (; pre[s] > 0 && !vis[pre[s]]; s = pre[s], vis[s] = true)
        ;
      for (; nxt[t] > 0 && !vis[nxt[t]]; t = nxt[t], vis[t] = true)
        ;
      if (nxt[t] == s) {
        cxy++;
      } else if (fst[s] && !lst[t]) {
        c0y++;
      } else if (!fst[s] && lst[t]) {
        cx0++;
      } else if (fst[s] && lst[t]) {
        c00++;
      }
    }
  }
  std::vector<int> F(c0y + 1), G(cx0 + 1), H(c00 + 1);
  for (int i = 0; i <= c0y; i++) {
    long long sum = 0;
    for (int j = i; j <= c0y; j++) {
      sum += (long long)s[j][i] * c[c0y][j] % MOD *
             (c0y == j ? 1 : c[c00 - 1 + c0y - j][c00 - 1]) % MOD *
             fac[c0y - j] % MOD;
    }
    F[i] = sum % MOD;
  }
  for (int i = 0; i <= cx0; i++) {
    long long sum = 0;
    for (int j = i; j <= cx0; j++) {
      sum += (long long)s[j][i] * c[cx0][j] % MOD *
             (cx0 == j ? 1 : c[c00 - 1 + cx0 - j][c00 - 1]) % MOD *
             fac[cx0 - j] % MOD;
    }
    G[i] = sum % MOD;
  }
  for (int i = 0; i <= c00; i++) {
    H[i] = (long long)s[c00][i] * fac[c00] % MOD;
  }
  std::vector<int> P = F * G * H;
  for (int i = 0, j = n - cxy; i < n; i++, j--) {
    printf("%d%c", 0 <= j && j < (int)P.size() ? P[j] : 0, " \n"[i == n - 1]);
  }
  return 0;
}
