CodeEff/ECCO huggingface dataset:
# Original solution
from collections import defaultdict
import heapq

vertices,edges = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
    source,target,w = list(map(int,input().split(" ")))
    link[source] = link.get(source,set()) | {target}
    link[target] = link.get(target,set()) | {source}
    weight[source].update({target:w})
    weight[target].update({source:w})
queue = []
heapq.heapify(queue)
heapq.heappush(queue,[0,0])
went = [0] * vertices
now_weight = 0
way[0] = 0

while queue:
    here_weight,here = heapq.heappop(queue)
    #print(went)
    if went[here]:
        continue
    went[here] = 1
    now_weight += here_weight
    min_weight,next_t = float("inf"),-1
    for c in link[here]:
        if not went[c] and way[c] > weight[here][c]:
            heapq.heappush(queue,[weight[here][c],c])
            way[c] = weight[here][c]
    #print(queue)
print(now_weight)

# Optimized solution
from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict)
for i in range(edges):
    v1, v2, w = (int(n) for n in input().split(" "))
    conn[v1] |= {v2}
    conn[v2] |= {v1}
    weight[v1][v2] = w
    weight[v2][v1] = w

queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0,0])
went = set()
went_vertices = 0
answer_weight = 0
while went_vertices < vertices:
    here_weight, here_v = heapq.heappop(queue)
    if here_v in went:
        continue
    went |= {here_v}
    for c in conn[here_v]:
        if c not in went:
            heapq.heappush(queue,[weight[here_v][c], c])
    answer_weight += here_weight
    went_vertices += 1
print(answer_weight)
# Original solution
import sys


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.p = [i for i in range(n + 5)]
        self.rank = [0 for i in range(n + 5)]

    def find_set(self, x):
        if self.p[x] != x:
            self.p[x] = self.find_set(self.p[x])
        return self.p[x]

    def unite(self, x, y):
        px, py = self.find_set(x), self.find_set(y)
        if px == py:
            return
        if self.rank[px] > self.rank[py]:
            self.p[py] = px
        else:
            self.p[px] = py
            if self.rank[px] == self.rank[py]:
                self.rank[py] += 1


def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = list(map(int, input().split()))
    E = []
    uf = UnionFind(nvertices)
    for i in range(nedges):
        s, t, w = list(map(int, input().split()))
        E.append((w, s, t))
    E.sort()

    ans = 0
    for w, s, t in E:
        if uf.find_set(s) != uf.find_set(t):
            ans += w
            uf.unite(s, t)

    print(ans)


main()

# Optimized solution
import sys


class UnionFind:

    def __init__(self, nvertices):
        self.rank = [1] * (nvertices + 5)
        self.p = [i for i in range(nvertices + 5)]

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])
        return self.p[u]

    def unite(self, u, v):
        x = self.find_set(u)
        y = self.find_set(v)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def is_connected(self, u, v):
        return self.find_set(u) == self.find_set(v)


def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = list(map(int, input().split()))
    edges = []
    for i in range(nedges):
        u, v, w = list(map(int, input().split()))
        edges.append((w, u, v))

    edges.sort(key=lambda e: e[0])
    ans = 0
    uf = UnionFind(nvertices)
    for w, u, v in edges:
        if not uf.is_connected(u, v):
            uf.unite(u, v)
            ans += w

    print(ans)


main()
# Original solution
X, A = list(map(int, input().split()))
if X < A:
  print('0')
else:
  print('10')

# Optimized solution
X, A = list(map(int, input().split()))
if X < A:
  print((0))
else:
  print((10))
# Original solution
x, a = list(map(int, input().split()))
if x < a:
	print((0))
if x >= a:
	print((10))

# Optimized solution
def main():
	x, a = list(map(int, input().split()))
	if x < a:
		print((0))
	else:
		print((10))




if __name__ == '__main__':
	main()
# Original solution
x,a=list(map(int,input().split()));print(((x>=a)*10))

# Optimized solution
x,a=input().split();print(((x>=a)*10))
# Original solution
X, A = list(map(int, input().split()))

if X < A:
    print((0))
else:
    print((10))


# Optimized solution
X, A = list(map(int, input().split()))

if X < A:
    print('0')
else:
    print('10')
# Original solution
import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(eval(input()))

def finput():
    return float(eval(input()))

def tinput():
    return input().split()

def rinput():
    return list(map(int, tinput()))

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    a, x = rinput()
    if x > a:
        print((0))
    else:
        print((10))
    
    
    
