Buggy python submission (verdict: Time Limit Exceeded):
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        l -= 1
        r -= 1
        qua = (r+l)//4
        mid1 = qua+1
        mid2 = qua*2+1
        mid3 = qua*3+1
        cnt = 0
        for i in range(l,mid1):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid1,mid2):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid2,mid3):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid3,r):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    dp = [0]*(N+1)
    for i in range(1,N):
        if S[i-1:i+1] == 'AC':
            dp[i+1] = dp[i]+1
        else:
            dp[i+1] = dp[i]
    for _ in range(Q):
        l,r = map(int, input().split())
        print(dp[r]-dp[l])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        l -= 1
        r -= 1
        mid = (r+l)//2+1
        cnt = 0
        for i in range(l,mid):
            if S[i:i+2] == 'AC': cnt += 1
        for i in range(mid,r):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    dp = [0]*(N+1)
    for i in range(1,N):
        if S[i-1:i+1] == 'AC':
            dp[i+1] = dp[i]+1
        else:
            dp[i+1] = dp[i]
    for _ in range(Q):
        l,r = map(int, input().split())
        print(dp[r]-dp[l])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    ans = [0]*Q
    for q in range(Q):
        l,r = map(int, input().split())
        cnt = 0
        for i in range(l-1,r-1):
            if S[i:i+2] == 'AC': cnt += 1
        print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,Q = map(int, input().split())
    S = input().rstrip()
    dp = [0]*(N+1)
    for i in range(1,N):
        if S[i-1:i+1] == 'AC':
            dp[i+1] = dp[i]+1
        else:
            dp[i+1] = dp[i]
    for _ in range(Q):
        l,r = map(int, input().split())
        print(dp[r]-dp[l])

if __name__ == '__main__':
    main()