Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i ++)
using namespace std;
const int N = 4e4 + 10, mod = 998244353;
int n, f[N], fac[N], inv[N], s[N], L;
char a[N], b[N];
int C(int n, int m) {
	return fac[n] * 1LL * inv[n - m] % mod * inv[m] % mod;
}
int pw(int a, int b) { 
	int w = 1; for(;b;b >>= 1, a = 1LL * a * a % mod) if (b & 1) w = 1LL * w * a % mod;
	return w; 
}


int rev[N], w[2][N];
void nttinit(int &n){
	int m = 1, l = 0;
	while (m < n) m <<= 1, l++;
	n = m;
	rep(i,1,n - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (l - 1));
	w[1][n] = pw(3, (mod - 1) >> l);
	dep(i,l - 1,1) w[1][1 << i] = (1LL * w[1][1 << (i + 1)] * w[1][1 << (i + 1)]) % mod;
	w[0][n] = pw(w[1][n], mod - 2);
	dep(i,l - 1,1) w[0][1 << i] = (1LL * w[0][1 << (i + 1)] * w[0][1 << (i + 1)]) % mod;
}
void fft(int *a, int l, int f){
	if (f == -1) f = 0;
	Rep(i,l) if (rev[i] < i) swap(a[i], a[rev[i]]);
	for(int n = 2; n <= l; n <<= 1){
		int mid = n >> 1, wn = w[f][n];
		for(int i = 0; i < l; i += n){
			int w = 1;
			Rep(j,mid){
				int t1 = a[i + j], t2 = 1LL * a[i + j + mid] * w % mod;
				a[i + j] = (t1 + t2) % mod;
				a[i + j + mid] = (t1 - t2) % mod;
				w = 1LL * w * wn % mod;
			}
		}
	}
	int invl = pw(l, mod - 2);
	if (!f) Rep(i,l) a[i] = 1LL * a[i] * invl % mod;
}

int t; 
void conv(int a[], int b[], int c[]) {
	static int ta[N], tb[N];
	Rep(i,t) ta[i] = tb[i] = 0;
	Rep(i,L) ta[i] = a[i], tb[i] = b[i];
	fft(ta, t, 1), fft(tb, t, 1);
	Rep(i,t) c[i] = 1LL * ta[i] * tb[i] % mod;
	fft(c, t, -1);
	rep(i,L,t) c[i] = 0;
}

void pw(int a[], int b, int w[]) {
	memset(w, 0, (N - 1) * sizeof(w[0])); w[0] = 1;
	for( ;b; b >>= 1, conv(a, a, a)) if (b & 1) conv(w, a, w);
}

int sc[N], g[N];
void init(int c) {
	L = n + 1; t = L * 2; nttinit(t);
	rep(i,1,n - c + 1) sc[i] = inv[i];
	pw(sc, c, g);
	rep(i,c,n) g[i] = 1LL * g[i] * fac[i] % mod;
}


int count_chain(int c, int m) {
	return g[m + c];
}

int main() {
	scanf("%s",a + 1); scanf("%s",b + 1); n = strlen(a + 1);
	fac[0] = 1; rep(i,1,n) fac[i] = 1LL * i * fac[i - 1] % mod;
	inv[n] = pw(fac[n], mod - 2); dep(i,n - 1,0) inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
	int cnt = 0; rep(i,1,n) if (a[i] != b[i]) cnt++; cnt /= 2;
	int m = 0; rep(i,1,n) if (a[i] == '1') m++; swap(n, m);
	int ans = 0;
	init(cnt);
	rep(i,0,n - cnt) {
		int rest = (n - cnt) - i;
		int cof = 1LL * C(n - cnt, i) * fac[i] % mod * fac[cnt] % mod * fac[n - cnt - i] % mod * count_chain(cnt, n - cnt - i) % mod;
		ans = (ans + 1LL * cof * fac[i] % mod * C(n, i)) % mod;
	}
	if (ans < 0) ans += mod;
	printf("%d\n",ans);
	return 0; 
}#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i ++)
using namespace std;
const int N = 4e4 + 10, mod = 998244353;
int n, f[N], fac[N], inv[N], s[N], L;
char a[N], b[N];
int C(int n, int m) {
	return fac[n] * 1LL * inv[n - m] % mod * inv[m] % mod;
}
int pw(int a, int b) { 
	int w = 1; for(;b;b >>= 1, a = 1LL * a * a % mod) if (b & 1) w = 1LL * w * a % mod;
	return w; 
}


