Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

n=int(input())
a=list(map(int,input().split()))

mod=10**9+7
acnt=dict()
acnt[a[0]]=1
t=3
for i in range(1,n):

    if a[i] in acnt:
        acnt[a[i]]+=1
    else:
        acnt[a[i]]=1

    if a[i]!=0:
        if acnt[a[i]-1]==2:
            if acnt[a[i]]==1:
                t=(t*2)%mod
        elif acnt[a[i]-1]==3:
            if acnt[a[i]]==1:
                t=(t*3)%mod
            elif acnt[a[i]]==2:
                t=(t*2)%mod
    else:
        if acnt[0]==2:
            t=(t*2)%mod

#    print("i:",i,"a[i]:",a[i],"acnt[a[i]]:",acnt[a[i]],"t:",t)
                
print(t)       
        


Fixed submission:

import sys

n=int(input())
a=list(map(int,input().split()))

#n=54
#a=[0,0,1,0,1,2,1,2,3,2,3,3,4,4,5,4,6,5,7,8,
#   5,6,6,7,7,8,8,9,9,10,10,11,9,12,10,13,14,
#   11,11,12,12,13,13,14,14,15,15,15,16,16,16,
#   17,17,17]
#ans=115295190

#n=10
#a=[3,2,5,1,7,3,6,4,5,4]
#ans=0

if a[0]!=0:
    print(0)
    sys.exit()
 
mod=10**9+7
acnt=dict()
acnt[a[0]]=1
acntkeymax=0
t=3
for i in range(1,n):

    if a[i] in acnt:
        acnt[a[i]]+=1
        if acnt[a[i]]>3:
            print(0)
            sys.exit()
    else:
        if acntkeymax+1==a[i]:
            acntkeymax=a[i]
            acnt[a[i]]=1
        else:
            print(0)
            sys.exit()

    if a[i]!=0:
        if acnt[a[i]-1]==1:
            if acnt[a[i]]!=1:
                print(0)
                sys.exit()
        elif acnt[a[i]-1]==2:
            if acnt[a[i]]==1:
                t=(t*2)%mod
            elif acnt[a[i]]!=2:
                print(0)
                sys.exit()
        elif acnt[a[i]-1]==3:
            if acnt[a[i]]==1:
                t=(t*3)%mod
            elif acnt[a[i]]==2:
                t=(t*2)%mod
            elif acnt[a[i]]!=3:
                print(0)
                sys.exit()
    else:
        if acnt[0]==2:
            t=(t*2)%mod
        elif acnt[0]!=3:
            print(0)
            sys.exit()

#    print("i:",i,"a[i]:",a[i],"acnt[a[i]]:",acnt[a[i]],"t:",t)
                
print(t)
Buggy python submission (verdict: Runtime Error):
from collections import deque

n=int(input())
g=[[] for i in range(n)]
b=[0]*(n-1)
for i in range(n-1):
    ai,bi=map(int,input().split())
    g[ai-1].append(bi-1)
    g[bi-1].append(ai-1)
    b[i]=bi-1
    
#n=8
#g=[[1], [0, 2, 3, 4], [1], [1, 6], [1, 5], [4, 7], [3], [5]]
#n=6
#g=[[1, 2, 3, 4, 5], [0], [0], [0], [0], [0]]

q=deque([0])

stack=[0]
parent=[-1]*n
pc=[-1]*n
parent[0]=0
dist=[-1]*n
dist[0]=0
while q:
    state = q.popleft()
    ic=0
    for v in g[state]:
        if parent[v] !=-1:
            continue
        else:
            parent[v]=state
            dist[v]=dist[state]+1
            q.append(v)
            ic+=1
            if ic==pc[state]:
                ic+=1
            pc[v]=ic

k=max(pc)
print(k)
for i in range(1,n):
    print(pc[bi[i]])
    

Fixed submission:
from collections import deque

