#P7279. Glowing Substrings

    ID: 20478 Type: Default 1000ms 256MiB

Glowing Substrings

Glowing Substrings

You are given a string \(S\) of length \(n\) (indexed from 1 to \(n\)) and an integer array \(a_{1\dots n}\). You are also given two integers \(L\) and \(R\).

A pair of substrings \(\big(S_{l_1\dots r_1}, S_{l_2\dots r_2}\big)\) (with different starting positions) is said to be glowing if the two substrings are identical (i.e. they are the same sequence of characters) and they satisfy the condition \[ L \le (a_{r_1} \oplus a_{r_2}) + \Bigl(r_1 - l_1 + 1\Bigr) \le R, \] where \(\oplus\) denotes the bitwise XOR operation and \(S_{l\dots r}\) denotes the substring of \(S\) from index \(l\) to \(r\) (inclusive). Note that each unordered pair is counted only once.

Output the number of glowing substring pairs modulo \(998244353\).

inputFormat

The input consists of four lines:

  1. The first line contains an integer \(n\) denoting the length of string \(S\).
  2. The second line contains the string \(S\) of length \(n\). It consists only of lowercase English letters.
  3. The third line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).
  4. The fourth line contains two integers \(L\) and \(R\), representing the lower and upper bounds, respectively.

outputFormat

Output a single integer, the number of glowing substring pairs modulo \(998244353\).

sample

3
aaa
1 2 3
3 5
3