jiahuimbzuai/CoQuIR huggingface dataset:
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let S = readLines()
    let T = readLines()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿入力
    var ans = 1000
    
    print(S.count, T.count)
    
    let length = S.count == T.count ? 1: S.count - T.count
    for i in 0..<length {
        var cnt = 0
        for j in 0..<T.count {
            if S[i + j] != T[j] {
                cnt += 1
            }
        }
        ans = min(ans, cnt)
    }
    print(ans)
}
main()
//  [swift]
func main(text1: String = readLine()!, text2: String = readLine()!) {
    let text2Count = text2.count
    var searchText1 = text1
    searchText1.removeLast(text2Count)
    var result = text2Count
    for text1Index in searchText1.indices {
        var difference = 0
        for (character1, character2) in zip(text1[text1Index...], text2) where character1 != character2 {
            difference += 1
        }
        if result > difference {
            result = difference
        }
    }
    print(result)
}

main()
//  [swift]
import Foundation

let s = readLine() ?? ""
let t = readLine() ?? ""

let minCost = (0...max(0, s.count - t.count))
    .map(s.dropFirst)
    .map { zip($0, t).filter { $0 != $1 }.count }
    .min() ?? 0

print(minCost)
//  [typescript]
import * as fs from "fs";

const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");

let s: string;
let t: string;

s = input[0];
t = input[1];

var ans = 100000;
for (let i = 0; i <= s.length - t.length; i++) {
    var count = 0;
    for (let j = i; j < i + t.length; j++) {
        if (s[j] != t[j - i]) count++;
    }
    if (count < ans) ans = count;
}
console.log(ans);
//  [typescript]
var main = (input: string) => {
    let a: string[] = input.split("\n");
    let template: string = a[0];
    let target: string = a[1];

    let minCount = target.length;
    for (let i: number = 0; i <= template.length - target.length; i++) {
        let hollowed = template.substring(i, i + target.length);
        let count = 0;
        for (let j: number = 0; j < target.length; j++) {
            if (hollowed.charAt(j) !== target.charAt(j)) {
                count++;
            }
        }
        if (count < minCount) {
            minCount = count;
        }
    }
    console.log(minCount);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [typescript]
import * as fs from 'fs';

const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const s = input[0] as string;
const t = input[1] as string;
var l = t.length;
for (var i = 0; i <= s.length - t.length; i++) {
    var l0 = 0;
    for (var j = 0; j < t.length; j++) {
        if (s[i + j] != t[j]) {
            l0++;
            if (l < l0) break;
        }
    }
    if (l0 < l) l = l0;
    if (l == 0) break;
}
console.log(l);
//  [typescript]
var main = (input: string) => {
    let a: string[] = input.split("\n");
    let template: string = a[0];
    let target: string = a[1];

    let minCount = target.length;
    for (let i: number = 0; i < template.length - target.length; i++) {
        let hollowed = template.substring(i, i + target.length);
        let count = 0;
        for (let j: number = 0; j < target.length; j++) {
            if (hollowed.charAt(j) !== target.charAt(j)) {
                count++;
            }
        }
        if (count < minCount) {
            minCount = count;
        }
    }
    console.log(minCount);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, Q = map(int, readline().split())
    S = readline().strip()
    (*LR,) = map(int, read().split())

    vec = [0] * (N + 1)
    for i in range(N - 1):
        vec[i + 1] = vec[i]
        if S[i] == 'A' and S[i + 1] == 'C':
            vec[i + 1] += 1

    ans = [0] * Q
    for i, (l, r) in enumerate(zip(*[iter(LR)] * 2)):
        l -= 1
        r -= 1
        ans[i] = vec[r] - vec[l]

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()
//  [python]
def main():
    from itertools import accumulate

    n, q, s, *lr = open(0).read().split()
    n = int(n)
    *u, = map(int, lr)
    c = [1 if s[i] == 'C' and s[i - 1] == 'A' else 0 for i in range(n)]
    a = tuple(accumulate(c))
    ans = ''
    for i,j in zip(*[iter(u)]*2):
        ans += str(a[j-1]-a[i-1]) + '\n'
    print(ans)

if __name__ == '__main__':
    main()
//  [python]
def main():
    from itertools import accumulate
    import sys
    n, q, s, *lr = sys.stdin.read().split()
    *query, = map(int, lr)
    c = [1 if s[i] == 'C' and s[i - 1] == 'A' else 0 for i in range(int(n))]
    a = tuple(accumulate(c))
    ans = ''
    for i,j in zip(*[iter(query)]*2):
        ans += str(a[j-1]-a[i-1]) + '\n'
    print(ans)

if __name__ == '__main__':
    main()
//  [python]
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        a.append(a[l]+1)
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])
//  [python]
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        for j in range(1,3):
            a.append(a[l]+1)
        l+=1
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])
//  [python]
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        for j in range(1,2):
            a.append(a[l]+1)
        l+=1
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])
print(a)
//  [java]
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			ArrayList<Integer> list = new ArrayList<Integer>(); 
			
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					list.add(i-1);
				}
			}
			
			Collections.sort(list);
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				int ret = 0;
				if((l[i]+1)==r[i]) {
					System.out.println(ret);
					continue;
				}
				
				for(int j=0;j<list.size();j++) {
					
					if(list.get(j)>=r[i]) {
						break;
					}
					
					if(l[i]<=list.get(j)&&list.get(j)<r[i]) {
						ret++;
					}
				}
				
				System.out.println(ret);
			}
			
			
	    }
		
	}