n=int(input())
g=[[] for i in range(n)]
b=[0]*(n-1)
for i in range(n-1):
    ai,bi=map(int,input().split())
    g[ai-1].append(bi-1)
    g[bi-1].append(ai-1)
    b[i]=bi-1
    
#n=8
#g=[[1], [0, 2, 3, 4], [1], [1, 6], [1, 5], [4, 7], [3], [5]]
#b=[1, 2, 3, 4, 6, 5, 7]
#n=6
#g=[[1, 2, 3, 4, 5], [0], [0], [0], [0], [0]]

q=deque([0])

stack=[0]
parent=[-1]*n
pc=[-1]*n
parent[0]=0
dist=[-1]*n
dist[0]=0
while q:
    state = q.popleft()
    ic=0
    for v in g[state]:
        if parent[v] !=-1:
            continue
        else:
            parent[v]=state
            dist[v]=dist[state]+1
            q.append(v)
            ic+=1
            if ic==pc[state]:
                ic+=1
            pc[v]=ic

k=max(pc)
print(k)
for i in range(n-1):
    print(pc[b[i]])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000000)

def slime(slist,t):
    if len(slist)==1:
        if len(t)==0:
            return slist[0]
        elif slist[0]==t[0]:
            return t
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
        return t
    else:
        if slist[0]==slist[1]:
            del slist[0]
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
            del slist[0]
        return slime(slist,t)
        


n=int(input())
s=input()
slist=[]
t=[]

for i in range(len(s)):
    slist.append(s[i])
    
t=slime(slist,t)
print(len(t))

Fixed submission:
n=int(input())
s=input()
if n==1:
    print(1)
else:
    slist=[]
    for i in range(len(s)):
        slist.append(s[i])
    
    for i in range(len(s)-1,0,-1):
        if slist[i-1]==slist[i]:
            del slist[i]

    print(len(slist))

Buggy python submission (verdict: Runtime Error):
def slime(slist,t):
    if len(slist)==1:
        if len(t)==0:
            return slist[0]
        elif slist[0]==t[0]:
            return t
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
        return t
    else:
        if slist[0]==slist[1]:
            del slist[0]
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
            del slist[0]
        return slime(slist,t)
        


n=int(input())
s=input()
slist=[]
t=[]

for i in range(len(s)):
    slist.append(s[i])
    
t=slime(slist,t)
print(len(t))

Fixed submission:
n=int(input())
s=input()
if n==1:
    print(1)
else:
    slist=[]
    for i in range(len(s)):
        slist.append(s[i])
    
    for i in range(len(s)-1,0,-1):
        if slist[i-1]==slist[i]:
            del slist[i]

    print(len(slist))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=(input().split())
a1={}
for i in range(n):
    a1[(a[i])]=i+1
#print(a1)    
str1=""
for i in range(n):
    a2=str(i+1)
#    print(a2)
    str1=str1 + " " + str(a1[a2])
print(str1)

Fixed submission:
n=int(input())
a=(input().split())
a1={}
for i in range(n):
    a1[(a[i])]=i+1
