Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        sub = cl[l-1:r]
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

cl = [0 for i in range(len(S))]

for i in range(1,len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        cl[i] = cl[i-1] + 1
    else:
        cl[i] = cl[i-1]


#print(cl) 
#print(S)

for l,r in lr:
    sub = cl[l-1:r]
    res = cl[r-1] - cl[l-1] 
    print(res)


Fixed submission:
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

cl = [0 for i in range(len(S))]

for i in range(1,len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        cl[i] = cl[i-1] + 1


#print(cl) 
#print(S)

for l,r in lr:
    sub = cl[l-1:r]
    res = sub.count(1)
    if sub[0] == 1:
        res -= 1
    print(res)


Fixed submission:
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

for l,r in lr:
    substr = S[l-1:r]
    res = 0
    for i in range(len(substr)-1):
        if substr[i] == 'A' and substr[i+1] == 'C':
            res += 1
    print(res)

Fixed submission:
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()