int rev[N], w[2][N];
void nttinit(int &n){
	int m = 1, l = 0;
	while (m < n) m <<= 1, l++;
	n = m;
	rep(i,1,n - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (l - 1));
	w[1][n] = pw(3, (mod - 1) >> l);
	dep(i,l - 1,1) w[1][1 << i] = (1LL * w[1][1 << (i + 1)] * w[1][1 << (i + 1)]) % mod;
	w[0][n] = pw(w[1][n], mod - 2);
	dep(i,l - 1,1) w[0][1 << i] = (1LL * w[0][1 << (i + 1)] * w[0][1 << (i + 1)]) % mod;
}
void fft(int *a, int l, int f){
	if (f == -1) f = 0;
	Rep(i,l) if (rev[i] < i) swap(a[i], a[rev[i]]);
	for(int n = 2; n <= l; n <<= 1){
		int mid = n >> 1, wn = w[f][n];
		for(int i = 0; i < l; i += n){
			int w = 1;
			Rep(j,mid){
				int t1 = a[i + j], t2 = 1LL * a[i + j + mid] * w % mod;
				a[i + j] = (t1 + t2) % mod;
				a[i + j + mid] = (t1 - t2) % mod;
				w = 1LL * w * wn % mod;
			}
		}
	}
	int invl = pw(l, mod - 2);
	if (!f) Rep(i,l) a[i] = 1LL * a[i] * invl % mod;
}

int t; 
void conv(int a[], int b[], int c[]) {
	static int ta[N], tb[N];
	Rep(i,t) ta[i] = tb[i] = 0;
	Rep(i,L) ta[i] = a[i], tb[i] = b[i];
	fft(ta, t, 1), fft(tb, t, 1);
	Rep(i,t) c[i] = 1LL * ta[i] * tb[i] % mod;
	fft(c, t, -1);
	rep(i,L,t) c[i] = 0;
}

void pw(int a[], int b, int w[]) {
	memset(w, 0, (N - 1) * sizeof(w[0])); w[0] = 1;
	for( ;b; b >>= 1, conv(a, a, a)) if (b & 1) conv(w, a, w);
}

int sc[N], g[N];
void init(int c) {
	L = n + 1; t = L * 2; nttinit(t);
	rep(i,1,n - c + 1) sc[i] = inv[i];
	pw(sc, c, g);
	rep(i,c,n) g[i] = 1LL * g[i] * fac[i] % mod;
}


int count_chain(int c, int m) {
	return g[m + c];
}

int main() {
	scanf("%s",a + 1); scanf("%s",b + 1); n = strlen(a + 1);
	fac[0] = 1; rep(i,1,n) fac[i] = 1LL * i * fac[i - 1] % mod;
	inv[n] = pw(fac[n], mod - 2); dep(i,n - 1,0) inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
	int cnt = 0; rep(i,1,n) if (a[i] != b[i]) cnt++; cnt /= 2;
	int m = 0; rep(i,1,n) if (a[i] == '1') m++; swap(n, m);
	int ans = 0;
	init(cnt);
	rep(i,0,n - cnt) {
		int rest = (n - cnt) - i;
		int cof = 1LL * C(n - cnt, i) * fac[i] % mod * fac[cnt] % mod * fac[n - cnt - i] % mod * count_chain(cnt, n - cnt - i) % mod;
		ans = (ans + 1LL * cof * fac[i] % mod * C(n, i)) % mod;
	}
	if (ans < 0) ans += mod;
	printf("%d\n",ans);
	return 0; 
}

Compiler output:
a.cc:95:2: error: stray '#' in program
   95 | }#include <iostream>
      |  ^
a.cc: In function 'void pw(int*, int, int*)':
a.cc:62:9: error: 'memset' was not declared in this scope
   62 |         memset(w, 0, (N - 1) * sizeof(w[0])); w[0] = 1;
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 | #define rep(i,a,b) for(int i = a; i <= b; i++)
a.cc: In function 'int main()':
a.cc:80:51: error: 'strlen' was not declared in this scope
   80 |         scanf("%s",a + 1); scanf("%s",b + 1); n = strlen(a + 1);
      |                                                   ^~~~~~
a.cc:80:51: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: At global scope:
a.cc:95:3: error: 'include' does not name a type
   95 | }#include <iostream>
      |   ^~~~~~~
a.cc:102:11: error: redefinition of 'const int N'
  102 | const int N = 4e4 + 10, mod = 998244353;
      |           ^
a.cc:8:11: note: 'const int N' previously defined here
    8 | const int N = 4e4 + 10, mod = 998244353;
      |           ^
a.cc:102:25: error: redefinition of 'const int mod'
  102 | const int N = 4e4 + 10, mod = 998244353;
      |                         ^~~
a.cc:8:25: note: 'const int mod' previously defined here
    8 | const int N = 4e4 + 10, mod = 998244353;
      |                         ^~~
a.cc:103:5: error: redefinition of 'int n'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |     ^
a.cc:9:5: note: 'int n' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |     ^
a.cc:103:8: error: redefinition of 'int f [40010]'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |        ^
a.cc:9:8: note: 'int f [40010]' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |        ^
a.cc:103:14: error: redefinition of 'int fac [40010]'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |              ^~~
a.cc:9:14: note: 'int fac [40010]' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |              ^~~
a.cc:103:22: error: redefinition of 'int inv [40010]'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |                      ^~~
a.cc:9:22: note: 'int inv [40010]' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |                      ^~~
a.cc:103:30: error: redefinition of 'int s [40010]'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |                              ^
a.cc:9:30: note: 'int s [40010]' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |                              ^
a.cc:103:36: error: redefinition of 'int L'
  103 | int n, f[N], fac[N], inv[N], s[N], L;
      |                                    ^
