Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(0, len(data), 2):
        if data[i]=='A':
            if (i+1)<len(data):
                if data[i+1] == 'C':
                    cnt+=1
        elif data[i]=='C':
            if (i-1)>=0:
                if data[i-1] == 'A':
                    cnt+=1
    return cnt
  
ret = []

for i in range(Q):
    r, l = map(int, input().split())
    cnt = countAC(S, r, l)
    ret.append(str(cnt))
print('\n'.join(ret))

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []

for i in range(Q):
    r, l = map(int, input().split())
    cnt = countAC(S, r, l)
    ret.append(str(cnt))
print('\n'.join(ret))

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []
for it in pos:
    cnt = countAC(S, it[0], it[1])
    ret.append(str(cnt))
print('\n'.join(ret))

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []
for it in pos:
    cnt = countAC(S, it[0], it[1])
    ret.append(cnt)
_ = [print(it) for it in ret]

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
for it in pos:
    cnt = countAC(S, it[0], it[1])
    print(cnt)

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
N ,Q = map(int, input().split())
S = input()

pos = []
for i in range(Q):
    pos.append(list(map(int, input().split())))
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
for it in pos:
    cnt = countAC(S, it[0], it[1])
    print(cnt)

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

cumul = [0]*len(S)
cnt = 0
for i in range(len(S)-1):
    cumul[i] = cnt
    if S[i]=='A':
        if S[i+1] == 'C':
            cnt+=1
cumul[-1]=cnt

ret = []
for i in range(Q):
    l, r = map(int, input().split())
    cnt = cumul[r-1] - cumul[l-1]
    ret.append(str(cnt))
print('\n'.join(ret))