#include <bits/stdc++.h>
using namespace std;
int f[251][251][251], g[251][251], ans[251];
const int p = 998244353;
struct node {
  int x, y;
} a[251];
int dfs(int x, int y, int cir) {
  if (x < 0 || y < 0 || cir < 0) return 0;
  if (f[x][y][cir] != -1) return f[x][y][cir];
  if (x == 0 && y == 0) return cir == 0;
  int re;
  if (y) {
    re = ((long long)dfs(x - 1, y, cir) * x + dfs(x, y - 1, cir)) % p;
  } else {
    re = ((long long)dfs(x - 1, y, cir) * (x - 1) + dfs(x - 1, y, cir - 1)) % p;
  }
  f[x][y][cir] = re;
  return re;
}
int gfs(int x, int cir) {
  if (x == 0) return cir == 0;
  if (cir < 0) return 0;
  if (g[x][cir] != -1) return g[x][cir];
  return g[x][cir] =
             (gfs(x - 1, cir - 1) + (long long)gfs(x - 1, cir) * (x - 1)) % p;
}
int main() {
  int n, cir = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].x);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].y);
  bool ok = 1;
  int nn = n;
  while (ok) {
    ok = 0;
    for (int j = 1; j <= n; j++) {
      for (int k = j; k <= n; k++)
        if (a[j].x == a[k].y && a[j].x != 0 ||
            a[j].y == a[k].x && a[j].y != 0) {
          ok = 1;
          if (j == k) {
            cir++;
            a[j] = a[n];
            n--;
          } else if (a[j].x == a[k].y && a[j].x) {
            a[j].x = a[k].x;
            a[k] = a[n];
            n--;
          } else if (a[j].y == a[k].x && a[j].y) {
            a[j].y = a[k].y;
            a[k] = a[n];
            n--;
          }
          break;
        }
      if (ok) break;
    }
  }
  for (int i = 1; i <= n; i++)
    if (a[i].x && a[i].y) {
      a[i] = a[n];
      n--;
      i--;
    }
  int x = 0, y = 0, z = 0;
  for (int i = 1; i <= n; i++)
    if (a[i].x + a[i].y == 0)
      z++;
    else if (a[i].x)
      x++;
    else if (a[i].y)
      y++;
  memset(f, -1, sizeof f);
  memset(g, -1, sizeof g);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= i; j++)
      for (int k = 0; k <= i - j; k++)
        if (dfs(y, z, j) != 0 && dfs(x, z, k) != 0) {
          int l = i - j - k;
          if (gfs(z, l) != 0)
            ans[i + cir] = (ans[i + cir] + (long long)dfs(y, z, j) *
                                               dfs(x, z, k) % p * gfs(z, l)) %
                           p;
        }
  }
  n = nn;
  for (int i = 0; i <= n / 2; i++) swap(ans[i], ans[n - i]);
  long long tp = 1;
  for (int i = 1; i <= z; i++) tp = tp * i % p;
  for (int i = 0; i <= n - 1; i++) printf("%I64d ", ans[i] * tp % p);
}