main()

# Optimized solution
from sys import stdin
n=input().split(' ')
if(int(n[0])>=int(n[1])):
    print('10')
else:
    print('0')
# Original solution
x,a = list(map(int, input().split()))

if x <a:
  print('0')
elif x >= a:
  print('10')

# Optimized solution
x,a = list(map(int, input().split()))
print(('0' if x<a else '10'))
# Original solution
X,A = list(map(int, input().split()))
if X<A:
  print((0))
if X>=A:
  print((10))


# Optimized solution
x,a = list(map(int, input().split()))
if x<a:
  print((0)) 
else:
  print((10))
# Original solution
X,A=list(map(int,input().split()))
print((10*(X>=A)))

# Optimized solution
X,A=list(map(int,input().split()))
print(("0" if X<A else "10"))
# Original solution
X, A = list(map(int,input().split()))
print((0 if X < A else 10))

# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, A = lr()
print((0 if X < A else 10))
#
# Original solution
x, a = list(map(int, input().split()))
print((0 if x < a else 10))

# Optimized solution
x, a = list(map(int, input().split()))
print((10 if x >= a else 0))
# Original solution
x,a = list(map(int,input().split()))

if x <a:
  print((0))
else:
  print((10))

# Optimized solution
x,a = list(map(int,input().split()))

if x < a:
  print('0')
else:
  print('10')
# Original solution
x, a = map(int, input().split())
print('0') if x < a else print('10')
cons = 10 ** 7
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
primes(cons)


# Optimized solution
x, a = list(map(int, input().split()))
if x < a:
  print((0))
else:
  print((10))
# Original solution
n=input().split()

if n[0]<n[1]:
    print('0')
else:
    print('10')

# Optimized solution
x,a=list(map(int,input().split()))

if x < a:
    print((0))
else:
    print((10))
# Original solution
import sys

sys.setrecursionlimit(100000)

def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0

    for i in adj[v]:
        if est[i] == float('inf'):
            child += 1
            parents[i] = v
            dfs(i, tm + 1)
            est[v] = min(est[v], est[i])

            if parents[v] is None and child > 1: aps[v] = True
            if parents[v] is not None and est[i] >= dts[v]: aps[v] = True

        elif parents[v] != i:
            est[v] = min(est[v], dts[i])


nv, ne = list(map(int, input().split(' ')))
adj = [[] for _ in range(nv)]
est = [float('inf')] * nv
parents = [None] * nv
aps = [False] * nv
dts = [0] * nv

for _ in range(ne):
    s, t = list(map(int, input().split(' ')))
    adj[s].append(t)
    adj[t].append(s)

dfs(0, 0)

for i in range(nv):
    if aps[i]:
        print(i)

# Optimized solution
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0
    for i in adj[v]:
        if isinf(est[i]):
            child += 1
            parents[i] = v
            dfs(i, tm + 1)
            est[v] = min(est[v], est[i])
            if parents[v] is None and child > 1: aps[v] = True
            if parents[v] is not None and est[i] >= dts[v]: aps[v] = True
        elif parents[v] != i:
            est[v] = min(est[v], dts[i])
n, m = list(map(int, stdin.readline().split()))
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * n
for _ in range(m):
    s, t = list(map(int, stdin.readline().split()))
    adj[s].append(t)
    adj[t].append(s)
dfs(0, 0)
for i in range(n):
    if aps[i]:
        print(i)
# Original solution
a = int(eval(input()))
print((48 - a))

# Optimized solution
m = int(eval(input()))
print((48-m))
# Original solution
print((48-int(eval(input()))))

# Optimized solution
m=int(eval(input()))
print((48-m))
# Original solution
m = int(eval(input()))
print((24 - m + 24))


# Optimized solution
m = int(eval(input()));print((48 - m))
# Original solution
print((24*2-int(eval(input()))))

# Optimized solution
print((48-int(eval(input()))))
# Original solution
M = int(eval(input()))
ans = 48-M

print(ans)

# Optimized solution
def solve():
    M = int(eval(input()))
    ans = 48-M
    return ans
print((solve()))
# Original solution
print(((24-int(eval(input())))+24))

# Optimized solution
print((48-int(eval(input()))))
# Original solution
print(-eval(input())+48)

# Optimized solution
print((48-int(eval(input()))))
# Original solution
print((48 - int(eval(input()))))

