uwu

Time limit: 0.8s Memory limit: 128MB Input: Output:

Although Stefan hasn't started school for some time, a familiar sound has captured his thoughts: uwuwuwuwuwu.

Therefore, he thought to use this opportunity to turn this sound into a problem for RoAlgo Back to School!

Task

Given a string ss indexed from 11 containing only the letters u and w, as well as qq queries of the form Li,RiL_i, R_i, determine for each query how many uwu subsequences exist in the interval [Li,Ri][L_i, R_i].

A subsequence defined by chosen positions ii, jj, and kk (with Lii<j<kRiL_i \leq i < j < k \leq R_i) is called uwu if si=s_i = u, sj=s_j = w, sk=s_k = u.

Input data

The first line contains two integers, nn and qq, representing the length of the string and the number of queries. The next line contains the string ss, of length nn. The next qq lines contain the queries, in the order they need to be answered.

Note! It is recommended to add the following line of code at the beginning of the main() function to speed up reading the input:

cin.tie(0);ios::sync_with_stdio(0);

Output data

Print qq lines, where line ii contains the answer to the ii-th query.

Constraints and clarifications

  • 1n,q500 0001 \leq n, q \leq 500 \ 000
# Points Constraints
0 0 Example
1 21 N,Q2 000N, Q \leq 2 \ 000
2 17 There are at most 2020 characters equal to w
3 23 N,Q100 000N, Q \leq 100 \ 000
4 39 No additional constraints

Example

stdin

14 8
uuwuwuuuwwuuuu
1 14
5 10
8 13
3 9
4 12
2 11
4 6
1 9

stdout

85
0
6
3
21
23
1
17

Explanation

For the fourth query, the triplets that form uwu subsequences are (4,5,6)(4, 5, 6), (4,5,7)(4, 5, 7), (4,5,8)(4, 5, 8).

Log in or sign up to be able to send submissions!