Your favourite emperor Caesar is back! He gives you the following problem. He defines a 1-step transformation in the following way: a 1-step transformation transforms an a
into a b
, a b
into a c
, ..., a y
into a z
, and finally a z
into an a
. Furthermore, for any non-negative integer , he defines a k-step transformation as a 1-step transformation applied times. For example, a 3-step transformation transforms an a
into a d
. Note that a 0-step transformation does nothing i.e. it transforms an a
into an a
, a b
into a b
, and so on.
Caesar provides you with two strings and , each of length . These are both indexed from 0. Furthermore, he provides you with intervals where . For each interval , he wants you to find the number of pairs such that and there exists a such that, for all , we have that is the -step transformation of .
For example, if and then the valid pairs are and . For we take , and for we take .
Interaction Protocol
The contestant must implement two functions:
void init (int n, int q, char A[], char B []);
long long query (int l, int r);
The function init
will be called exactly once, at the beginning of the interaction. The function will be supplied with the values and and with the two strings, and . Then, the committee will call the function query
times. It will be supplied with the values and , representing a query. The contestant must return one integer, the answer for the interval , according to the statement.
Attention! The contestant must not implement the main function, and must #include
the caesar.h
header! Contestants are allowed to use global variables and other functions.
Restrictions
- .
- .
- and contain lowercase English letters only.
Subtask 1 (5 points)
Subtask 2 (9 points)
- and contain only
a
andn
Subtask 3 (10 points)
Subtask 4 (15 points)
Subtask 5 (30 points)
Subtask 6 (31 points)
- No further restrictions
Examples
Committee
init(3, 1, "aac", "bbc")
query(0, 2)
Contestant
4
Committee
init(5, 3, "abcde", "bcdyz")
query(1, 3)
query(0, 2)
query(4, 4)
Contestant
4
6
1
Committee
init(20, 20, "aggccdaloaxgnakfivqd"
"ckjdfgdnsczhpdmilxrh")
query(2, 9)
query(8, 10)
query(2, 11)
query(3, 4)
query(9, 15)
query(6, 12)
query(8, 10)
query(8, 10)
query(2, 5)
query(5, 14)
query(8, 13)
query(5, 11)
query(0, 1)
query(6, 14)
query(0, 5)
query(2, 2)
query(0, 3)
query(9, 14)
query(3, 12)
query(8, 11)
Contestant
11
4
14
2
8
8
4
4
5
12
7
9
2
10
7
1
4
7
14
5
Explanations
First example: For the interval the valid pairs are and . For the first three pairs we take which transforms the letters a
into letters b
. For the last one we take which leaves the letter c
as it is.
Second example: For the interval we have the valid pairs and . For and we choose which transforms the letter b
into c
and the letter c
into d
respectively. For we choose , because it transforms the letter d
into y
. Therefore, the answer is . For the interval every possible pair is valid. For all of them we choose , which makes the letter a
into b
, the letter b
into c
and the letter c
into d
respectively. Therefore, the answer is . For the interval the only pair that satisfies the statement is , for which we choose , which transforms the letter e
into z
. Therefore, the answer is .