Buggy python submission (verdict: Time Limit Exceeded):





N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)


a = []
for i in range(N-1):
    if (S[i] == "A")and(S[i+1] == "C"):
        a.append(1)
    else:
        a.append(0)
for i in range(Q):
    l, r = map(int, input().split())
    print(sum(a[l-1:r-1]))

        
    
            
        
    
    
    





Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))

Buggy python submission (verdict: Time Limit Exceeded):





N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

for i in range(Q):
    l, r = map(int, input().split())
    count = 0
    for i in range(len(S[int(l-1):int(r)])-1):
        if (S[int(l-1):int(r)][i] == "A"):
            if (S[int(l-1):int(r)][i+1] == "C"):
                count += 1
    print(count)
            
        
    
    
    





Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)

for i in range(Q):
    l, r = map(int, input().split())
    lst = S[int(l-1):int(r)]
    count = 0
    for i in range(len(lst)-1):
        if (lst[i] == "A")and(lst[i+1] == "C"):
            count += 1
    print(count)

Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))

Buggy python submission (verdict: Time Limit Exceeded):


# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 03:17:55 2019

@author: rubug
"""

# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)

for i in range(Q):
    l, r = map(int, input().split())
    lst = S[int(l-1):int(r)]
    count = 0
    for i in range(len(lst)-1):
        if (lst[i] == "A")and(lst[i+1] == "C"):
            count += 1
    print(count)
            
        
    
    
    





Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))

Buggy python submission (verdict: Time Limit Exceeded):



# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 03:17:55 2019

@author: rubug
"""

# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)

for i in range(Q):
    l, r = map(int, input().split())
    lst = S[int(l-1):int(r)]
    count = 0
    for i in range(len(lst)-1):
        if (lst[i] == "A")and(lst[i+1] == "C"):
            count += 1
    print(count)
            
        
    
    
    





Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))

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

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)
l = np.zeros(Q)
r = np.zeros(Q)
for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    lst = S[int(l[i]-1):int(r[i])]
    count = 0
    for i in range(len(lst)-1):
        if (lst[i] == "A")and(lst[i+1] == "C"):
            count += 1
    print(count)

Fixed submission:




import numpy as np

N,Q = map(int,input().split())
S = []
for c in str(input()):
    S.append(c)

a = np.zeros(N)
   
for i in range(1,N):
    if (S[i-1] == "A")and(S[i] == "C"):
        a[i] = a[i-1] + 1
    else:
        a[i] = a[i-1]
        
for i in range(Q):
    l, r = map(int, input().split())
    print(int(a[r-1] - a[l-1]))