Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        S_2 = ''.join(S[l-1:r])
        print(len(re.findall('AC', S_2)))
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        S_2 = ''.join(S[l-1:r])
        print(S_2.count("AC"))
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            I.append(i)
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        R = []
        for i in I:
            if l-1 <= i < r-1:
                cnt += 1
        print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    I = []
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            I.append(i)
    for j in range(Q):
        cnt = 0
        l,r = L[j]
        R = []
        for k in range(l-1,r-1):
            R.append(k)
        for i in I:
            if i in R:
                cnt += 1
        print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
    I = []
    for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        I.append(i)
    for j in range(Q):
    cnt = 0
    l,r = L[j]
    R = []
    for k in range(l-1,r-1):
        R.append(k)
    for i in I:
        if i in R:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S = list(input())
L = []
for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
I = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        I.append(i)
for j in range(Q):
    cnt = 0
    l,r = L[j]
    R = []
    for k in range(l-1,r-1):
        R.append(k)
    for i in I:
        if i in R:
            cnt += 1
    print(cnt)

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S = list(input())
L = []
for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
I = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        I.append(i)
for j in range(Q):
    cnt = 0
    l,r = L[j]
    R = []
    for k in range(l-1,r-1):
        R.append(k)
    for i in I:
        if i in R:
            cnt += 1
    print(cnt)

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = list(map(int, input().split()))
S = list(input())
L = []
for _ in range(Q):
    temp = list(map(int, input().split()))
    L.append(temp)
for i in range(Q):
    ans = 0
    r,l = L[i]
    for j in range(r-1,l-1):
        if S[j] == "A" and S[j + 1] == "C":
            ans += 1
    print(ans)

Fixed submission:
def main():
    import sys
    import re
    input = sys.stdin.readline
    N,Q = list(map(int, input().split()))
    S = list(input())
    L = []
    for _ in range(Q):
        temp = list(map(int, input().split()))
        L.append(temp)
    dp = [0] * N
    for i in range(1,N):
        if S[i] == "C" and S[i-1] == "A":
            dp[i] = dp[i-1] + 1
        else:
            dp[i] = dp[i-1]
    for j in range(Q):
        l,r = L[j]
        print(dp[r-1] - dp[l-1])
if __name__ == '__main__':
    main()