Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = 1
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(sum(t[l:r]))
        
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    t_sum = 0
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = t_sum + 1
            t_sum +=  1
        else: 
            t[i] = t_sum
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])
        
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = 1
        pre = s[i]
    t = np.array(t)
    for _ in range(q):
        l, r = map(int, input().split())
        print(sum(t[l:r]))
        
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    t_sum = 0
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = t_sum + 1
            t_sum +=  1
        else: 
            t[i] = t_sum
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])
        
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, q = map(int, input().split())
    s = input()
    lr =  [list(map(int, input().split())) for _ in range(q)]
    
    t = [0] * n
    pre = s[0]
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = 1
        pre = s[i]
    for l, r in lr:
        print(sum(t[l:r]))
        
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    t_sum = 0
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = t_sum + 1
            t_sum +=  1
        else: 
            t[i] = t_sum
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])
        
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, q = map(int, input().split())
    s = input()
    lr =  [list(map(int, input().split())) for _ in range(q)]
    
    for l, r in lr:
        print(s[l-1:r].count('AC'))
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    t_sum = 0
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = t_sum + 1
            t_sum +=  1
        else: 
            t[i] = t_sum
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])
        
    
if __name__ == '__main__':
    main()