a.cc:9:36: note: 'int L' previously declared here
    9 | int n, f[N], fac[N], inv[N], s[N], L;
      |                                    ^
a.cc:104:6: error: redefinition of 'char a [40010]'
  104 | char a[N], b[N];
      |      ^
a.cc:10:6: note: 'char a [40010]' previously declared here
   10 | char a[N], b[N];
      |      ^
a.cc:104:12: error: redefinition of 'char b [40010]'
  104 | char a[N], b[N];
      |            ^
a.cc:10:12: note: 'char b [40010]' previously declared here
   10 | char a[N], b[N];
      |            ^
a.cc:105:5: error: redefinition of 'int C(int, int)'
  105 | int C(int n, int m) {
      |     ^
a.cc:11:5: note: 'int C(int, int)' previously defined here
   11 | int C(int n, int m) {
      |     ^
a.cc:108:5: error: redefinition of 'int pw(int, int)'
  108 | int pw(int a, int b) {
      |     ^~
a.cc:14:5: note: 'int pw(int, int)' previously defined here
   14 | int pw(int a, int b) {
      |     ^~
a.cc:114:5: error: redefinition of 'int rev [40010]'
  114 | int rev[N], w[2][N];
      |     ^~~
a.cc:20:5: note: 'int rev [40010]' previously declared here
   20 | int rev[N], w[2][N];
      |     ^~~
a.cc:114:13: error: redefinition of 'int w [2][40010]'
  114 | int rev[N], w[2][N];
      |             ^
a.cc:20:13: note: 'int w [2][40010]' previously declared here
   20 | int rev[N], w[2][N];
      |             ^
a.cc:115:6: error: redefinition of 'void nttinit(int&)'
  115 | void nttinit(int &n){
      |      ^~~~~~~
a.cc:21:6: note: 'void nttinit(int&)' previously defined here
   21 | void nttinit(int &n){
      |      ^~~~~~~
a.cc:125:6: error: redefinition of 'void fft(int*, int, int)'
  125 | void fft(int *a, int l, int f){
      |      ^~~
a.cc:31:6: note: 'void fft(int*, int, int)' previously defined here
   31 | void fft(int *a, int l, int f){
      |      ^~~
a.cc:144:5: error: redefinition of 'int t'
  144 | int t;
      |     ^
a.cc:50:5: note: 'int t' previously declared here
   50 | int t;
      |     ^
a.cc:145:6: error: redefinition of 'void conv(int*, int*, int*)'
  145 | void conv(int a[], int b[], int c[]) {
      |      ^~~~
a.cc:51:6: note: 'void conv(int*, int*, int*)' previously defined here
   51 | void conv(int a[], int b[], int c[]) {
      |      ^~~~
a.cc:155:6: error: redefinition of 'void pw(int*, int, int*)'
  155 | void pw(int a[], int b, int w[]) {
      |      ^~
a.cc:61:6: note: 'void pw(int*, int, int*)' previously defined here
   61 | void pw(int a[], int b, int w[]) {
      |      ^~
a.cc: In function 'void pw(int*, int, int*)':
a.cc:156:9: error: 'memset' was not declared in this scope
  156 |         memset(w, 0, (N - 1) * sizeof(w[0])); w[0] = 1;
      |         ^~~~~~
a.cc:156:9: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: At global scope:
a.cc:160:5: error: redefinition of 'int sc [40010]'
  160 | int sc[N], g[N];
      |     ^~
a.cc:66:5: note: 'int sc [40010]' previously declared here
   66 | int sc[N], g[N];
      |     ^~
a.cc:160:12: error: redefinition of 'int g [40010]'
  160 | int sc[N], g[N];
      |            ^
a.cc:66:12: note: 'int g [40010]' previously declared here
   66 | int sc[N], g[N];
      |            ^
a.cc:161:6: error: redefinition of 'void init(int)'
  161 | void init(int c) {
      |      ^~~~
a.cc:67:6: note: 'void init(int)' previously defined here
   67 | void init(int c) {
      |      ^~~~
a.cc:169:5: error: redefinition of 'int count_chain(int, int)'
  169 | int count_chain(int c, int m) {
      |     ^~~~~~~~~~~
a.cc:75:5: note: 'int count_chain(int, int)' previously defined here
   75 | int count_chain(int c, int m) {
      |     ^~~~~~~~~~~
a.cc:173:5: error: redefinition of 'int main()'
  173 | int main() {
      |     ^~~~
a.cc:79:5: note: 'int main()' previously defined here
   79 | int main() {
      |     ^~~~
a.cc: In function 'int main()':
a.cc:174:51: error: 'strlen' was not declared in this scope
  174 |         scanf("%s",a + 1); scanf("%s",b + 1); n = strlen(a + 1);
      |                                                   ^~~~~~
a.cc:174:51: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'