str1=""
for i in range(n):
    print(str(a1[str(i+1)]),end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=(input().split())
a1=[]
for i in range(n):
    a1.append(int(a[i]))
    
str1=""
for i in range(n):
    for ii in range(n):
        if i+1 == int(a[ii]):
            str1=str1 + " " +str(ii+1)
            break
print(str1)

Fixed submission:
n=int(input())
a=(input().split())
a1={}
for i in range(n):
    a1[(a[i])]=i+1
str1=""
for i in range(n):
    print(str(a1[str(i+1)]),end=" ")
print()

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
#a=map(int,input().split())
a=(input().split())
#print(a)
a1=[]
for i in range(n):
    a1.append(int(a[i]))
#print(a1)
    
str1=""
for i in range(n):
    for ii in range(n):
        if i+1 == int(a[ii]):
            str1=str1 + " " +str(ii+1)
print(str1)

Fixed submission:
n=int(input())
a=(input().split())
a1={}
for i in range(n):
    a1[(a[i])]=i+1
str1=""
for i in range(n):
    print(str(a1[str(i+1)]),end=" ")
print()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
slist=[]
for i in range(n):
    s10=input()
    si=[]
    for ii in range(10):
        si.append(s10[ii])
    si.sort()
    stmp=""
    for ii in range(10):
        stmp=stmp+si[ii]
    slist.append(stmp)
    
icnt=0    
for i in range(n):
    for j in range(i+1,n):
        if slist[i]==slist[j]:
            icnt=icnt+1
            
print(icnt)            

Fixed submission:
n=int(input())
slist=[]
for i in range(n):
    s10=input()
    si=[]
    for ii in range(10):
        si.append(s10[ii])
    si.sort()
    stmp=""
    for ii in range(10):
        stmp=stmp+si[ii]
    slist.append(stmp)
slist.sort()
    
icnt=0   
i=0 
while i<=n-2:
    j=i+1
    jcnt=0
    while slist[i]==slist[j]:
        jcnt=jcnt+1
        icnt=icnt+jcnt
        j=j+1
        if j>=n:
            break
    i=j
    if i>=n-1:
        break
            
print(icnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
imax=0
amax=int(input())
amax2=amax
for i in range(1,n)
    ai=int(input())
    if amax<ai:
        amax=ai
        imax=i
        if amax2<ai:
          amax2=ai
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
    print(amax)
    

Fixed submission:
n=int(input())
imax=0
amax=0
amax2=amax
for i in range(n):
    ai=int(input())
    if amax<ai:
        adummy=amax
        amax=ai
        imax=i
        amax2=adummy
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())

w2=w//2
h2=h//2

s1=h*w2
s2=w*h2
err1=(s1-s2)/s1
if -1.0*10**(-9)<err1 and err1<1.0*10**(-9):
    print(s1,1)
elif s1>s2:
    print(s1,0)
else:
    print(s2,0)

Fixed submission:
w,h,x,y=map(int,input().split())

if w/2==x and h/2==y:
    print(0.5*h*w,1)
else:
    print(0.5*h*w,0)

Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())

w2=w//2
h2=h//2

s1=h*w2
s2=w*h2
err1=(s1-s2)/s1
if -1.0*10**(-9)<err1<1.0*10**(-9):
    print(s1,1)
elif s1>s2:
    print(s1,0)
else:
    print(s2,0)

Fixed submission:
w,h,x,y=map(int,input().split())

if w/2==x and h/2==y:
    print(0.5*h*w,1)
else:
    print(0.5*h*w,0)
Buggy python submission (verdict: Runtime Error):

n,m=map(int,input().split())
a=[True]*n
for i in range(m):
    a[int(input())]=False

mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if a[1]:
    dp[1]=1
else:
    dp[1]=0
for nn in range(2,n):
    if a[nn]:
        dp[nn]=(dp[nn-1]+dp[nn-2])%mod
    else:
        dp[nn]=0
if n>=2:
    dp[n]=(dp[n-1]+dp[n-2])%mod

print(dp[n])


Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
    ai=int(input())
    a.add(ai)


mod=10**9+7

t=[0]*(n+1)
t[0]=1

if 1 in a:
    t[1]=0
else:
    t[1]=1

for i in range(2,n+1):
    if i in a:
        t[i]=0
    else:
        t[i]=(t[i-1]+t[i-2])%mod

print(t[n])

Buggy python submission (verdict: Runtime Error):

n,m=map(int,input().split())
a=[True]*n
for i in range(m):
    a[int(input())]=False

mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if a[1]:
    dp[1]=1
else:
    dp[1]=0
for nn in range(2,n):
    if a[nn]:
        dp[nn]=(dp[nn-1]+dp[nn-2])%mod
    else:
        dp[nn]=0
dp[n]=(dp[n-1]+dp[n-2])%mod

print(dp[n])


Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
    ai=int(input())
    a.add(ai)


mod=10**9+7