# Optimized solution
m = int(eval(input()))
print((24 + 24 - m))
# Original solution
a=int(eval(input()))
print((48-a))

# Optimized solution
print((48-int(eval(input()))))
# Original solution
M = int(eval(input()))
print((48-M))

# Optimized solution
print((48 - int(eval(input()))))
# Original solution
#coding: utf-8

a = int(eval(input()))

print((24 - a + 24))

# Optimized solution
#coding: utf-8

a = int(eval(input()))

print(((24 - a) + 24))
# Original solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Q = LI()
S = input()
"""
ACのインデックスをすべて記録しておき、始点、終点で区切って出す
少ない方を取ったほうがいいかな
"""
ACs = []
for sidx in range(0, len(S)-1):
    if S[sidx] == 'A':
        if S[sidx+1] == 'C':
            ACs.append(sidx)

#  print(ACs)

LR = []
for i in range(Q):
    LR.append(LI())

#  N, Q = 10**5, 10**5
#  S = 'ACTCTTCGTG'*10**4
#  LR = []
#  for i in range(Q):
#      LR.append([3,9000])

#  for l, r in LR:
#      tmp = S[l-1:r]
#      print(tmp.count('AC'))

result = []
#  print(ACs)
for l, r in LR:
    start = bisect.bisect_left(ACs, l-1)
    end = bisect.bisect_left(ACs, r-1)
    #  print('s,e', start, end)
    print(len(ACs[start:end]))


# Optimized solution
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, Q = LI()
S = input()
"""
ACのインデックスをすべて記録しておき、始点、終点で区切って出す
少ない方を取ったほうがいいかな
"""
ACs = []
for sidx in range(0, len(S)-1):
    if S[sidx] == 'A':
        if S[sidx+1] == 'C':
            ACs.append(sidx)

#  print(ACs)

LR = []
for i in range(Q):
    LR.append(LI())

#  N, Q = 10**5, 10**5
#  S = 'ACTCTTCGTG'*10**4
#  LR = []
#  for i in range(Q):
#      LR.append([3,9000])

#  for l, r in LR:
#      tmp = S[l-1:r]
#      print(tmp.count('AC'))

result = []
#  print(ACs)
for l, r in LR:
    start = bisect.bisect_left(ACs, l-1)
    end = bisect.bisect_left(ACs, r-1)
    #  print('s,e', start, end)
    print(end-start)
# Original solution
N, Q = list(map(int, input().split()))
string = input()
a = []
for i in range(Q):
    a.append(list(map(int, input().split())))
test_dict = {}
for j, temp in enumerate(a):
    #print(temp)
    str_sub = string[temp[0]-1:temp[1]]
    #print('j',j)
    if j == 0:
        test_dict[str_sub] = str_sub.count('AC')
        result = str(test_dict[str_sub])
        continue
    if test_dict.get(str_sub) and j >= 1:
        #print(test_dict.get(str_sub))
        result += '\n' + str(test_dict.get(str_sub))
        continue
    test_dict[str_sub] = str_sub.count('AC')
    result += '\n' + str(test_dict[str_sub])
    #print(test_dict[str_sub])
    #print('result', result)
print(result)


# Optimized solution
N, Q = list(map(int, input().split()))
string = input()
cnt = [0]
for i in range(N):
#    print(i)
#    print(string[i-2:i])
#    if i == 0:
#        cnt.append(0)
#        continue
    if string[i-1:i+1] == 'AC':
        cnt.append(cnt[i]+1)
        continue
    cnt.append(cnt[i])

for j in range(Q):
    #print(j)
    pare = list(map(int, input().split()))
    print((cnt[pare[1]] - cnt[pare[0]]))
# Original solution
N, Q = [int(i) for i in input().strip().split()]
S = input().strip()

pre = ''
hit = []
for i, s in enumerate(S):
  if pre=='A' and s=='C':
    hit.append(i)
  pre = s
  
for _ in range(Q):
  l, r = [int(i) for i in input().strip().split()]
  print((sum([1 for h in hit if l<=h<r])))
  


# Optimized solution
N, Q = [int(i) for i in input().strip().split()]
S = input().strip()

hit = [0]*(N+1)
for i in range(N):
  hit[i+1] = hit[i] + (1 if S[i:i+2]=='AC' else 0)
  
for _ in range(Q):
  l, r = [int(i) for i in input().strip().split()]
  print((hit[r-1]-hit[l-1]))
