Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input().rstrip()
sb = s.encode()

for _ in range(q):
  i, r = map(int, input().split())
  print(sb[i-1:r].count(b'AC'))

Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = input()

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input().rstrip()

pos = []
i = 0
while i < len(s):
    i = s.find('AC', i)
    if i == -1:
        break
    pos.append(i)
    i += 2

for _ in range(q):
    i, r = map(int, input().split())
    print(len([c for c in pos if i -1 <= c < r - 1]))

Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = input()

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input().rstrip()

pos = []
i = 0
while i < len(s):
    i = s.find('AC', i)
    if i == -1:
        break
    pos.append(i)
    i += 2

for _ in range(q):
    i, r = map(int, input().split())
    print(len([c for c in pos if i -1 <= c < r - 1]))

Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = input()

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input().rstrip()
for _ in range(q):
  i, r = map(int, input().split())
  print(s[i-1:r].count('AC'))


Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = input()

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input().rstrip()
for _ in range(q):
  i, r = map(int, input().split())
  print(s[i-1:r].count('AC'))


Fixed submission:
def main():
    N, Q = map(int, input().split())
    S = input()

    lis = [0 for _ in range(len(S))]
    for i in range(len(S)):
        if i > 0:
            lis[i] += lis[i - 1]
        if i < len(S) - 1 and S[i] == 'A' and S[i + 1] == 'C':
            lis[i + 1] += 1

    for _ in range(Q):
        L = tuple(map(int, input().split()))
        print(lis[L[1] - 1] - lis[L[0] - 1])


if __name__ == '__main__':
    main()