#P7279. 光棱碎片

光棱碎片

Description

The boy only has one string SS, with length nn, indexed from 1n1 \dots n;
and an array a1na_{1\dots n}.

The boy wrote down two numbers L,RL, R and tried to find those shards that have been lit by light:
For two substrings (Sl1r1,Sl2r2)(S_{l_1\dots r_1}, S_{l_2\dots r_2}) in SS that occur at different positions but are identical in content, if $L \le (a_{r_1} \oplus a_{r_2}) + (r_1 - l_1 + 1) \le R$, then there is light between these two substrings.
Here, SlrS_{l\dots r} denotes the substring formed by concatenating the characters of SS with indices in [l,r][l, r] in order, and \oplus denotes the bitwise XOR operation.

The boy wants to know how many pairs of substrings have light between them.
Substring pairs are unordered. Specifically, (Sl1r1,Sl2r2)(S_{l_1\dots r_1}, S_{l_2\dots r_2}) and (Sl2r2,Sl1r1)(S_{l_2\dots r_2}, S_{l_1\dots r_1}) are considered the same pair.
You only need to output the answer modulo 998244353998244353.

Input Format

The first line contains a positive integer nn.
The second line contains a string SS.
The third line contains nn non-negative integers a1na_{1\dots n}.
The fourth line contains two non-negative integers L,RL, R.

Output Format

One line containing a non-negative integer, which is the answer.

5
abcbc
0 1 2 3 4
2 7
2

Hint

Constraints:
For 20%20\% of the testdata, n100n \le 100;
For 50%50\% of the testdata, n103n \le 10^3;
For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 0ai,L,R1050 \le a_i, L, R \le 10^5, LRL \le R, and SS contains only lowercase letters.

"A gift from the problem setter"
Be a bit braver. Trust the constant factor of some algorithm. What you think of might be a trash standard solution.

Translated by ChatGPT 5