# Original solution
# ABC122C - GeT AC
import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n - 1)
for i in range(n - 1):
    if s[i : i + 2] == "AC":
        cnt[i] += 1
for i, j in arr:
    print((cnt[i - 1 : j - 1].count(1)))

# Optimized solution
# ABC122C - GeT AC
import sys
input = sys.stdin.readline

n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
for i, j in arr:
    print((cnt[j - 1] - cnt[i - 1]))
# Original solution
# ABC122C - GeT AC
n, q = list(map(int, input().rstrip().split()))
s = input().rstrip()
arr = [list(map(int, input().rstrip().split())) for _ in range(q)]
cnt = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]
for i, j in arr:
    print((cnt[j - 1] - cnt[i - 1]))


# Optimized solution
# ABC122C - GeT AC
import sys
input = sys.stdin.readline


def main():
    n, q = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    arr = tuple(tuple(map(int, input().split())) for _ in range(q))
    cnt = [0] * (n + 1)
    for i in range(n):
        if s[i : i + 2] == "AC":
            cnt[i + 1] = cnt[i] + 1
        else:
            cnt[i + 1] = cnt[i]
    for i, j in arr:
        print((cnt[j - 1] - cnt[i - 1]))


if __name__ == "__main__":
    main()
# Original solution
# coding: utf-8
list1 = input().split()


String = input()

lr_list = []

q = int(list1[1])

for x in range(q):
    item_list = input().split()
    lr_list.append(item_list)

str_list = []

for x in range(q):
    l = int(lr_list[x][0]) -1
    r = int(lr_list[x][1])
    l = int(l)
    r = int(r)

    str_item = String[l:r]
    str_list.append(str_item)

for string in str_list:
    
    print(string.count('AC'))


# Optimized solution
# coding: utf-8
list1 = input().split()


String = input()

lr_list = []

q = int(list1[1])

for x in range(q):
    item_list = input().split()
    lr_list.append(item_list)
    str_list = []

    l = int(lr_list[x][0]) -1
    r = int(lr_list[x][1])

    string_item = String[l:r]
    print(string_item.count('AC'))
# Original solution
N,Q = map(int,input().split())
S = input()

ansLis = [0]
line = ""
for i in range(N):
    line += S[i]
    ansLis.append(line.count("AC"))
# print(ansLis)

ans = []
for _ in range(Q):
    l,r = map(int,input().split())
    num = ansLis[r] - ansLis[l]
    # if S[l-2] == "A" and S[l-1] == "C":
    #     num = max(0, num-1)
    ans.append(num)

print(*ans,sep="\n")


# Optimized solution
N,Q = map(int,input().split())
S = input()

ansLis = [0]
tmp = 0
flgA = False
for i in range(N):
    if flgA and S[i]=="C":
        tmp += 1
    ansLis.append(tmp)
    flgA = (S[i] == "A")
# print(ansLis)

ans = []
for _ in range(Q):
    l,r = map(int,input().split())
    num = ansLis[r] - ansLis[l]
    # if S[l-2] == "A" and S[l-1] == "C":
    #     num = max(0, num-1)
    ans.append(num)

print(*ans,sep="\n")
# Original solution
import sys
from collections import deque

def resolve():
    input=sys.stdin.readline
    N,Q=list(map(int,input().rstrip().split()))
    S=list(input().rstrip())
    R=[list(map(int,input().rstrip().split())) for _ in range(Q)]
    cumsum=[0 for i in range(N)]

    _S=deque(S)
    T=""
    for i in range(N):
        #T=S[0:i+1]#i=0で一字含む, 
        T+=_S.popleft()
        cumsum[i]=T.count("AC")#cumsum[i]:i+1文字以下でACを含むか
    
    cumsum=[0]+cumsum#cumsum[i]:i文字以下でACを含むか
    for j in range(Q):
        print((cumsum[R[j][1]]-cumsum[R[j][0]]))

