Problem:
Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

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

Notes

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

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

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            //対になる塩基を出す
            if (s == "A")
                Console.WriteLine("T");
            else if (s == "T")
                Console.WriteLine("A");
            else if (s == "G")
                Console.WriteLine("C");
            else
                Console.WriteLine("G");

        }
    }

    class ProgramB
    {
        public void main()
        {

            //入力
            string s = Console.ReadLine();

            int ans = 0;

            //先頭から調べていく
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != 'A' && s[i] != 'T' && s[i] != 'C' && s[i] != 'G')
                    continue;

                int count = 0;

                for (int j = i; j < s.Length; j++)
                {
                    if (s[j] == 'A' || s[j] == 'T' || s[j] == 'C' || s[j] == 'G')
                    {
                        count++;
                    }
                    else
                        break;
                }

                ans = Math.Max(ans, count);
            }

            //答え出力
            Console.WriteLine(ans);
            

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] ss = Console.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int q = int.Parse(ss[1]);
            string s = Console.ReadLine();

            //i文字目までにACが何個あるか記録する
            int[] AC = new int[n + 1];
            int count = 0;

            for(int i = 2; i <= n;i++)
            {
                if (s[i - 1] == 'C' && s[i - 2] == 'A')
                    count++;
                AC[i] = count;
            }

            for(int i = 0;i < q;i++)
            {
                string[] temp = Console.ReadLine().Split(' ');

                Console.WriteLine(AC[int.Parse(temp[1])] - AC[int.Parse(temp[0])]);
            }

        }


    }


    class ProgramD
    {
        public void main()
        {

            //入力
            string[] ss = Console.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int k = int.Parse(ss[1]);
            string s = Console.ReadLine();

            List<long> array = new List<long>();
            int flag = 0;

            //頭を記録しておく
            if (s[0] - '0' == 1)
                flag = 1;

            int count = 1;
            //1が続く数を連続で入れる
            for (int i = 1; i < n; i++)
            {
                if (s[i] != s[i - 1])
                {
                    array.Add(count);
                    count = 1;
                }
                else
                    count++;

                if (i == n - 1)
                    array.Add(count);
            }
            int num = array.Count;
            //ダミーを入れておく
            array.Add(0);
            array.Add(0);

            //入れた数が2*k + flag より少なければ全交換可能
            if (num <= 2 * k + flag)
            {
                Console.WriteLine(s.Length);
                return;
            }

            //kが0回のときは最大の続いているものを出す
            if(k == 0)
            {
                long ans2 = 0;
                if (flag == 0)
                {
                    for (int i = 0; i < num; i = i + 2)
                        ans2 = Math.Max(ans2, array[i + 1]);
                }
                else
                {
                    for (int i = 0; i < num; i = i + 2)
                        ans2 = Math.Max(ans2, array[i]);

                }
                Console.WriteLine(ans2);
                return;

            }

            long sum = 0;
            //それ以外は交換した個数を頭から比較（尺取り法）
            for (int i = 0; i < 2 * k + flag; i++)
                sum += array[i];
            //答を入れておく
            long ans = sum;

            for (int i = 2 * k + flag; i < num; i = i + 2)
            {
                //最初のときは頭によって場合分け
                if (i == 2 * k + flag)
                {
                    if (flag == 0)
                    {
                        sum -= array[0];
                        sum += array[2 * k];
                        sum += array[2 * k + 1];
                    }
                    else
                    {
                        sum -= array[0];
                        sum -= array[1];
                        sum += array[2 * k + 1];
                        sum += array[2 * k + 2];
                    }


                }
                else
                {
                    //それ以外は二個引いて二個足す
                    sum -= array[i - 2 * k];
                    sum -= array[i - 2 * k - 1];
                    sum += array[i];
                    sum += array[i + 1];
                }
                //最大を更新
                ans = Math.Max(ans, sum);
            }

            //答を出す
            Console.WriteLine(ans);

        }

    }

    


}