Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i]=="A":
        if s[i+1]=="C":
            ac[i+1] = 1

for i in range(q):
    l,r = map(int,input().split())
    ans.append(sum(ac[l:r]))
#ここから出力
for i in ans:
    print(i)

Fixed submission:
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
ac = []
ans = []
for i in range(len(s)-1):
    if s[i]=="A":
        if s[i+1]=="C":
            ac.append(i+1)

for i in range(q):
    l,r = map(int,input().split())
    ct = [i for i in ac if i >= l and i+1 <= r] 
    an = len(ct)
    ans.append(an)
#ここから出力
for i in ans:
    print(i)

Fixed submission:
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
ans = []
for i in range(q):
    l,r = map(int,input().split())
    count = 0
    s_1 = s[l-1:r]
    for i in range(len(s_1)-1):
        if s_1[i]=="A":
            if s_1[i+1]=="C":
                count += 1
    ans.append(count)
#ここから出力
for i in ans:
    print(i)

Fixed submission:
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
l = []
ans = []
for i in range(q):
    l1 = [int(i) for i in input().split()]
    l.append(l1)
#ここまで入力
for i in l:
    count = 0
    s_1 = s[i[0]-1:i[1]]
    for i in range(len(s_1)-1):
        if s_1[i]=="A":
            if s_1[i+1]=="C":
                count += 1
    ans.append(count)
#ここから出力
for i in ans:
    print(i)

Fixed submission:
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int,input().split())
s = input()
l = []
ans = []
for i in range(q):
    l1 = [int(i) for i in input().split()]
    l.append(l1)
#ここまで入力
for i in l:
    count = 0
    s_1 = s[i[0]-1:i[1]]
    for i in range(len(s_1)-1):
        if s_1[i]=="A":
            if s_1[i+1]=="C":
                count += 1
    ans.append(count)
#ここから出力
for i in ans:
    print(i)

Fixed submission:
n,q = map(int,input().split())
s = input()
ac = [0 for i in range(n+1)]
ans = []
for i in range(len(s)-1):
    if s[i:i+2]=="AC":
        ac[i+1] = ac[i] + 1
    else:
        ac[i+1] = ac[i]

for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])