from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """8 3
ACACTACG
3 7
2 3
1 8"""
        output = """2
0
3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

# Optimized solution
import sys
from collections import deque

def resolve():
    input=sys.stdin.readline
    N,Q=list(map(int,input().rstrip().split()))
    S=list(input().rstrip())
    R=[list(map(int,input().rstrip().split())) for _ in range(Q)]
    cumsum=[0 for i in range(N)]

    _S=deque(S)
    prevT=_S.popleft()
    for i in range(1,N):
        #T=S[0:i+1]#i=0で一字含む, 
        """
        T+=_S.popleft()
        cumsum[i]=T.count("AC")#cumsum[i]:i+1文字以下でACを含むか
        """
        nowT=_S.popleft()
        if(prevT=="A" and nowT=="C"):
            cumsum[i]=cumsum[i-1]+1
        else:
            cumsum[i]=cumsum[i-1]
        prevT=nowT

    cumsum=[0]+cumsum#cumsum[i]:i文字以下でACを含むか
    for j in range(Q):
        print((cumsum[R[j][1]]-cumsum[R[j][0]]))

from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """8 3
ACACTACG
3 7
2 3
1 8"""
        output = """2
0
3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()
# Original solution
n,q = map(int,input().split())
s = list(input())
ans = []
for i in range(q):
    l,r = map(int,input().split())
    a = ''.join(s[l-1:r])
    ans.append(a.count('AC'))
[print(i) for i in ans]


# Optimized solution
n,q = map(int,input().split())
s = input()
dp = [0]*(n+1)
ans = []
for i in range(n):
    dp[i+1] = dp[i]+(1 if s[i:i+2]=='AC' else 0)
for i in range(q):
    l,r = map(int,input().split())
    ans.append(dp[r-1]-dp[l-1])
[print(i) for i in ans]
# Original solution
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

ans = [S[LR[i][0]-1:LR[i][1]].count('AC') for i in range(Q)]

print(*ans, sep='\n')


# Optimized solution
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i: i+2] == 'AC' else 0)
ans = [t[LR[i][1] - 1] - t[LR[i][0] - 1] for i in range(Q)]    

print(*ans, sep='\n')
# Original solution
import sys
input = sys.stdin.readline
def ii(): return int(eval(input()))
def mi(): return list(map(int, input().rstrip().split()))
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*(N+1)
for i in range(N - 1):
    if i in Alist:
        AClist[i + 2] = AClist[i+1] + 1
    else:
        AClist[i+2] = AClist[i+1]

# print(AClist)

for i in range(Q):
    l, r = mi()
    if AClist[l - 1] != AClist[l]:
        print((AClist[r] - AClist[l]))
    else:
        print((AClist[r] - AClist[l-1]))

# Optimized solution
import sys
input = sys.stdin.readline
def ii(): return int(eval(input()))
def mi(): return list(map(int, input().rstrip().split()))
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
# print(N, Q)
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
Aset = set(Alist)
AClist = [0]*(N+1)
for i in range(N-1):
    if i in Aset:
        AClist[i + 2] = AClist[i + 1] + 1
    else:
        AClist[i+2] = AClist[i+1]
        # print(AClist)

for i in range(Q):
    l, r = mi()
    if AClist[l - 1] != AClist[l]:
        print((AClist[r] - AClist[l]))
    else:
        print((AClist[r] - AClist[l-1]))
# Original solution
def solve():
    n, q = map(int, input().split())
    s = input()
    lrs = list(list(map(int, input().split())) for _ in range(q))
    ans = [s[l - 1:r].count("AC") for l, r in lrs]
    print(*ans, sep="\n")


if __name__ == "__main__":
    solve()


# Optimized solution
def solve():
    n, q = map(int, input().split())
    s = input()
    lrs = list(list(map(int, input().split())) for _ in range(q))
    # ans = [s[l - 1:r].count("AC") for l, r in lrs]
    c = [0] * n
    for i in range(1, n):
        c[i] = c[i - 1]
        if s[i - 1] == "A" and s[i] == "C":
            c[i] += 1
    ans = [c[r - 1] - c[l - 1] for l, r in lrs]
    print(*ans, sep="\n")


if __name__ == "__main__":
    solve()
# Original solution
import sys
N,Q = list(map(int,sys.stdin.readline().rstrip().split()))
S = sys.stdin.readline().rstrip()
lr = [list(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)]
for i in lr:  
  print((S[i[0]-1:i[1]].count("AC")))


# Optimized solution
import sys
N,Q = list(map(int,sys.stdin.readline().rstrip().split()))
S = sys.stdin.readline().rstrip()
D = [0]
DD = 0
for i in range(1,len(S)):
  if S[i-1] + S[i] == "AC":
    DD += 1
  D.append(DD)
for _ in range(Q):
  l,r  = list(map(int,sys.stdin.readline().rstrip().split()))
  print((D[r-1]- D[l-1]))
  del l
  del r