t=[0]*(n+1)
t[0]=1

if 1 in a:
    t[1]=0
else:
    t[1]=1

for i in range(2,n+1):
    if i in a:
        t[i]=0
    else:
        t[i]=(t[i-1]+t[i-2])%mod

print(t[n])

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
    a[i]=int(input())

mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if 1 in a:
    dp[1]=0
else:
    dp[1]=1
for nn in range(2,n+1):
    if nn in a:
        dp[nn]=0
#    if nn-1 in a:
    else:
        dp[nn]=(dp[nn-1]+dp[nn-2])%mod

#print(dp)
print(dp[n])


Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
    ai=int(input())
    a.add(ai)


mod=10**9+7

t=[0]*(n+1)
t[0]=1

if 1 in a:
    t[1]=0
else:
    t[1]=1

for i in range(2,n+1):
    if i in a:
        t[i]=0
    else:
        t[i]=(t[i-1]+t[i-2])%mod

print(t[n])

Buggy python submission (verdict: Runtime Error):
def kjou(kkk):
    ka=1
    for km in range(kkk):
        ka=ka*(km+1)    
    return ka

def fcof(ad):
    k=ad//2
    if k==0 :
        return 1
    kcnt=0
    for kk in range(k+1):
        ar=ad-(kk)*2
        dk=kjou(kk+ar)/kjou(kk)/kjou(ar)
        kcnt=kcnt+ dk
        print(ad,k,kk,ar)
    return kcnt       

n,m=map(int,input().split())
n=20
m=2
a1=int(input())
a1=3
icnt=1
for i in range(m):
    a2=int(input())
    a2=11
    ad=a2-a1-1
    if ad<=0:
        print(0)
    fcof1=fcof(ad) 
    icnt=icnt*fcof1
    a1=a2
    print(icnt)

Fixed submission:
n,m=map(int,input().split())
a=set()
for i in range(m):
    ai=int(input())
    a.add(ai)


mod=10**9+7

t=[0]*(n+1)
t[0]=1

if 1 in a:
    t[1]=0
else:
    t[1]=1

for i in range(2,n+1):
    if i in a:
        t[i]=0
    else:
        t[i]=(t[i-1]+t[i-2])%mod

print(t[n])
Buggy python submission (verdict: Runtime Error):

import sys

n,k=map(int,input().split())
v=list(map(int,input().split()))

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))    



Fixed submission:
import sys

n,k0=map(int,input().split())
v=list(map(int,input().split()))

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))
Buggy python submission (verdict: Time Limit Exceeded):
icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(2 ** n):
        total = 0
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                total = total+v[j]-c[j]  # 買い物累計額にも加算
        tmax=max(total,tmax)
    print(tmax)
    

Fixed submission:
icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(n):
        total = 0
        for j in range(n):
            total = total+max(0,v[j]-c[j])   
        tmax=max(tmax,total)
    print(tmax)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left,bisect,bisect_right
import sys

icase=1
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)

Fixed submission:
from bisect import bisect_left,bisect,bisect_right
import sys

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)
Buggy python submission (verdict: Runtime Error):
icase=3
if icase==0:
    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)

kk=1

ix=0
iy=0
iz=0
ss=[]
s=a[ix]+b[iy]+c[iz]

xyz=[]
xyz.append((ix+1,iy,iz))
xyz.append((ix,iy+1,iz))
xyz.append((ix,iy,iz+1))

#print(ix,iy,iz,s)
#print(xyz)
ss.append(s)
while kk<k:
    kk+=1
    s1=0
    for ix,iy,iz in xyz:
        s2=a[ix]+b[iy]+c[iz]
        if s2>s1:
            s1=s2
            ixx,iyy,izz=ix,iy,iz
