Language: C++

#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<array>
using namespace std;
#define MOD 1000000007
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

//nCrとか
class Combination {
public:
	Array fact;
	Array inv;
	ll mod;
	ll mod_inv(ll x) {
		ll n = mod - 2LL;
		ll res = 1LL;
		while (n > 0) {
			if (n & 1) res = res * x % mod;
			x = x * x % mod;
			n >>= 1;
		}
		return res;
	}
	ll nCr(ll n, ll r) {
		return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
	}
	ll nPr(ll n, ll r) {
		return (fact[n] * inv[n - r]) % mod;
	}
	ll nHr(ll n, ll r) {
		return nCr(r + n - 1, r);
	}
	Combination(ll n, ll _mod) {
		mod = _mod;
		fact.resize(n + 1);
		fact[0] = 1;
		REP(i, n) {
			fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
		}
		inv.resize(n + 1);
		inv[n] = mod_inv(fact[n]);
		for (int i = n; i > 0; i--) {
			inv[i - 1] = inv[i] * i % mod;
		}
	}
};

int popcount3(int x) {
	x = (x & 0x55555555) + (x >> 1 & 0x55555555);
	x = (x & 0x33333333) + (x >> 2 & 0x33333333);
	x = (x & 0x0F0F0F0F) + (x >> 4 & 0x0F0F0F0F);
	x = (x & 0x00FF00FF) + (x >> 8 & 0x00FF00FF);
	x = (x & 0x0000FFFF) + (x >> 16 & 0x0000FFFF);

	return x;
}

ll garner(Array& xs, Array& mods) {
	int M = xs.size();
	Array coeffs(M, 1), constants(M, 0);
	for (int i = 0; i < M - 1; ++i) {
		// coffs[i] * v + constants[i] == mr[i].val (mod mr[i].first) を解く
		ll v = (xs[i] - constants[i] + mods[i]) % mods[i];
		v = (v * mod_pow(coeffs[i], mods[i] - 2, mods[i])) % mods[i];
		for (int j = i + 1; j < M; j++) {
			constants[j] = (constants[j] + coeffs[j] * v) % mods[j];
			coeffs[j] = (coeffs[j] * mods[i]) % mods[j];
		}
	}
	return constants.back();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);


	ll mod = 998244353;
	ll n, k, s, t;
	cin >> n >> k >> s >> t;
	Combination comb(n, MOD);
	Combination comb2(n, mod);
	Array a(n);
	REP(i, n)cin >> a[i];
	Array c;
	REP(i, 18) {
		if ((s & (1LL << i)) && !(t & (1LL << i))) {
			cout << 0 << "\n";
			return 0;
		}
		if ((t & (1LL << i)) && !(s & (1LL << i)))c.push_back(i);
	}
	
	Array b;
	REP(i, n) {
		auto check = [&]() {
			REP(j, 18) {
				if ((s & (1LL << j)) && (t & (1LL << j))) {
					if (!(a[i] & (1LL << j)))return false;
				}
				else if (!(s & (1LL << j)) && !(t & (1LL << j))) {
					if (a[i] & (1LL << j))return false;
				}
			}
			return true;
		};
		if (check() == true)b.push_back(a[i]);
	}
	Array ans(3, 0);
	REP(i, 1LL << c.size()) {
		ll mask = 0;
		REP(j, c.size())if (i & (1LL << j))mask ^= (1LL << c[j]);
		map<ll, ll> cnt;
		REP(j, b.size()) cnt[b[j] & mask]++;
		ll co = popcount3(i) % 2;
		for (auto [key, v] : cnt) {
			rep(j, 1, min(k, v) + 1)(ans[0] += MOD + comb.nCr(v, j) * (co == 0 ? 1 : -1)) %= MOD;
			rep(j, 1, min(k, v) + 1)(ans[1]+= mod + comb2.nCr(v, j) * (co == 0 ? 1 : -1)) %= mod;
		}
	}
	Array m = { MOD,mod,9007199254740997LL };
	cout << garner( ans,m) << "\n";


	return 0;
}


Compiler output:
a.cc: In function 'long long int garner(Array&, Array&)':
a.cc:88:26: error: 'mod_pow' was not declared in this scope
   88 |                 v = (v * mod_pow(coeffs[i], mods[i] - 2, mods[i])) % mods[i];
      |                          ^~~~~~~