Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
count = 0
for match in result:
    count += 1
    ac[match.span()[0]] = count

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    for i in range(end-1, start, -1):
        if ac[i]!=0:
            m = ac[i]
#            print 'm', m
            break
    m2 = 0
    for i in range(start-1, -1, -1):
        if ac[i]!= 0:
            m2 = ac[i]
#            print 'm2',m2
            break
    wa = m-m2
#    wa = np.sum(ac[start:end] == 1)
#    wa = ac[start:end].count(1)
#    wa = sum(ac[start:end])
    if ac[end-1]!=0: wa = wa-1
    print int(wa)


Fixed submission:
#!/usr/bin/env python3
N, Q = map(int, input().split())
S = input()
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append([l,r])

A = [0]

cnt = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        cnt += 1
    A.append(cnt)

for l, r in LR:
    print(A[r-1] - A[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
count = 0
for match in result:
#    count += 1
    ac[match.span()[0]] = 1

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    wa = np.sum(ac[start:end] == 1)
#    wa = ac[start:end].count(1)
#    wa = sum(ac[start:end])
    if ac[end-1]==1: wa = wa-1
    print int(wa)


Fixed submission:
#!/usr/bin/env python3
N, Q = map(int, input().split())
S = input()
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append([l,r])

A = [0]

cnt = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        cnt += 1
    A.append(cnt)

for l, r in LR:
    print(A[r-1] - A[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
for match in result:
    ac[match.span()[0]] = 1

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    wa = sum(ac[start:end])
    if ac[end-1]==1: wa = wa-1
    print int(wa)


Fixed submission:
#!/usr/bin/env python3
N, Q = map(int, input().split())
S = input()
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append([l,r])

A = [0]

cnt = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        cnt += 1
    A.append(cnt)

for l, r in LR:
    print(A[r-1] - A[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

for d in x:
    r = d.split(' ')
    ss = s[int(r[0])-1:int(r[1])]
    print ss.count('AC')

Fixed submission:
#!/usr/bin/env python3
N, Q = map(int, input().split())
S = input()
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append([l,r])

A = [0]

cnt = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        cnt += 1
    A.append(cnt)

for l, r in LR:
    print(A[r-1] - A[l-1])