func_code_string: #include <bits/stdc++.h>   using namespace std;   long long len, ans, s0, s1, s2, fac[2001], invfac[2001], S[2001][2001],       lst[2001], n, a[2001], b[2001], pv[2001], nxt[2001], F[2001], f[2001],       G[2001], g[2001], h[2001], k[2001], K[2001], minn[2001];   int read() {     char c = 0;     int sum = 0;     while (c <  0  || c >  9 ) c = getchar();     while ( 0  <= c && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   long long fast_pow(long long a, int b) {     if (b == 0) return 1;     if (b & 1)       return fast_pow(a * a % 998244353, b / 2) * a % 998244353;     else       return fast_pow(a * a % 998244353, b / 2);   }   long long A(int x, int y) { return fac[x] * invfac[x - y] % 998244353; }   long long C(int x, int y) {     return fac[x] * invfac[x - y] % 998244353 * invfac[y] % 998244353;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();     for (int i = 1; i <= n; ++i) b[i] = read();     for (int i = 1; i <= n; ++i) nxt[i] = pv[i] = -1;     for (int i = 1; i <= n; ++i) {       nxt[a[i]] = b[i];       pv[b[i]] = a[i];     }     for (int i = 1; i <= n; ++i) {       lst[i] = i;       minn[i] = i;       while (nxt[lst[i]] != i && nxt[lst[i]] != 0 && nxt[lst[i]] != -1) {         lst[i] = nxt[lst[i]];         minn[i] = min(minn[i], lst[i]);       }       lst[i] = nxt[lst[i]];     }     for (int i = 1; i <= n; ++i) {       if (a[i] == 0 && b[i] > 0 && lst[b[i]] == -1) s1++;       if (a[i] == 0 && b[i] > 0 && lst[b[i]] == 0) s2++;       if (a[i] == 0 && b[i] == 0) s2++;       if (a[i] > 0 && lst[a[i]] == a[i] && minn[a[i]] == a[i]) ans++;       if (a[i] > 0 && lst[a[i]] == 0 && pv[a[i]] == -1) s0++;     }     fac[0] = 1;     for (int i = 1; i <= 2000; ++i) fac[i] = fac[i - 1] * i % 998244353;     invfac[2000] = fast_pow(fac[2000], 998244353 - 2);     for (int i = 1999; i >= 0; --i)       invfac[i] = invfac[i + 1] * (i + 1) % 998244353;     S[0][0] = 1;     for (int i = 1; i <= 2000; ++i)       for (int j = 1; j <= i; ++j)         S[i][j] =             (S[i - 1][j] * (i - 1) % 998244353 + S[i - 1][j - 1]) % 998244353;     for (int i = 0; i <= s0; ++i)       for (int j = i; j <= s0; ++j)         F[i] = (F[i] + C(s0, j) * S[j][i] % 998244353 * A(s0 - j + s2, s0 - j) %                            998244353) %                998244353;     for (int i = 0; i <= s0; ++i)       for (int j = i; j <= s0; ++j) {         if ((j - i) % 2 == 0)           f[i] = (f[i] + F[j] * C(j, i) % 998244353) % 998244353;         else           f[i] = (f[i] - F[j] * C(j, i) % 998244353) % 998244353;       }     for (int i = 0; i <= s1; ++i)       for (int j = i; j <= s1; ++j)         G[i] = (G[i] + C(s1, j) * S[j][i] % 998244353 * A(s1 - j + s2, s1 - j) %                            998244353) %                998244353;     for (int i = 0; i <= s1; ++i)       for (int j = i; j <= s1; ++j) {         if ((j - i) % 2 == 0)           g[i] = (g[i] + G[j] * C(j, i) % 998244353) % 998244353;         else           g[i] = (g[i] - G[j] * C(j, i) % 998244353) % 998244353;       }     for (int i = 0; i <= s2; ++i) h[i] = S[s2][i] * fac[s2] % 998244353;     for (int i = 0; i <= s0; ++i)       for (int j = 0; j <= s1; ++j)         k[i + j] = (k[i + j] + f[i] * g[j] % 998244353) % 998244353;     for (int i = 0; i <= s0 + s1; ++i)       for (int j = 0; j <= s2; ++j)         K[i + j] = (K[i + j] + k[i] * h[j] % 998244353) % 998244353;     puts(  );     for (int i = n; i >= 1; --i) {       if (i < ans)         printf( %lld  , 0);       else         printf( %lld  , (K[i - ans] + 998244353) % 998244353);     }     puts(  );     return 0;   }   