Problem:
Score : 1000 points

Problem Statement

There are N non-negative integers written on a blackboard. The i-th integer is A_i.

Takahashi can perform the following two kinds of operations any number of times in any order:

Select one integer written on the board (let this integer be X). Write 2X on the board, without erasing the selected integer.

Select two integers, possibly the same, written on the board (let these integers be X and Y). Write X XOR Y (XOR stands for bitwise xor) on the blackboard, without erasing the selected integers.

How many different integers not exceeding X can be written on the blackboard? We will also count the integers that are initially written on the board.
Since the answer can be extremely large, find the count modulo 998244353.

Constraints

1 \leq N \leq 6

1 \leq X < 2^{4000}

1 \leq A_i < 2^{4000}(1\leq i\leq N)

All input values are integers.

X and A_i(1\leq i\leq N) are given in binary notation, with the most significant digit in each of them being 1.

Input

Input is given from Standard Input in the following format:

N X
A_1
:
A_N

Output

Print the number of different integers not exceeding X that can be written on the blackboard.

Sample Input 1

3 111
1111
10111
10010

Sample Output 1

4

Initially, 15, 23 and 18 are written on the blackboard. Among the integers not exceeding 7, four integers, 0, 3, 5 and 6, can be written.
For example, 6 can be written as follows:

Double 15 to write 30.

Take XOR of 30 and 18 to write 12.

Double 12 to write 24.

Take XOR of 30 and 24 to write 6.

Sample Input 2

4 100100
1011
1110
110101
1010110

Sample Output 2

37

Sample Input 3

4 111001100101001
10111110
1001000110
100000101
11110000011

Sample Output 3

1843

Sample Input 4

1 111111111111111111111111111111111111111111111111111111111111111
1

Sample Output 4

466025955

Be sure to find the count modulo 998244353.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 998244353;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

const int N = 4010;
ll pow2[4020];

vi bxor(const vi& a, const vi& b) {
	vi res(N, 0);
	rep(i, 0, N) res[i] = (a[i] ^ b[i]);
	return res;
}

int fbit(const vi& a) { //fbit(0101) = 3
	rer(i, N, 0) {
		if(a[i] == 1) return i + 1;
	}
	return 0;
}

vi shift(const vi& a, int k) {
	vi res(N, 0);
	int fa = fbit(a);
	assert(fa + k <= N);
	rep(i, 0, fa) {
		res[i + k] = a[i];
	}
	return res;
}

bool is_zero(const vi& a) {
	rep(i, 0, N) {
		if(a[i]) return false;
	}
	return true;
}

vi gcd(const vi& a, const vi& b) {
	if(is_zero(b)) return a;
	vi c = a;
	while(true) {
		int fc = fbit(c), fb = fbit(b);
		if(fc < fb) break;
		int diff = fc - fb;
		c = bxor(c, shift(b, diff));
	}
	return gcd(b, c);
}

vi stobit(const string& str) {
	vector<int> res(N, 0);
	int n = sz(str);
	rep(i, 0, n) {
		res[n - i - 1] = str[i] - '0';
	}
	return res;
}

ll loop(const vi& a, const vi& b) {
	int fa = fbit(a), fb = fbit(b);
	if(fa < fb) return 0;
	vi c = bxor(a, shift(b, fa - fb));
	return (loop(c, b) + pow2[fa - fb]) % mod;
}

int M;
vi X;
vi B[10];

void solve() {
	string str;
	cin >> M >> str;
	pow2[0] = 1;
	rep(i, 1, 4010) pow2[i] = pow2[i - 1] * 2 % mod;
	X = stobit(str);
	rep(i, 0, M) {
		cin >> str;
		B[i] = stobit(str);
	}
	vi g = B[0];
	rep(i, 0, M - 1) g = gcd(g, B[i + 1]);
	int a = fbit(X), b = fbit(g);
	vi c(N, 0);
	ll res = 0;
	rep(i, 0, (a - b + 1)) {
		if(X[a - i - 1] == 1) {
			c = bxor(c, shift(g, (a - b - i)));
			ADD(res, pow2[a - b - i]);
		}
		if(X[a - i - 1] == 0 && c[a - i - 1] == 1) {
			c = bxor(c, shift(g, (a - b - i)));
		}
	}
	rer(i, N, 0) {
		if(X[i] == 0 && c[i] == 1) {
			cout << res << "\n";
			return;
		}
		else if(X[i] == 1 && c[i] == 0) {
			cout << (res + 1) % mod << "\n";
			return;
		}
	}
	cout << (res + 1) % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}