atcoder#ABC122C. [ABC122C] GeT AC

[ABC122C] GeT AC

Score : 300300 points

Problem Statement

You are given a string SS of length NN consisting of A, C, G and T. Answer the following QQ queries:

  • Query ii (1iQ1 \leq i \leq Q): You will be given integers lil_i and rir_i (1li<riN1 \leq l_i < r_i \leq N). Consider the substring of SS starting at index lil_i and ending at index rir_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string TT is a string obtained by removing zero or more characters from the beginning and the end of TT.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and `` (the empty string), but not AC.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1Q1051 \leq Q \leq 10^5
  • SS is a string of length NN.
  • Each character in SS is A, C, G or T.
  • 1li<riN1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

NN QQ

SS

l1l_1 r1r_1

::

lQl_Q rQr_Q

Output

Print QQ lines. The ii-th line should contain the answer to the ii-th query.

8 3
ACACTACG
3 7
2 3
1 8
2
0
3
  • Query 11: the substring of SS starting at index 33 and ending at index 77 is ACTAC. In this string, AC occurs twice as a substring.
  • Query 22: the substring of SS starting at index 22 and ending at index 33 is CA. In this string, AC occurs zero times as a substring.
  • Query 33: the substring of SS starting at index 11 and ending at index 88 is ACACTACG. In this string, AC occurs three times as a substring.