//  [java]
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			ArrayList<Integer> list = new ArrayList<Integer>(); 
			
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					list.add(i-1);
				}
			}
			
			Collections.sort(list);
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				int ret = 0;
				for(int j=0;j<list.size();j++) {
					
					if(list.get(j)>=r[i]) {
						break;
					}
					
					if(l[i]<=list.get(j)&&list.get(j)<r[i]) {
						ret++;
					}
				}
				
				System.out.println(ret);
			}
			
			
	    }
		
	}
//  [java]
import java.util.ArrayList;
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int q = sc.nextInt();
			char[] S = sc.next().toCharArray();
			char[] s = new char[n+1];
			int[] l = new int[q];
			int[] r = new int[q];
			ArrayList<Integer> list = new ArrayList<Integer>(); 
			
			
			for(int i=1;i<=n;i++) {
				s[i] = S[i-1];
				if(i>1&&s[i]=='C'&&s[i-1]=='A') {
					list.add(i-1);
				}
			}
			
			for(int i=0;i<q;i++) {
				l[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			for(int i=0;i<q;i++) {
				int ret = 0;
				for(int j=0;j<list.size();j++) {
					if(l[i]<=list.get(j)&&list.get(j)<r[i]) {
						ret++;
					}
				}
				
				System.out.println(ret);
			}
			
			
	    }
		
	}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), Q = getint();

	int AC[100000];
	AC[0] = 0;
	rep(i, N - 1) {
		AC[i + 1] = AC[i];
		if (*ci++ == 'A' && *ci == 'C') AC[i + 1]++;
	}
	ci += 2;
	rep(i, Q) {
		int l = getint(), r = getint();
		putint(AC[r - 1] - AC[l - 1]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint(), Q = getint();
	
	int AC[100000];
	AC[0] = 0;
	rep(i, N - 1) {
		AC[i + 1] = AC[i];
		if (*ci++ == 'A' && *ci == 'C') AC[i + 1]++;
	}
	ci += 2;
	rep(i, Q) {
		int l = getint(), r = getint();
		putint(AC[r - 1] - AC[l - 1]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
  if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
  return *ci++;
}

inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
  else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
  return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;

inline void putint(int X) {
  if (X == 0) {
    *di++ = '0';
    *di++ = '\n';
    return;
  }
  int keta = 0;
  char C[10];
  while (X) {
    *(C + keta) = '0' + X % 10;
    X /= 10;
    keta++;
  }
  for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
  *di++ = '\n';
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n = getint(), q = getint();
  vector<int> arr(n);
  arr[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    arr[i + 1] = arr[i];
    if (*ci++ == 'A' && *ci =='C') ++arr[i + 1];
  }
  ci += 2;
  for (int i = 0; i < q; ++i) {
    int left = getint(), right = getint();
    putint(arr[right - 1] - arr[left - 1]);
  }
  fwrite_unlocked(dn, di - dn, 1, stdout);
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int N, cnt;

int main(){
  cin >> S;
  int len = 0;
  string t = "ACGT";
rep(i,t.size()){
  printl(t.at(i));
}
  rep(i,S.size()){
    if(S.at(i)== t.at(0) ||S.at(i)== t.at(1) ||S.at(i)== t.at(2) ||S.at(i)== t.at(3)){
      len++;
      cnt = max(len,cnt);
    }else{
      len=0;
    }
  }
  print(cnt);
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int N, cnt;

int main(){
  cin >> S;
  int len = 0;
  string t = "ACGT";
  rep(i,S.size()){
    if(S.at(i)== t.at(0) ||S.at(i)== t.at(1) ||S.at(i)== t.at(2) ||S.at(i)== t.at(3)){
      len++;
            cnt = max(len,cnt);
    }else{
      len=0;
    }
  }
  print(cnt);
}
//  [cpp]
#include <iostream>
#include <string>
using namespace std;

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  
  for(int i = 0;i < Q;i++){
    int l, r;
    cin >> l >> r;
    
    int cnt = 0;
    for(int j = l;j < r;j++) if(S.at(j-1) == 'A' && S.at(j) == 'C') cnt++;
    cout << cnt << endl;
  }
  
  return 0;
}
//  [c]
// AtCoder ABC122: C - GeT AC
// 2019.9.9 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

int  N;
int  a[100005];
char S[100005];

int main()
{
	int i, Q;
		
	N = in(), Q = in(), ins(S+1);
	for (i = 2; i <= N; i++) {
		if (S[i-1] == 'A' && S[i] == 'C') a[i] = a[i-1]+1;
		else a[i] = a[i-1];
	}
	
	while (Q--) {
		int l = in(), r = in();
		if (l == 1) out(a[r]);
		else if (a[l] != a[l-1]) out(a[r]-a[l-1]-1);
		else out(a[r]-a[l-1]);
	}
	return 0;
}
//  [c]
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
int n, q, i;
int l, r;
char s[100001], c;
int a[100001];
int main(void){
 n=nextInt();
 q=nextInt();
 s[0]=getchar();
 for(i=1; i<n; i++){
  s[i]=getchar();
  if(s[i-1]=='A' && s[i]=='C'){a[i]=1;}
  a[i] += a[i-1];
 }
 for(i=0; i<q; i++){
  l=nextInt()-1;
  r=nextInt()-1;
  printInt(a[r]-a[l]); println();
 }
}
//  [c]
// Using fgets(3) and strtol(3) to obtain integers. 
// It may be faster than scanf(3) version sometimes. 
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

int64_t solve(char *begin, char *end);

int main(int argc, char const* argv[])
{
  char *next;
  int64_t N, Q;
  char buf[32];
  fgets(buf, sizeof(buf), stdin);
  N = strtol(buf, &next, 10);
  Q = strtol(next + 1, NULL, 10);
  // fprintf(stderr, "N = %ld, Q = %ld\n", N, Q);
  
  char *S = malloc((size_t)N + 2);
  fgets(S, N + 2, stdin);
  S[N + 1] = '\0';
  S[N] = '\0';
  // getchar();

  int64_t R[N];
  memset(R, 0, 8 * N);
  for (int i = 0; i < N - 1; i++) {
    R[i + 1] = R[i] + (((S[i] == 'A') && (S[i + 1] == 'C')) ? 1 : 0);
  }

  int64_t l, r, res;

  for (int i = 0; i < Q; i++) {
    memset(buf, 0, sizeof(buf));
    fgets(buf, sizeof(buf), stdin);
    l = strtol(buf, &next, 10);
    r = strtol(next + 1, NULL, 10);
    res = R[r - 1] - R[l - 1];
    printf("%lu\n", res);
  }

  /*
  // Bad code! TLE
  for (int i = 0; i < Q; i++) {
    memset(buf, 0, sizeof(buf));
    fgets(buf, sizeof(buf), stdin);
    l = strtol(buf, &next, 10);
    r = strtol(next + 1, NULL, 10);
    res = solve(S + l - 1, S + r - 1);
    printf("%lu\n", res);

  }
  */
  free(S);
  return 0;
}

int64_t solve(char *begin, char *end) {
  int64_t res = 0;
  for (; begin < end; begin++) {
    if ((begin[0] == 'A') && (begin[1] == 'C')) {
      res++;
      begin++;
    }
  }
  return res;
}
//  [c]
#pragma warning(disable:4996)
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 100000

int main() {

	char sInput[100]="";
	char sTargetString[MAX_STRING+1]="";
	char* psInput=NULL;
	int anStart[MAX_STRING];
	int anEnd[MAX_STRING];
	int anScore[MAX_STRING];
	int anAcFoundIndex[MAX_STRING];
	int i=0;
	int j=0;
	int nStrLength=0;
	int nParaNumber=0;
	int nNowStart=0;
	int nNowEnd=0;
	int nFoundCount=0;
	
/*	for(i=0;i<MAX_STRING;i++){
		anStart[i]=0;
		anEnd[i]=0;
		anScore[i]=0;
		anAcFoundIndex[i]=0;
	}*/

	// read line 1
	gets(sInput);
	psInput=strtok(sInput," ");
	nStrLength=atoi(psInput);
	psInput=strtok(NULL," ");	
	nParaNumber=atoi(psInput);
	
	// read line 2
	gets(sTargetString);
	
	// read line 3 and lator
	for(i=0;i<nParaNumber;i++){
		gets(sInput);
		psInput=strtok(sInput," ");
		anStart[i]=atoi(psInput);
		psInput=strtok(NULL," ");	
		anEnd[i]=atoi(psInput);
	}
	
	// check"AC"
	for(i=1;i<nStrLength;i++){
		if(sTargetString[i-1]=='A' && sTargetString[i]=='C'){
			anAcFoundIndex[nFoundCount]=i-1;
			nFoundCount++;
		}
	}

	for(i=0;i<nFoundCount;i++){
		for(j=0;j<nParaNumber;j++){
			if((anStart[j]-1)<=anAcFoundIndex[i] && (anAcFoundIndex[i]+1)<=(anEnd[j]-1)){
				anScore[j]=anScore[j]+1;
			}
		}
	}

	
	
	for(i=0;i<nParaNumber;i++){
		printf("%d\n",anScore[i]);
	}

    return 0;
}
//  [c]
#pragma warning(disable:4996)
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 100000

int main() {

	char sInput[MAX_STRING+1]="";
	char sTargetString[MAX_STRING+1]="";
	char* psInput=NULL;
	int anStart[MAX_STRING];
	int anEnd[MAX_STRING];
	int anScore[MAX_STRING];
	int anAcFoundIndex[MAX_STRING];
	int i=0;
	int j=0;
	long long nK=0;
	int nStrLength=0;
	int nParaNumber=0;
	int nNowStart=0;
	int nNowEnd=0;
	int nFoundCount=0;
	
	for(i=0;i<MAX_STRING;i++){
		anStart[i]=0;
		anEnd[i]=0;
		anScore[i]=0;
		anAcFoundIndex[i]=0;
	}

	// read line 1
	gets(sInput);
	psInput=strtok(sInput," ");
	nStrLength=atoi(psInput);
	psInput=strtok(NULL," ");	
	nParaNumber=atoi(psInput);
	
	// read line 2
	gets(sTargetString);
	
	// read line 3 and lator
	for(i=0;i<nParaNumber;i++){
		gets(sInput);
		psInput=strtok(sInput," ");
		anStart[i]=atoi(psInput);
		psInput=strtok(NULL," ");	
		anEnd[i]=atoi(psInput);
	}
	
	// check"AC"
	for(i=1;i<nStrLength;i++){
		if(sTargetString[i-1]=='A' && sTargetString[i]=='C'){
			anAcFoundIndex[nFoundCount]=i-1;
			nFoundCount++;
		}
	}

	for(i=0;i<nFoundCount;i++){
		for(j=0;j<nParaNumber;j++){
			if((anStart[j]-1)<=anAcFoundIndex[i] && (anAcFoundIndex[i]+1)<=(anEnd[j]-1)){
				anScore[j]=anScore[j]+1;
			}
		}
	}

	
	
	for(i=0;i<nParaNumber;i++){
		printf("%d\n",anScore[i]);
	}

    return 0;
}
//  [c]
#pragma warning(disable:4996)
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_STRING 100000

int main() {

	char sInput[MAX_STRING+1]="";
	char sTargetString[MAX_STRING+1]="";
	char* psInput=NULL;
	int anStart[MAX_STRING];
	int anEnd[MAX_STRING];
	int anScore[MAX_STRING];
	int i=0;
	int j=0;
	long long nK=0;
	int nStrLength=0;
	int nParaNumber=0;
	int nNowStart=0;
	int nNowEnd=0;
	
	for(i=0;i<MAX_STRING;i++){
		anStart[i]=0;
		anEnd[i]=0;
		anScore[i]=0;
	}

	// read line 1
	gets(sInput);
	psInput=strtok(sInput," ");
	nStrLength=atoi(psInput);
	psInput=strtok(NULL," ");	
	nParaNumber=atoi(psInput);
	
	// read line 2
	gets(sTargetString);
	
	// read line 3 and lator
	for(i=0;i<nParaNumber;i++){
		gets(sInput);
		psInput=strtok(sInput," ");
		anStart[i]=atoi(psInput);
		psInput=strtok(NULL," ");	
		anEnd[i]=atoi(psInput);
	}
	
	// check"AC"
	for(i=1;i<nStrLength;i++){
		if(sTargetString[i-1]=='A' && sTargetString[i]=='C'){
			nNowStart=i-1;
			nNowEnd=i;
			
			for(j=0;j<nParaNumber;j++){
				if((anStart[j]-1)<=nNowStart && nNowEnd<=(anEnd[j]-1)){
					anScore[j]=anScore[j]+1;
				}
			}
		}
	}

	for(i=0;i<nParaNumber;i++){
		printf("%d\n",anScore[i]);
	}

    return 0;
}
//  [javascript]
'use strict'
function Main(input){
  input=input.trim().split(/\s+/);
  var N=input.shift()-0;
  var Q=input.shift()-0;
  var S='';
  var b=/A|T|G|C/;
  while(b.test(input[0]))
    S=S+input.shift();
  S=S.split('');
//  console.log(S);
  var T=[0,0];
  for(let i=1;i<N;i++)
    T[i+1]=T[i]+(S[i-1]==='A'&&S[i]==='C'?1:0);
//  console.log(T);
  var ans=[];
  for(let q=0;q<Q;q++){
    let l=input[2*q]-0,r=input[2*q+1]-0;
    ans[q]=T[r]-T[l];
  }
  console.log(ans.join('\n'));
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));
//  [javascript]
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.split("\n");
var nq=arr[0].split(" ").map(Number);
var str = arr[1];
var a=[0,0];
var cnt=0;
for(var i=1;i<str.length;i++){
   if(str[i]=="C" && str[i-1]=="A")cnt++;
   a.push(cnt);
}
var ans=[];
for(var i=2;i<nq[1]+2;i++){
   var lr=arr[i].split(" ");
   ans.push(a[lr[1]-0]-a[lr[0]-0]);
}
console.log(ans.join("\n"));
//  [javascript]
input = require('fs').readFileSync('/dev/stdin', 'utf8');
arr=input.split("\n");
nq=arr[0].split(" ").map(Number);
str = arr[1];
a=[0,0];
cnt=0;
for(i=1;i<str.length;i++){
   if(str[i]=="C" && str[i-1]=="A")cnt++;
   a.push(cnt);
}
ans=[];
for(i=2;i<nq[1]+2;i++){
   lr=arr[i].split(" ");
   ans.push(a[lr[1]-0]-a[lr[0]-0]);
}
console.log(ans.join("\n"));
//  [javascript]
function Main(input){
    const arr = input.split('\n');
    const NQ = arr[0].split(' ').map(Number);
    const S = arr[1];
    const lq = [];
    let answer = [];
    for(let i=2; i<arr.length; i++){
        lq.push(arr[i]);
    }
    for(let i=0; i<lq.length; i++){
        let num = 0;
        const left = lq[i].split(' ')[0];
        const right = lq[i].split(' ')[1];
        const string = S.slice(left-1, right);
        let j=0;
        while(true){
            const index = string.indexOf('AC', j);
            if(index>=0){ 
                num++;
                j = index+1;
            } else {
                break;
            }
        }
        answer.push(num)
    }
    console.log(answer.join('\n'));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
function Main(input){
    const arr = input.split('\n');
    const NQ = arr[0].split(' ').map(Number);
    const S = arr[1];
    const lq = [];
    let answer = 0;
    for(let i=2; i<arr.length; i++){
        lq.push(arr[i]);
    }
    for(let i=0; i<lq.length; i++){
        answer = 0;
        const left = lq[i].split(' ')[0];
        const right = lq[i].split(' ')[1];
        const string = S.slice(left-1, right);
        let j=0;
        while(true){
            const index = string.indexOf('AC', j);
            if(index>=0){ 
                answer++;
                j = index+1;
            } else {
                break;
            }
        }
        console.log(answer);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [N, Q] = nextIntArray()
    const s = next()
    let l = []
    let r = []
    let agg = new Array(N).fill(0)
    let sum = 0
    agg[0] = 0
    for(let i = 1; i<N; i++){
        if(s[i] == "C" && s[i-1] == "A"){
            sum++
        }
        agg[i] = sum
    }
    console.log(agg)
    while(hasNext()){
        let tmp = nextIntArray()
        l.push(tmp[0]-1)
        r.push(tmp[1]-1)
    }
    let ans = []
    for(let i = 0; i<l.length;i++){
        ans.push(agg[r[i]]-agg[l[i]])
    }
    console.log(ans.join("\n"))
}
Main()
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, 0)
	scanner.Buffer(buf, 10000000000)
	scanner.Split(bufio.ScanWords)
}

func ScanText() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	_, _ = fmt.Fprintf(os.Stderr, "Text not found")
	return ""
}

func ScanInt() (ret int) {
	var err error
	if scanner.Scan() {
		txt := scanner.Text()
		if ret, err = strconv.Atoi(txt); err != nil {
			_, _ = fmt.Fprintf(os.Stderr, err.Error())
		}
	}
	return
}

func main() {
	n, q := ScanInt(), ScanInt()
	s := ScanText()

	cur := 0
	t := make([]int, n)
	for i := 1; i < n; i++ {
		if s[i-1] == 'A' && s[i] == 'C' {
			cur++
		}
		t[i] = cur
	}

	var w = bufio.NewWriter(os.Stdout)
	for i := 0; i < q; i++ {
		l, r := ScanInt()-1, ScanInt()-1
		_, _ = fmt.Fprintln(w, t[r]-t[l])
	}
	_ = w.Flush()
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, q int
	var t string
	s := wordScanner(100001)
	scanInts(s, &n, &q)
	scanStrings(s, &t)

	l, r := make([]int, q), make([]int, q)
	for i := 0; i < q; i++ {
		scanInts(s, &l[i], &r[i])
	}

	count := make([]int, n)
	for i := 1; i < n; i++ {
		count[i] = count[i-1]
		if t[i-1:i+1] == "AC" {
			count[i]++
		}
	}

	ans := make([]string, q)
	for i := 0; i < q; i++ {
		ans[i] = strconv.Itoa(count[r[i]-1] - count[l[i]-1])
	}

	fmt.Println(strings.Join(ans, "\n"))
}

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}

func scanStrings(s *bufio.Scanner, vals ...*string) {
	for i := range vals {
		s.Scan()
		*vals[i] = s.Text()
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type pair struct {
	l, r int
}

func m() {
	n, q := getInt(), getInt()
	s := []rune(getString())
	ps := make([]pair, q)
	for i := range ps {
		ps[i].l = getInt() - 1
		ps[i].r = getInt() - 1
	}

	cSum := make([]int, n+1)
	for i := 0; i < n; i++ {
		if (i < n-1) && (s[i] == 'A') && (s[i+1] == 'C') {
			cSum[i+1] = cSum[i] + 1
		} else {
			cSum[i+1] = cSum[i]
		}
	}

	for _, p := range ps {
		res := cSum[p.r] - cSum[p.l]
		puts(res)
	}
}

// -----------------------------------------

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
)

func main() {
	buf := 200001
	scanner.Buffer(make([]byte, buf), buf)
	scanner.Split(bufio.ScanWords)
	m()
	writer.Flush()
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}

func puts(a ...interface{}) {
	if _, err := fmt.Fprintln(writer, a...); err != nil {
		panic(err)
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - GeT AC
	var N, Q int
	fmt.Scan(&N, &Q)
	var S string
	fmt.Scan(&S)

	var count int
	var flag int
	sum := make([]int, N)
	for i := 0; i < N; i++ {
		if S[i] == 'A' {
			flag = 1
		} else if S[i] == 'C' && flag == 1 {
			count++
		} else {
			flag = 0
		}

		sum[i] = count
	}

	var l, r int

	sc.Split(bufio.ScanWords)
	for i := 0; i < Q; i++ {
		l = nextInt()
		r = nextInt()
		fmt.Println(sum[r-1] - sum[l-1])

	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var N, Q int
var S string
var MEMO [][]int

func main() {
	var w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	N = nextInt()
	Q = nextInt()
	S = nextString()
	MEMO = make([][]int, N)
	for i := 0; i < N; i++ {
		MEMO[i] = make([]int, N+1)
	}
	solve(0, 2)
	for i := 0; i < Q; i++ {
		l := nextInt() - 1
		r := nextInt()
		fmt.Fprintln(w, MEMO[l][r])
	}
}

func solve(i, j int) {
	if j > N {
		return
	}
	MEMO[i][j] = MEMO[i][j-1] + count(S[j-2:j])
	solve(i, j+1)
	solve(i+1, j+1)
}

func count(s string) int {
	if s == "AC" {
		return 1
	} else {
		return 0
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var N, Q int
var S string
var MEMO [][]int

func main() {
	N = nextInt()
	Q = nextInt()
	S = nextString()
	MEMO = make([][]int, N)
	for i := 0; i < N; i++ {
		MEMO[i] = make([]int, N+1)
	}
	solve(0, 2)
	for i := 0; i < Q; i++ {
		l := nextInt() - 1
		r := nextInt()
		fmt.Println(MEMO[l][r])
	}
}

func solve(i, j int) {
	if j > N {
		return
	}
	MEMO[i][j] = MEMO[i][j-1] + count(S[j-2:j])
	solve(i, j+1)
	solve(i+1, j+1)
}

func count(s string) int {
	if s == "AC" {
		return 1
	} else {
		return 0
	}
}
//  [ruby]
N, Q = gets.split.map &:to_i
S = gets.chomp

b = Array.new(N+1, 0) # 累積和テーブル
N.times do |i|
  if i + 1 < N && S[i] == 'A' && S[i+1] == 'C'
    b[i+1] = b[i] + 1
  else
    b[i+1] = b[i]
  end
end

Q.times do
  l, r = gets.split.map { |i| i.to_i - 1 }
  puts b[r] - b[l]
end
//  [ruby]
#https://atcoder.jp/contests/abc122/submissions/14662859
#上のURLを参照にした。何回やっても時間制限かかるから。

#はじめから最後まで回す
#l,rまですべてのACの数をpushする。最後にlまでの合計からrまでの合計を引く。
n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split("")
s = s.unshift(" ")
arr = Array.new(n+1,0)
i = 2
ans = 0
while true
    if s[i] == "C" && s[i-1] == "A"
        arr[i] = ans + 1
    else
        arr[i] = ans
    end
    break if i == n
    ans = arr[i]
    i += 1
end
q.times do
    l, r = gets.chomp.split(" ").map(&:to_i)
    all = arr[r] - arr[l]
    puts all
end
//  [ruby]
N, Q = gets.chomp.split().map(&:to_i)
S = gets.chomp.split('')
AC_ind = Array.new(N+1, 0)

N.times do |i|
  if S[i] == 'A' && S[i+1] == 'C'
    AC_ind[i+1] = AC_ind[i] + 1
  else
    AC_ind[i+1] = AC_ind[i]
  end
end

Q.times do
  s, f = gets.chomp.split().map(&:to_i)
  puts AC_ind[f-1] - AC_ind[s-1]
end
//  [ruby]
n, q = gets.strip.split.map(&:to_i)
s = gets.strip
qs = q.times.map { gets.strip.split.map(&:to_i) }

len = s.chars.count()
counts = [0]
current = 0

(1..(len - 1)).each do |i|
  if s[i - 1] == 'A' && s[i] == 'C'
    current += 1
  end

  counts << current
end

qs.each do |l, r|
  puts(counts[r - 1] - counts[l - 1])
  puts(s[(l - 1)..(r - 1)])
end
//  [ruby]
N, Q = gets.split.map(&:to_i)
S = gets.chomp
lr = Q.times.map{|_| gets.split.map(&:to_i)}

cur = Hash.new()
m = Hash.new()
c = ""
S.chars.each.with_index(1) do |s, idx|
  p = 0
  if c == "A" && s == "C"
    p = 1
  end
  c = s
  idx.times do |i|
    i += 1
    if idx == i
      cur[i] = 0
      m[i] = {}
    else
      cur[i] += p
    end
    m[i][idx] = cur[i]
  end
end

lr.each do |l, r|
  p m[l][r]
end
//  [rust]
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    q: usize,
    s: chars,
    query: [(usize, usize); q],
  }
  let mut dp = vec![0; n + 1];
  let mut prev_a = false;
  for (i, &c) in s.iter().enumerate() {
    dp[i + 1] = dp[i];
    if c == 'C' && prev_a {
      dp[i + 1] += 1;
    }
    prev_a = c == 'A';
  }
  for &(l, r) in &query {
    puts!("{}\n", dp[r] - dp[l]);
  }
}
//  [rust]
// Snippet
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => ({
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    })
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    )
}

// End Snippet

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input!{
        source = src,
        n: usize, q: usize,
        s: chars,
        lr: [(usize, usize); q]
    }
    let mut ans = String::new();
    let mut counts = vec![0; n+1];

    for i in 1..n {
        counts[i] = counts[i-1] + if s[i-1] == 'A' && s[i] == 'C' {
            1
        } else {
            0
        }
    }

    for i in 0..q {
        let (l, r) = lr[i];
        let count = counts[r-1] - counts[l-1];
        ans.push_str(&count.to_string());
        ans.push_str("\n");
    }
    ans.to_string()
}

test! {
r"8 3
ACACTACG
3 7
2 3
1 8
"
=>
r"2
0
3
"
}
//  [rust]
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        q: usize,
        s: Chars,
        lr: [(usize, usize); q]
    };

    let s: Vec<char> = s;
    let mut v = vec![0; n - 1];
    let lr: Vec<(usize, usize)> = lr;

    let mut flag = false;
    let mut index = 0;

    for (i, si) in s.iter().enumerate() {
        if *si == 'A' {
            flag = true;
            index = i;
        } else if flag && *si == 'C' {
            flag = false;
            v[index] = 1;
        } else {
            flag = false;
        }
    }

    for lri in lr.iter() {
        let start = lri.0 - 1;
        let end = lri.1 - 1;

        let mut sum = 0;
        for i in start..end {
            sum += v[i];
        }

        println!("{}", sum);
    }
}
//  [rust]
use proconio::input;
use proconio::marker::Usize1;

