Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from Lib import heapq
Heappop=heapq.heappop
Heappush=heapq.heappush
N,M=map(int,input().split())
L=[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
q=[0]*10**5
ans=0
d=1
memo=0
while d<=M:
    while memo<=N-1:
        a,b=L[memo]
        if d<a:
            break
        else:
            Heappush(q,b)
            memo+=1
    ans-=Heappop(q)
    d+=1
print(ans)

Fixed submission:
import heapq
Heappop=heapq.heappop
Heappush=heapq.heappush
N,M=map(int,input().split())
L=[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
q=[0]*10**5
ans=0
d=1
memo=0
while d<=M:
    while memo<=N-1:
        a,b=L[memo]
        if d<a:
            break
        else:
            Heappush(q,b)
            memo+=1
    ans-=Heappop(q)
    d+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
for i in range(len(S)):
    new_dp=[0]*13
    s=S[-1-i]
    if s=="?":
        for j in range(10):
            rem=(j*10**i)%13
            for k in range(13):
                new_dp[(k+rem)%13]+=dp[k]
    else:
        rem=(int(s)*10**i)%13
        for k in range(13):
            new_dp[(k+rem)%13]+=dp[k]
    for l in range(13):
        new_dp[l]%=MOD
    dp=new_dp
print(dp[5])

Fixed submission:
a,b=map(int,input().split())
if (a+b)%2==1:print("IMPOSSIBLE")
else:print((a+b)//2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
A=deque(list(map(int,input().split())))
D={}
ans=""
M=0
for i in range(N):
    a=A.pop()
    if N//(N-i)==1:
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        p=N//(N-i)
        memo=0
        for j in range(1,p):
            memo+=D[(N-i)*(j+1)]
        if memo%2==a:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Fixed submission:
from collections import deque
N=int(input())
A=deque(list(map(int,input().split())))
D={}
ans=[]
M=0
for i in range(N):
    a=A.pop()
    if N//(N-i)==1:
        D[N-i]=a
        if a==1:
            M+=1
            ans.append(str(N-i))
    else:
        p=N//(N-i)
        memo=0
        for j in range(1,p):
            memo+=D[(N-i)*(j+1)]
        if memo%2==a:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans.append(str(N-i))
print(M)
print(" ".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
D={}
ans=""
M=0
for i in range(N):
    if N//(N-i)==1:
        a=A[N-i-1]
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        a=N//(N-i)
        memo=0
        for j in range(1,a):
            memo+=D[(N-i)*(j+1)]
        if memo%2==A[N-i-1]:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Fixed submission:
from collections import deque
N=int(input())
A=deque(list(map(int,input().split())))
D={}
ans=[]
M=0
for i in range(N):
    a=A.pop()
    if N//(N-i)==1:
        D[N-i]=a
        if a==1:
            M+=1
            ans.append(str(N-i))
    else:
        p=N//(N-i)
        memo=0
        for j in range(1,p):
            memo+=D[(N-i)*(j+1)]
        if memo%2==a:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans.append(str(N-i))
print(M)
print(" ".join(ans))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
D={}
ans=""
M=0
for i in range(N):
    if N//(N-i)==1:
        a=A[N-i-1]
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        a=N//(N-i)
        memo=0
        for j in range(1,a):
            memo+=D[(N-i)*(j+1)]
        if memo%2==A[N-i-1]:D[N-i]=0
        else:
            D[N-i-1]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Fixed submission:
from collections import deque
N=int(input())
A=deque(list(map(int,input().split())))
D={}
ans=[]
M=0
for i in range(N):
    a=A.pop()
    if N//(N-i)==1:
        D[N-i]=a
        if a==1:
            M+=1
            ans.append(str(N-i))
    else:
        p=N//(N-i)
        memo=0
        for j in range(1,p):
            memo+=D[(N-i)*(j+1)]
        if memo%2==a:
            D[N-i]=0
        else:
            D[N-i]=1
            M+=1
            ans.append(str(N-i))
print(M)
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
S=sum(A)//2
m=S
for n in range(N//2):m-=A[2*n+1]
ans=str(2*m)
for i in range(N-1):
    ans=ans+" "+str(2*(A[i]-m))
    m=A[i]-m
print(ans)

Fixed submission:
from collections import deque
N=int(input())
A=list(map(int,input().split()))
D=deque(A)
m=sum(A)//2
for n in range(N//2):m-=A[2*n+1]
ans=str(2*m)
for _ in range(N-1):
    a=deque.popleft(D)-m
    ans+=" "+str(a*2)
    m=a
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import factorial
def C(a,b):
    return (factorial(a)//factorial(b))//factorial(a-b)
N,K=map(int,input().split())
MOD=10**9+7
for i in range(1,K+1):
    print((C(N-K+1,i)*(C(K-1,i-1)))%MOD)

Fixed submission:
from math import factorial
def C(a,b):
    return (factorial(a)//factorial(b))//factorial(a-b)
N,K=map(int,input().split())
MOD=10**9+7
for i in range(1,K+1):
    if N-K+1>=i:print((C(N-K+1,i)*(C(K-1,i-1)))%MOD)
    else:print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict
input=sys.stdin.readline

n,m=map(int,input().split())
G=[[] for _ in range(n+1)]
for _ in range(m):
    u,v=map(int,input().split())
    G[u].append(v)
s,t=map(int,input().split())

D=defaultdict(int)
L=[s]
LL,LLL,LLLL,l=[],[],[],[]
cnt=0

while L:
    if t in L:
        print(cnt)
        exit()
    for i in L:
        for j in G[i]:
            LL.append(j)
    for ii in LL:
        for jj in G[ii]:
            LLL.append(jj)
    for iii in LLL:
        for jjj in G[iii]:
            LLLL.append(jjj)
    for iiii in LLLL:
        if D[iiii]==0:
            D[iiii]=1
            l.append(iiii)
    L,LL,LLL,LLLL=l,[],[],[]
    l=[]
    cnt+=1

print(-1)

Fixed submission:
import sys
from collections import deque
input=sys.stdin.readline

n,m=map(int,input().split())
G=[[] for _ in range(3*(n+1))]
for _ in range(m):
    u,v=map(int,input().split())
    G[3*u].append(3*v+2)
    G[3*u+1].append(3*v)
    G[3*u+2].append(3*v+1)
s,t=map(int,input().split())

Q=deque()
Q.append(s*3)
D=[-3 for _ in range(3*(n+1))]
D[s*3]=0

while Q:
    q=Q.popleft()
    for i in G[q]:
        if D[i]==-3:
            D[i]=D[q]+1
            Q.append(i)

print(D[t*3]//3)
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))

ans,i,D=0,1,0

while D<=X:
    D+=L[i-1]
    ans+=1
    i+=1
    
print(ans)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))

ans,D=1,0

for l in L:
   D+=l
   if D<=X:
       ans+=1
       
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
L=[]
for _ in range(n):
   x,y=map(int,input().split())
   L.append((x,y))
D=[]
for i in range(n):
   for j in range(i+1,n):
         D.append((L[i][0]-L[j][0],L[i][1]-L[j][1]))
         D.append((L[j][0]-L[i][0],L[j][1]-L[i][1]))
C=Counter(D)
print(n-C.most_common()[0][1])

Fixed submission:
from collections import Counter
n=int(input())
L=[]
for _ in range(n):
   x,y=map(int,input().split())
   L.append((x,y))
D=[]
if n==1:print(1)
else:
   for i in range(n):
      for j in range(i+1,n):
          D.append((L[i][0]-L[j][0],L[i][1]-L[j][1]))
          D.append((L[j][0]-L[i][0],L[j][1]-L[i][1]))
   C=Counter(D)
   print(n-C.most_common()[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
A=[]
MOD=10**9+7
for _ in range(M):
    A.append(int(input()))

a,b,n=0,1,1
while n<=N:
    if n in A:
        a,b=b,0
    else:
        a,b=b,a+b
    n+=1

print(b%MOD)

Fixed submission:
N,M=map(int,input().split())
MOD=10**9+7
p,q,n=0,1,1
for _ in range(M):
    a=int(input())
    while n<=a:
        p,q=q,p+q
        n+=1
    q=0
while n<=N:
    p,q=q,p+q
    n+=1

print(q%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
LA=list(map(int,input().split()))
for m in range(M):
    B,C=map(int,input().split())
    LA.extend([C]*B)
LA.sort(reverse=True)
print(sum(LA[0:N]))

Fixed submission:
N,M=map(int,input().split())
LA=list(map(int,input().split()))
L=[]
for i in LA:
    L.extend([[1,i]])
for m in range(M):
    B,C=map(int,input().split())
    L.extend([[B,C]])
L.sort(key=lambda _:_[1] ,reverse=True)

ans=0
n=0
x=0
while x<=N-1:
    y=0
    while y<=L[n][0]-1:
        ans+=L[n][1]
        y+=1
        x+=1
        if x==N:
            break
        else:
            pass
    n+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
LA=list(map(int,input().split()))
for m in range(M):
    B,C=map(int,input().split())
    for b in range(B):
        LA.append(C)
LA.sort(reverse=True)
print(sum(LA[0:N]))

Fixed submission:
N,M=map(int,input().split())
LA=list(map(int,input().split()))
L=[]
for i in LA:
    L.extend([[1,i]])
for m in range(M):
    B,C=map(int,input().split())
    L.extend([[B,C]])
L.sort(key=lambda _:_[1] ,reverse=True)

ans=0
n=0
x=0
while x<=N-1:
    y=0
    while y<=L[n][0]-1:
        ans+=L[n][1]
        y+=1
        x+=1
        if x==N:
            break
        else:
            pass
    n+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
LA=list(map(int,input().split()))
LA.sort()
for m in range(M):
    B,C=map(int,input().split())
    for b in range(B):
        if LA[b]<=C:
            LA[b]=C
        else:
            break
    LA.sort()

print(sum(LA))

Fixed submission:
N,M=map(int,input().split())
LA=list(map(int,input().split()))
L=[]
for i in LA:
    L.extend([[1,i]])
for m in range(M):
    B,C=map(int,input().split())
    L.extend([[B,C]])
L.sort(key=lambda _:_[1] ,reverse=True)

ans=0
n=0
x=0
while x<=N-1:
    y=0
    while y<=L[n][0]-1:
        ans+=L[n][1]
        y+=1
        x+=1
        if x==N:
            break
        else:
            pass
    n+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
ListAbeta=list(map(int,input().split()))
ListA=sorted(ListAbeta)
ListBC=[]
m=1
while m<=M:
    ListBC.append(list(map(int,input().split())))
    b=1
    while b<=ListBC[m-1][0]:
        if ListA[b-1]>=ListBC[m-1][1]:
            break
        else:
            ListA[b-1]=ListBC[m-1][1]
            b+=1
    ListA=sorted(ListA)
    m+=1
    b=0
print(sum(ListA))

Fixed submission:
N,M=map(int,input().split())
LA=list(map(int,input().split()))
L=[]
for i in LA:
    L.extend([[1,i]])
for m in range(M):
    B,C=map(int,input().split())
    L.extend([[B,C]])
L.sort(key=lambda _:_[1] ,reverse=True)

ans=0
n=0
x=0
while x<=N-1:
    y=0
    while y<=L[n][0]-1:
        ans+=L[n][1]
        y+=1
        x+=1
        if x==N:
            break
        else:
            pass
    n+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
=input()
L=["01","02","03","04","05","06","07","08","09","10","11","12"]

if S[:2] in L:
    if S[2:] in L:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if S[2:] in L:
        print("YYMM")
    else:
        print("NA")

Fixed submission:
S=input()
L=["01","02","03","04","05","06","07","08","09","10","11","12"]

if S[:2] in L:
    if S[2:] in L:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if S[2:] in L:
        print("YYMM")
    else:
        print("NA")
Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=list(map(int,input().split()))

p_m=1
for n in range(N):
    p_m*=LA[n]
    
LA_absolute=[i*(-1) if i<0 else i for i in LA]


if p_m>=0:
    print(sum(LA_absolute))
else:
    print(sum(LA_absolute)-2*min(LA_absolute))

Fixed submission:
A,B,T=map(int,input().split())

print(B*(T//A))

Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    while n:
        m,n=n,m%n
    return m

from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

Fixed submission:
A,B,T=map(int,input().split())

print(B*(T//A))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    while n:
        m,n=n,m%n
    return m

from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    if m==0 or n==0:
        return m+n
    while n:
        m,n=n,m%n
    return m

La=[0]
Lb=[0]

for n in range(N-1):
    La.append(gcd(La[n],LA[n]))
    Lb.append(gcd(Lb[n],LA[-(n+1)]))

for n in range(N):
    ans.append(gcd(La[n],Lb[-(n+1)]))
        
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    if m==0 or n==0:
        return m+n
    while n:
        m,n=n,m%n
    return m

La=[0]
Lb=[0]

for n in range(N-1):
    La.append(gcd(La[n],LA[n]))
    Lb.append(gcd(Lb[n],LA[-(n+1)]))

for n in range(N):
    ans.append(gcd(La[n],Lb[-(n+1)]))
        
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def func(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(func(L))

print(max(ans))

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    if m==0 or n==0:
        return m+n
    while n:
        m,n=n,m%n
    return m

La=[0]
Lb=[0]

for n in range(N-1):
    La.append(gcd(La[n],LA[n]))
    Lb.append(gcd(Lb[n],LA[-(n+1)]))

for n in range(N):
    ans.append(gcd(La[n],Lb[-(n+1)]))
        
print(max(ans))

Buggy python submission (verdict: Runtime Error):
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def func(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(func(L))

print(max(ans))

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    if m==0 or n==0:
        return m+n
    while n:
        m,n=n,m%n
    return m

La=[0]
Lb=[0]

for n in range(N-1):
    La.append(gcd(La[n],LA[n]))
    Lb.append(gcd(Lb[n],LA[-(n+1)]))

for n in range(N):
    ans.append(gcd(La[n],Lb[-(n+1)]))
        
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
LA=list(map(int,input().split()))

p_m=1
for n in range(N):
    p_m*=LA[n]
    
LA_absolute=[i*(-1) if i<0 else i for i in LA]


if p_m>=0:
    print(sum(LA_absolute))
else:
    print(sum(LA_absolute)-2*min(LA_absolute))

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==1:
    ans=sum(L_absolute)
elif Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)

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

p_m=1
for n in range(N):
    p_m*=LA[n]
    
LA_absolute=[i*(-1) if i<0 else i for i in LA]


if p_m>=0:
    print(sum(LA_absolute))
else:
    LA_absolute.sort()
    print(sum(LA_absolute)-2*LA_absolute[0])

Fixed submission:
N=int(input())
LA=list(map(int,input().split()))

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==1:
    ans=sum(L_absolute)
elif Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB=[]
append=AB.append
for i in range(min(K,X)):
    for j in range(min(K,Y)):
        append(A[i]+B[j])
AB.sort(reverse=True)
ABC=[]
appendd=ABC.append
for k in range(min(K,len(AB))):
    for l in range(min(K,Z)):
        appendd(AB[k]+C[l])
ABC.sort(reverse=True)
for m in range(K):
    print(ABC[m])

Fixed submission:
import sys
def main():
    input=sys.stdin.readline
    X,Y,Z,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    AB=[]
    append=AB.append
    for i in range(min(K,X)):
        for j in range(min(K,Y)):
            append(A[i]+B[j])
    AB.sort(reverse=True)

    ABC=[]
    appendd=ABC.append
    for k in range(min(K,len(AB))):
        for l in range(min(K,Z)):
            appendd(AB[k]+C[l])
    ABC.sort(reverse=True)

    for m in range(K):
        print(ABC[m])

if __name__=="__main__":
    main()

Buggy python submission (verdict: Runtime Error):
X,Y,Z,K=list(map(int,input().split()))
LA=list(map(int,input().split()))
LB=list(map(int,input().split()))
LC=list(map(int,input().split()))

LA.sort(reverse=True)
LB.sort(reverse=True)
LC.sort(reverse=True)

L=[]

for p in range(min(X,K-2)):
    for q in range(min(Y,K-p-1)):
        for r in range(min(Z,K-p-q)):
            L.append(LA[p]+LB[q]+LC[r])

L.sort(reverse=True)

for k in range(K):
    print(L[k])

Fixed submission:
import sys
def main():
    input=sys.stdin.readline
    X,Y,Z,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    AB=[]
    append=AB.append
    for i in range(min(K,X)):
        for j in range(min(K,Y)):
            append(A[i]+B[j])
    AB.sort(reverse=True)

    ABC=[]
    appendd=ABC.append
    for k in range(min(K,len(AB))):
        for l in range(min(K,Z)):
            appendd(AB[k]+C[l])
    ABC.sort(reverse=True)

    for m in range(K):
        print(ABC[m])

if __name__=="__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
AC_or_No=[]
ans=[]
n=0

while n<=N-2:
    if S[n]=="A":
        if S[n+1]=="C":
            AC_or_No.append(1)
            AC_or_No.append(0)
            n+=2
    else:
        AC_or_No.append(0)
        n+=1

for _ in range(Q):
    l,r=map(int,input().split())
    ans.append(sum(AC_or_No[l-1:r-1]))

for i in ans:
    print(i)

Fixed submission:
N,Q=map(int,input().split())
S=input()
AC_or_No=[0]
ans=[]
n=0

while n<=N-2:
    if S[n]=="A" and S[n+1]=="C":
        AC_or_No.append(AC_or_No[n]+1)
    else:
        AC_or_No.append(AC_or_No[n])
    n+=1

for _ in range(Q):
    l,r=map(int,input().split())
    ans.append(AC_or_No[r-1]-AC_or_No[l-1])

for i in ans:
    print(i)

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

for _ in range(Q):
    l,r=map(int,input().split())
    continuous=0
    while l<=r-1:
        if S[l-1]=="A":
            if S[l]=="C":
                continuous+=1
                l+=2
        else:
            l+=1
    ans.append(continuous)

for j in ans:
    print(j)

Fixed submission:
N,Q=map(int,input().split())
S=input()
AC_or_No=[0]
ans=[]
n=0

while n<=N-2:
    if S[n]=="A" and S[n+1]=="C":
        AC_or_No.append(AC_or_No[n]+1)
    else:
        AC_or_No.append(AC_or_No[n])
    n+=1

for _ in range(Q):
    l,r=map(int,input().split())
    ans.append(AC_or_No[r-1]-AC_or_No[l-1])

for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
A,B=map(int,input().split())
ans=A
i=1

while i<=B-A:
    ans=ans^(A+i)
    i+=1

print(ans)

Fixed submission:
A,B=map(int,input().split())

def XOR(x):
    if x%4==1 or x%4==2:
        l="0"
    else:
        l="1"
    i=2
    while x>=(2**(i-1)):
        k=x%(2**i)
        if k<=2**(i-1)-1:
            l+="0"
        else:
            if k%2==0:
                l+="1"
            else:
                l+="0"
        i+=1    
    l=l[::-1]
    return(l)

b=XOR(B)
a=XOR(A-1).zfill(len(b))
ans=""

for j in range(len(b)):
    if b[j]==a[j]:
        ans+="0"
    else:
        ans+="1"

print(int(ans,2))

Buggy python submission (verdict: Time Limit Exceeded):
A,B=map(int,input().split())
l=[]
ldi=[]
ans=""

a=A
while a<=B:
    l.append(format(a, 'b'))
    a+=1

i=0
while i<=B-A:
    ldi.append(l[i].zfill(len(format(B, 'b'))))
    i+=1

j=0
while j<=len(format(B, 'b'))-1:
    k=0
    p=0
    while k<=B-A:
        if ldi[k][j]=="1":
            p+=1
        else:
            pass
        k+=1
    if p%2==1:
        ans=ans+"1"
    else:
        ans=ans+"0"
    j+=1

print(int(ans, 2))

Fixed submission:
A,B=map(int,input().split())

def XOR(x):
    if x%4==1 or x%4==2:
        l="0"
    else:
        l="1"
    i=2
    while x>=(2**(i-1)):
        k=x%(2**i)
        if k<=2**(i-1)-1:
            l+="0"
        else:
            if k%2==0:
                l+="1"
            else:
                l+="0"
        i+=1    
    l=l[::-1]
    return(l)

b=XOR(B)
a=XOR(A-1).zfill(len(b))
ans=""

for j in range(len(b)):
    if b[j]==a[j]:
        ans+="0"
    else:
        ans+="1"

print(int(ans,2))
Buggy python submission (verdict: Time Limit Exceeded):
A,B,Q=map(int,input().split())
s=[]
t=[]
answer=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s=[-10**21]+s+[10**21]
t=[-10**21]+t+[10**21]

def binary_search(list,target):
    left=0
    right=len(list)-1
    while left<=right:
        center=(left+right)//2
        if list[center]==target:
            return center
            break
        elif list[center]<target and list[center+1]>target:
            return center
            break
        elif list[center]<target:
            left=center+1
        else:
            right=center-1
    
for q in range(Q):
    x=int(input())
    i=binary_search(s,x)
    j=binary_search(t,x)
    ans=min(max(x-t[j],x-s[i]),max(s[i+1]-x,t[j+1]-x),t[j+1]-s[i]+min(x-s[i],t[j+1]-x),s[i+1]-t[j]+min(x-t[j],s[i+1]-x))
    answer.append(ans)

for k in answer:
    print(k)

Fixed submission:
A,B,Q=map(int,input().split())
s=[]
t=[]
answer=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s=[-10**21]+s+[10**21]
t=[-10**21]+t+[10**21]

def binary_search(list,target):
    left=0
    right=len(list)-1
    while left<=right:
        center=(left+right)//2
        if list[center]<target and list[center+1]>target:
            return center
            break
        elif list[center]<target:
            left=center+1
        else:
            right=center-1
    
for q in range(Q):
    x=int(input())
    i=binary_search(s,x)
    j=binary_search(t,x)
    ans=min(max(x-t[j],x-s[i]),max(s[i+1]-x,t[j+1]-x),t[j+1]-s[i]+min(x-s[i],t[j+1]-x),s[i+1]-t[j]+min(x-t[j],s[i+1]-x))
    answer.append(ans)

for k in answer:
    print(k)