Buggy python submission (verdict: Time Limit Exceeded):
def get_ac(n,q,s,l,r):
    pos = []

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos.append(j+1)

    p_len = len(pos)
    for i in range(q):
        left = l[i]
        right = r[i]
        count = 0
        for j in range(p_len):
            if left <= pos[j] and pos[j]+1 <= right:
                count += 1
        else:
            print count

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

Fixed submission:
def get_ac(n,q,s,l,r):
    pos = [0]*n

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos[j+1] = pos[j] + 1
        else:
            pos[j+1] = pos[j]

    for i in range(q):
        left = l[i]
        right = r[i]
        count = pos[right - 1] - pos[left - 1]

        print count

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':

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

    for i in range(q):
        left,right = map(int,raw_input().split())

        for j in range(left-1,right-1):
            if s[j] == 'A' and s[j+1] == 'C':
                count += 1
        else:
            print count

Fixed submission:
def get_ac(n,q,s,l,r):
    pos = [0]*n

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos[j+1] = pos[j] + 1
        else:
            pos[j+1] = pos[j]

    for i in range(q):
        left = l[i]
        right = r[i]
        count = pos[right - 1] - pos[left - 1]

        print count

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)

Buggy python submission (verdict: Time Limit Exceeded):
def get_ac(n,q,s,l,r):

    for i in range(q):
        left = l[i]
        right = r[i]
        #print s[left-1:right]
        count = 0
        for j in range(left-1,right-1):
            if s[j] == 'A' and s[j+1] == 'C':
                count += 1
        else:
            print count

if __name__ == '__main__':
    n,q = map(int,raw_input().split())
    s = raw_input()

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())


    get_ac(n,q,s,l,r)

Fixed submission:
def get_ac(n,q,s,l,r):
    pos = [0]*n

    for j in range(0,n-1):
        if s[j] == 'A' and s[j+1] == 'C':
            pos[j+1] = pos[j] + 1
        else:
            pos[j+1] = pos[j]

    for i in range(q):
        left = l[i]
        right = r[i]
        count = pos[right - 1] - pos[left - 1]

        print count

if __name__ == '__main__':

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

    l = [0]*q
    r = [0]*q

    for i in range(q):
        l[i],r[i] = map(int,raw_input().split())

#    t2 = time.time()
#    print('{0:.9f}'.format(t2 - t1))
    get_ac(n,q,s,l,r)