Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
s = [0 for i in range(Q)]
t = 0
for i in range(Q):
    l,r = map(int,input().split())
    j = l-1
    for j in range(l-1,r-1):
        if S[j] is "A" and S[j+1] is "C":
            t += 1
    s[i] = t
    t = 0
for i in range(Q):
    print(s[i])

Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
s = [0 for i in range(Q)]
for i in range(Q):
    l,r = map(int,input().split())
    j = l-1
    for j in range(l-1,r-1):
        if S[j] is "A" and S[j+1] is "C":
            s[i] += 1
for i in range(Q):
    print(s[i])

Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
#S  = input()
#s = []
s = [0 for i in range(Q)]
#print(s)
for i in range(Q):
    l,r = map(int,input().split())
    #s.append(0)
    j = l-1
    while j < r-1:
    #for j in range(l-1,r-1):
        if S[j] is "A" and S[j+1] is "C":
            s[i] += 1
            j += 1
        j += 1
for i in range(Q):
    print(s[i])
#for i in range(Q):
#    print(S[i].count("AC"))


Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
#S  = input()
s = []
for i in range(Q):
    l,r = map(int,input().split())
    s.append(0)
    for j in range(l-1,r-1):
        if S[j] is "A" and S[j+1] is "C":
            s[i] += 1
for i in range(Q):
    print(s[i])
#for i in range(Q):
#    print(S[i].count("AC"))

Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
s = []
for i in range(Q):
    l,r = map(int,input().split())
    #c = 0
    #print(Q,i)
    s.append(0)
    #print(s)
    for j in range(l-1,r-1):
        #print(i,j)
        if S[j] == "A" and S[j+1] == "C":
            s[i] += 1
        #if c == 0 and S[j] == "A":
         #   c = 1
            #print("a")
        #elif c == 1 and S[j] == "C":
         #   c = 0
          #  s[i] = s[i]+ 1
            #print("b")
    #print(i)
for i in range(Q):
    print(s[i])

Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = list(input())
s = []
for i in range(Q):
    l,r = map(int,input().split())
    c = 0
    #print(Q,i)
    s.append(0)
    #print(s)
    for j in range(l-1,r):
        #print(i,j)
        if c == 0 and S[j] == "A":
            c = 1
            #print("a")
        elif c == 1 and S[j] == "C":
            c = 0
            s[i] = s[i]+ 1
            #print("b")
    #print(i)
for i in range(Q):
    print(s[i])

Fixed submission:
N, Q = map(int,input().split())
S = input()
a =[0] * N
for i in range(N-1):
    if S[i] == "A" and S[i + 1] == "C":
        a[i + 1] = a[i] + 1
    else:
        a[i + 1] = a[i]
l, r = 0, 0
b = [0] * Q
for i in range(Q):
    l, r = map(int, input().split())
    b[i] = a[r-1] - a[l-1]
for i in range(Q):
    print(b[i])