#    print("1:",ixx,iyy,izz,s2)
    xyz.remove((ixx,iyy,izz))
    if ixx<x-1 and ((ixx+1,iyy,izz) not in xyz): 
        xyz.append((ixx+1,iyy,izz))
    if iyy<y-1 and ((ixx,iyy+1,izz) not in xyz): 
        xyz.append((ixx,iyy+1,izz))
    if izz<z-1 and ((ixx,iyy,izz+1) not in xyz): 
        xyz.append((ixx,iyy,izz+1))
#    print(ixx,iyy,izz,s1)
#    print(xyz)
    ss.append(s1)

for kk in range(k):
    print(ss[kk])        


Fixed submission:
icase=0
if icase==0:
    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)

kk=1

ix=0
iy=0
iz=0
ss=[]
s=a[ix]+b[iy]+c[iz]

xyz=[]
xyz.append((ix+1,iy,iz))
xyz.append((ix,iy+1,iz))
xyz.append((ix,iy,iz+1))

#print(ix,iy,iz,s)
#print(xyz)
ss.append(s)
while kk<k:
    kk+=1
    s1=0
    for ix,iy,iz in xyz:
        s2=a[ix]+b[iy]+c[iz]
        if s2>s1:
            s1=s2
            ixx,iyy,izz=ix,iy,iz
#    print("1:",ixx,iyy,izz,s2)
    xyz.remove((ixx,iyy,izz))
    if ixx<x-1 and ((ixx+1,iyy,izz) not in xyz): 
        xyz.append((ixx+1,iyy,izz))
    if iyy<y-1 and ((ixx,iyy+1,izz) not in xyz): 
        xyz.append((ixx,iyy+1,izz))
    if izz<z-1 and ((ixx,iyy,izz+1) not in xyz): 
        xyz.append((ixx,iyy,izz+1))
#    print(ixx,iyy,izz,s1)
#    print(xyz)
    ss.append(s1)

for kk in range(k):
    print(ss[kk])
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
lr=[[0]*2 for i in range(q)]
for i in range(q):
    lr[i]=list(map(int,input().split()))
    
for lri in lr:
    print(s[lri[0]-1:lri[1]].count("AC"))
    

Fixed submission:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt[i+1]=cnt[i]+1
#    else:
#      cnt[i+1]=cnt[i]

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri]-cnt[li])

Fixed submission:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])

Buggy python submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
cnt=[]
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt.append(1)
    else:
      cnt.append(0)

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
    print(cnt[li-1:ri-1].sum())

Fixed submission:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])

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

Fixed submission:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
ai,bi=map(int,input().split())
a.append(ai)
b.append(bi)
for i in range(1:n):
    ai,bi=map(int,input().split())
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii,ai)
            b.insert(ii,bi)
            break
    if len(a)==i-1:
        a.append(ai)
        b.append(bi)
#print(ai)
msum=0
asum=0
for i in range(n):
    asum=asum+a[i]*b[i]
    msum=msum+b[i]  
    if msum>=m:
        break
asum=asum-a[i]*(msum-m)
print(asum)
        
        


Fixed submission:
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii)=ai
            b.insert(ii)=bi
            break
        else:
            a.append(ai)
            b.append(bi)
print(ai)
  

Fixed submission:
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)
Buggy python submission (verdict: Runtime Error):
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if n==0:
    print(0)
elif none<=nzero:
    print(nall-none*2)
else:
    print(nall-nzero*2)


Fixed submission:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(none*2)
else:
    print(nzero*2)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
si=len(s)//2+1
ns0=len(s)
ssum=0
for i in range(si):
    nsi=len(s)
#    s=s.replace("01","")
#    s=s.replace("10","")
    s=s.replace("01","").replace("10","")
    if nsi==len(s):
        break
print(ns0-nsi)


Fixed submission:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(none*2)
else:
    print(nzero*2)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
si=len(s)//2+1
ns0=len(s)
ssum=0
for i in range(si):
    nsi=len(s)
    s=s.replace("01","")
    s=s.replace("10","")
    if nsi==len(s):
        break
print(ns0-nsi)

Fixed submission:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(none*2)
else:
    print(nzero*2)