Buggy python submission (verdict: Runtime Error):
n, q = list(map(int,input().split()))
s = input()
l = []
for i in range(q) :
    l.append(list(map(int,input().split())))
pla = []
for i in range(len(s)) :
    if s[i] == "A" :
        if s[i+1] == "C" :
            pla.append(i)
for i in l :
    count = 0
    st = 0
    en = 0
    for j in range(len(pla)) :
        if i[0] - 1  <= pla[j] :
            st = j
            break
    for j in range(1,len(pla) - 1) :
        if pla[-j] < i[1] - 1 :
            en = len(pla) - 1
            break
    print(en-st+1)


Fixed submission:
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])

Buggy python submission (verdict: Runtime Error):
n, q = list(map(int,input().split()))
s = input()
l = []
for i in range(q) :
    l.append(list(map(int,input().split())))
pla = []
for i in range(len(s)) :
    if s[i] == "A" :
        if s[i+1] == "C" :
            pla.append(i)
for i in l :
    count = 0
    for j in pla :
        if i[0] - 1 <= j < i[1] - 1 :
            count += 1
    print(count)


Fixed submission:
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int,input().split()))
s = input()
ka = []
for i in range(q) :
    l, r = list(map(int,input().split()))
    print(s[l - 1 : r].count("AC"))

Fixed submission:
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int,input().split()))
s = input()
ka = []
for i in range(q) :
    ka.append(list(map(int,input().split())))
for i in ka :
    ss = s[i[0] - 1 :i[1]]
    print(ss.count("AC"))


Fixed submission:
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = list(map(int,input().split()))
s = input()
l = []
for i in range(q) :
    l.append(list(map(int,input().split())))
def f(l,r) :
    global s
    count = 0
    for i in range(l,r) :
        if s[i - 1] == "A" and s[i] == "C" :
            count += 1
    print(count)
for l,r in l :
    f(l,r)

Fixed submission:
n,q= map(int,input().split())
s = input()
l = [list(map(int,input().split())) for i in range(q)]
sa = [0]*n
for i in range(0,len(s)-1):
    if s[i] == "A" and s[i+1] == "C":
        sa[i+1] = sa[i] + 1
    else:
        sa[i+1] = sa[i]

""" A C D D D A C A C """
"""0 1 1 1 1 1 2 2 3  """
for si, syu in l:
    print(sa[syu-1] - sa[si-1])