fn main() {
  input! {
    n: usize,
    q: usize,
    s: String,
    lrs: [(Usize1,Usize1);q],
  }
  let s = s.chars().collect::<Vec<char>>();
  let mut dp = vec![0;n];
  
  let mut last = s[0];
  for i in 1..n {
    let c = s[i];
    if last == 'A' && c == 'C' {
      last = 'C';
      dp[i] = dp[i-1] + 1;
    } else if last != 'A' && c == 'A' {
      last = 'A';
      dp[i] = dp[i-1];
    } else {
      dp[i] = dp[i-1];
    }
  }

  for (l, r) in lrs {
    println!("{}", dp[r] - dp[l]);  
  }
}
//  [rust]
fn solve() {
    let n: usize = read();
    let q: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let mut acc = vec![0, 0];
    let mut ac_count = 0;
    for i in 1..s.len() {
        if s[i - 1] == 'A' && s[i] == 'C' {
            ac_count += 1;
        }
        acc.push(ac_count);
    }
    println!("{:?}", acc);
    for i in 0..q {
        let (l, r): (usize, usize) = (read::<usize>(), read::<usize>());
        println!("{}", acc[r] - acc[l]);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========
//  [swift]
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let nq = readInts()
    let (n, q) = (nq[0], nq[1])
    let s = readLine()!.map { String($0) }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var count = 0
    var aryACIndex = [Int](repeating: 0, count: n)
    for i in 1..<n {
        if s[i - 1] == "A" && s[i] == "C" {
            count += 1
        }
        aryACIndex[i] = count
    }
    
    for _ in 1...q {
        let lr = readInts()
        let (l, r) = (lr[0] - 1, lr[1] - 1)
        
        print(aryACIndex[r] - aryACIndex[l])
    }
}
main()
//  [swift]
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (N, Q) = (input[0], input[1])
let S = (readLine()!+"_").characters.map{String($0)}
var t = Array(count: N+1, repeatedValue: 0)
for i in 0..<N {
  	t[i+1] = t[i] + (S[i] + S[i+1] == "AC" ? 1 : 0)
}
for _ in 0..<Q {
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    let (l, r) = (input[0], input[1])
    print(t[r-1] - t[l-1])
}
//  [swift]
import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

let input = readLine()!.split(by: " ").map{Int($0)!}
let N = input[0]
let Q = input[1]
let S = (readLine()!+"_").characters.map{$0}

var sum = [0]
for i in 1...N {
    sum.append(sum[i-1])
    if (S[i-1] == "A") && (S[i] == "C") {
        sum[i] += 1
    }
}

for _ in 0..<Q {
    let input = readLine()!.split(by: " ").map{Int($0)!}
    print(sum[input[1]-1] - sum[input[0]-1])
}