Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=[0]*1001
for i in range(1000):
    v=0
    i="000"+str(i)
    for j in s:
        if j==i[-1] and v==2:v+=1
        if j==i[-2] and v==1:v+=1
        if j==i[-3] and v==0:v+=1
    if v==3:ans[int(i)]=1
print(sum(ans))

Fixed submission:
n=int(input())
s=input()
a,b,c=[],[],[]
ans=0
for i in range(n):
  if s[i] not in a:
    a.append(s[i])
    b=[]
    for j in range(i+1,n):
      if s[j] not in b:
        b.append(s[j])
        c=[]
        for k in range(j+1,n):
          if s[k] not in c:
            c.append(s[k])
            ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
a=set()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            b=s[i]+s[j]+s[k]
            a=a|{b}
print(len(a))

Fixed submission:
n=int(input())
s=input()
a,b,c=[],[],[]
ans=0
for i in range(n):
  if s[i] not in a:
    a.append(s[i])
    b=[]
    for j in range(i+1,n):
      if s[j] not in b:
        b.append(s[j])
        c=[]
        for k in range(j+1,n):
          if s[k] not in c:
            c.append(s[k])
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
b=a.pop(0)
if b!=0:print(0);exit()
import collections
d=collections.Counter(a)
e=[[i,j] for i,j in d.items()]
e.sort()
ans=1
d1=[i[0] for i in e]
d2=[i[1] for i in e]
for i,I,j,J in zip(d1,d1[1:],d2,d2[1:]):
    if i+1!=I:
        print(0)
        RE
    ans*=j**J
print(ans) 

Fixed submission:
n,*a=map(int,open(0).read().split())
mod=998244353
d={}
for i in a:
  d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]+1 or b[0][1]!=1:
    ans=0
for i in range(1,len(b)):
    ans*=b[i-1][1]**b[i][1]
    ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x=map(int,input().split())
if x<=a*a*b/2:
    y=b/((b**2+(2*x/(a*b))**2)**0.5)
    print(90-math.degrees(math.acos(y)))
else:
    y=2*(a*a*b-x)/(a*a)
    z=(a*a+2*(a*a*b-x)/(a*a))**0.5
    print(90-math.degrees(math.acos(y/z)))

Fixed submission:
import math
a,b,x=map(int,input().split())
if x<=a*a*b/2:
    h=2*x/a/b
    print(math.degrees(math.atan(b/h)))
else:
    h=2*(a*a*b-x)/a/a
    print(math.degrees(math.atan(h/a)))
Buggy python submission (verdict: Time Limit Exceeded):
n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[k]>=l[i]+l[j]:
                break
            if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
                a+=1
print(a)

Fixed submission:
import bisect
n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]
        a+=max(0,bisect.bisect_left(l,k)-j-1)
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,*l=map(int,open(0).read().split())
print(sum(a<b+c and b<c+a and c<a+b for a,b,c in itertools.combinations(l, 3)))

Fixed submission:
import bisect
n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]
        a+=max(0,bisect.bisect_left(l,k)-j-1)
print(a)
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())
s=s*k
ans=0
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        ans+=1
        s[i]="A"
print(ans)  

Fixed submission:
s=list(input())
k=int(input())
a,b,c=0,0,0
S=s*2
SS=s*3

for i in range(1,len(s)):
    if s[i-1]==s[i]:
        a+=1
        s[i]="A"

for i in range(1,len(S)):
    if S[i-1]==S[i]:
        b+=1
        S[i]="A"
for i in range(1,len(SS)):
    if SS[i-1]==SS[i]:
        c+=1
        SS[i]="A"        

x=a
y=c-a
z=c-b

if k%2==0:
    print(y*((k-2)//2)+x+z)
else:    
    print(y*(k//2)+x)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
from math import *
c=gcd(a,b)
d=0
for i in range(1,c+1):
    if c%i==0:
        c//=i
        d+=+1
print(d)

Fixed submission:
def z(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a,b=map(int,input().split())
A=set(z(a))
B=set(z(b))
c=[i for i in A if i in B]
print(len(c)+1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
a=[int(input())-1 for i in range(q)]
ans=[k-q]*n
for i in range(n):
    ans[i]+=a.count(i)
    print("Yes" if ans[i]>0 else "No")

Fixed submission:
n,k,q=map(int,input().split())
a=[int(input())-1 for i in range(q)]
ans=[k-q]*n
for i in a:
    ans[i]+=1
for i in range(n):
    print("Yes" if ans[i]>0 else "No")
Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    k=heapq.heappop(a)
    print(k)
    heapq.heappush(a,int(k/2))
    print(a)
print(-sum(a))    

Fixed submission:
import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    k=heapq.heappop(a)
    heapq.heappush(a,-(abs(k)//2))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
while m>0:
    b=max(a)
    a.remove(b)
    a.append(b//2)
    m-=1
print(sum(a))   

Fixed submission:
import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    k=heapq.heappop(a)
    heapq.heappush(a,-(abs(k)//2))
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
while m>0:
    a.sort()
    b=a.pop()
    a.append(b//2)
    m-=1
print(sum(a))    

Fixed submission:
import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    k=heapq.heappop(a)
    heapq.heappush(a,-(abs(k)//2))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ans=0
for i in range(1,n):
    ans+=i
print(ans)

Fixed submission:
n=int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
s=input()
a=""
ans=0
i=0
while i<len(s):
    if s[i]==a:
        i+=2
        ans+=1
        a=""
    else:
        i+=1
        ans+=1
        a=s[i]
print(ans)

Fixed submission:
s=input()
n=len(s)
dp=[[0]*2 for _ in range(n)]
dp[0]=[1,0]
# dp[1]=
for i in range(n):
    if i+1<n:
        dp[i+1][0]=max(dp[i+1][1],dp[i][1]+1)
        if s[i]!=s[i+1]:
            dp[i+1][0]=max(dp[i+1][0],dp[i][0]+1)
    if i+2<n:    
        dp[i+2][1]=max(dp[i+2][0],dp[i][0]+1)
        if s[i-1:i+1]!=s[i+1:i+3]:
            dp[i+2][1]=max(dp[i+2][1],dp[i][1]+1)
print(max(dp[-1]))
Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int,input().split())
c=[[] for i in range(m+1)]
for i in range(n):
    a,b=map(int,input().split())
    c[a].append(-b)
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(len(c[i])):
        heapq.heappush(d,c[i][j])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
c=[[] for i in range(m+1)]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        c[a].append(-b)
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(len(c[i])):
        heapq.heappush(d,c[i][j])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)

Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int,input().split())
c=[[] for i in range(pow(10,5))]
for i in range(n):
    a,b=map(int,input().split())
    c[a].append(-b)
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(len(c[i])):
        heapq.heappush(d,c[i][j])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
c=[[] for i in range(m+1)]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        c[a].append(-b)
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(len(c[i])):
        heapq.heappush(d,c[i][j])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,m=map(int,input().split())
c=[]
for i in range(n):
    a,b=map(int,input().split())
    c.append([a,-b])
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(n):
        if c[j][0]==i:
            heapq.heappush(d,c[j][1])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)  

Fixed submission:
import heapq
n,m=map(int,input().split())
c=[[] for i in range(m+1)]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        c[a].append(-b)
d=[]
heapq.heapify(d)
ans=0
for i in range(1,m+1):
    for j in range(len(c[i])):
        heapq.heappush(d,c[i][j])
    if d!=[]:
        ans+=heapq.heappop(d) 
print(-ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for _ in range(n)]
b=max(a)
for i in range(n):
    if a[i]!=b:
        print(b)
    else:
        
        print(sorted(a)[-2])

Fixed submission:
n=int(input())
a=[int(input()) for _ in range(n)]
b=sorted(a)
ans=[b[-1]]*n
ans[a.index(b[-1])]=b[-2]
print(*ans,sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
a=[i%2019 for i in range(l,r+1)]
set(a)
ans=2018
for i in a:
    for j in a:
        if i!=j:
            ans=min(ans,(i*j)%2019)
print(ans)

Fixed submission:
l,r=map(int,input().split())
a=[i%2019 for i in range(l,min(r+1,l+2020))]
ans=2018
for i in a:
    for j in a:
        if i!=j:
            ans=min(ans,(i*j)%2019)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
import math
e=(c*d)//math.gcd(c,d)
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Fixed submission:
a,b,c,d=map(int,input().split())
import fractions
e=(c*d)//fractions.gcd(c,d)
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
import math
def lcm(x,y):
    return(x*y)//math.gcd(x,y)
e=lcm(c,d)    
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Fixed submission:
a,b,c,d=map(int,input().split())
import fractions
e=(c*d)//fractions.gcd(c,d)
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
e=lcm(c,d)    
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Fixed submission:
a,b,c,d=map(int,input().split())
import fractions
e=(c*d)//fractions.gcd(c,d)
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
for i in range(n):
    if b[i][0]<sum(c[:i+1]):
        ans="No"
        break
print(ans)

Fixed submission:
n=int(input())
# a=[[0]*2]*n
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
d=0
for i in range(n):
    d+=c[i]
    if b[i][0]<d:
        ans="No"
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
for i in range(n):
    if b[i][0]<sum(c[:i+1]):
        ans="No"
print(ans)

Fixed submission:
n=int(input())
# a=[[0]*2]*n
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
d=0
for i in range(n):
    d+=c[i]
    if b[i][0]<d:
        ans="No"
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(d.values()))

Fixed submission:
(n,),*a=[[*map(int,i.split())]for i in open(0)]
d={}
for i,j in a:
    for x,y in a:
        if i!=x or j!=y:
            d[(i-x,j-y)]=d.get((i-x,j-y),0)+1
print(n-max(list(d.values())+[0]))
Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*abs(a[0]))
if n==2:
    print(a[1]-1[0])
    print(a[1],a[0])
else:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
if a[0]>0:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])
elif a[-1]<0:
    for i in a[:-1]:
        print(a[-1],i)
        a[-1]-=i
else:
    for i in a[1:-1]:
        if i<0:
            print(a[-1],i)
            a[-1]-=i
        else:
            print(a[0],i)
            a[0]-=i
    print(a[-1],a[0])

Buggy python submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
a.sort()
p,z,m=[],[],[]
for i in a:
    if i<0:m+=[i]
    elif i>0:p+=[i]
    else:z+=[i]
if p and m:
    p=z+p
    for i in p[:-1]:
        # print(m[0],i)
        m[0]-=i
    for i in m:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
elif p:
    p=z+p
    for i in p[:-2]:
        # print(p[0],i)
        p[0]-=i
    print(p[-2]-p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
if p and m:
    p=z+p
    for i in p[:-1]:
        print(m[0],i)
        m[0]-=i
    for i in m:
        print(p[-1],i)
        p[-1]-=i
elif p:
    p=z+p
    for i in p[:-2]:
        print(p[0],i)
        p[0]-=i
    print(p[-2],p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        print(p[-1],i)
        p[-1]-=i

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
if a[0]>0:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])
elif a[-1]<0:
    for i in a[:-1]:
        print(a[-1],i)
        a[-1]-=i
else:
    for i in a[1:-1]:
        if i<0:
            print(a[-1],i)
            a[-1]-=i
        else:
            print(a[0],i)
            a[0]-=i
    print(a[-1],a[0])

Buggy python submission (verdict: Runtime Error):
if p and m:
    p=z+p
    for i in p[:-1]:
        print(m[0],i)
        m[0]-=i
    for i in m:
        print(p[-1],i)
        p[-1]-=i
elif p:
    p=z+p
    for i in p[:-2]:
        print(p[0],i)
        p[0]-=i
    print(p[-2],p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        print(p[-1],i)
        p[-1]-=i

Fixed submission:
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
if a[0]>0:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])
elif a[-1]<0:
    for i in a[:-1]:
        print(a[-1],i)
        a[-1]-=i
else:
    for i in a[1:-1]:
        if i<0:
            print(a[-1],i)
            a[-1]-=i
        else:
            print(a[0],i)
            a[0]-=i
    print(a[-1],a[0])
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=[input() for i in range(n)]
ans=sum([s[i].count("AB") for i in range(n)])
a=[s[i].count("AB") for i in range(n)]
xxA=sum([1 if s[i][0]!="B" and s[i][-1]=="A"else 0 for i in range(n)])
Bxx=sum([1 if s[i][0]=="B" and s[i][-1]!="A" else 0 for i in range(n)])
BxA=sum([1 if s[i][0]=="B" and s[i][-1]=="A" else 0 for i in range(n)])
if abs(xxA-Bxx)>BxA:
    wer=min(xxA,Bxx)+BxA+1
else:
    wer=min(xxA,Bxx)+BxA
print(ans+wer)

Fixed submission:
n,k=map(int, input().split())
print(n-k+1)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=map(int, input().split())
ans=0
for i in range(N//R+1):
    for j in range((N-i*R)//G+1):
        for k in range((N-i*R-j*G)//B+1):
            if (i*R+j*G+k*B)==N:
                ans +=1
print(ans) 

Fixed submission:
R,G,B,N=map(int, input().split())
ans=0
for i in range(N//R+1):
    for j in range((N-i*R)//G+1):
        if (N-i*R-j*G)%B==0:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":a+=[a[-1]+1]
    else:a+=[a[-1]]
print(min(i-a[i]*2+s.count(".") for i in range(n+1)))

Fixed submission:
ans=n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":
        a+=[a[-1]+1]
    else:
        a+=[a[-1]]
w=s.count(".")
for i in range(n+1):
    ans=min(ans,i-a[i]+w-a[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
print(min(s[s.index("#"):].count("."),s[:-1].count("#")))

Fixed submission:
ans=n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":
        a+=[a[-1]+1]
    else:
        a+=[a[-1]]
w=s.count(".")
for i in range(n+1):
    ans=min(ans,i-a[i]+w-a[i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    t=s[l-1:r]
    print(sum(t[j:j+2]=="AC" for j in range(r-l)))

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*len(s)
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]+0
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int, input().split())
s=input()
t=s.replace("AC","11")
u=[0 if i!="1" else 1 for i in t]
for i in range(q):
    l,r=map(int, input().split())
    ans=sum(u[l-1:r])
    if s[l-1]=="C" and s[r-1]=="A":
        print(ans//2-1)
    else:
        print(ans//2)

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*len(s)
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]+0
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

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

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*len(s)
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]+0
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

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

Fixed submission:
n,q=map(int,input().split())
s=input()
t=[0]*len(s)
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        t[i+1]=t[i]+1
    else:
        t[i+1]=t[i]+0
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
ans=[]
for i in range(1,max(a,b)):
    if a%i==0 and b%i==0:
        ans.append(i)
print(ans[-k])

Fixed submission:
a,b,k=map(int, input().split())
ans=[]
for i in range(max(a,b)):
    if a%(i+1)==0 and b%(i+1)==0:
        ans.append(i+1)
print(ans[-k])
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[i-1 if i>0 else 0 for i in h]
        sum+=1
        # print(h,1)
    else:
        count0=[i for i, j in enumerate(h) if j==0]
        a=count0.copy() #copy()をつけないとaを変えるとcount0も変わる
        b=count0.copy()
        a.pop(0)
        b.pop(-1)
        c=[x-y for(x,y) in zip(a,b)]#a-bが要素のリストを作る
        sum = sum + len(c)-c.count(1)
        # print(count0)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
            # print(1)
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
            # print(2)
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
        # print(h,2)
print(sum)                
                

Fixed submission:
a,b,c=sorted(map(int, input().split()))
print(a*b//2)
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[i-1 if i>0 else 0 for i in h]
        sum+=1
    else:
        count0=[i for i, j in enumerate(h) if j==0]
        a=count0.copy() #copy()をつけないとaを変えるとcount0も変わる
        b=count0.copy()
        del a[0]
        del b[-1]
        c=[x-y for(x,y) in zip(a,b)]　#a-bが要素のリストを作る
        sum = sum + len(c)-c.count(1)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
print(sum)   

Fixed submission:
n=int(input())
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
    if 0 not in h:
        h=[X-1 if X>0 else 0 for X in h]
        sum+=1
        # print(h,1)
    else:
        count0=[Y for Y, Z in enumerate(h) if Z==0]
        a=count0.copy()
        b=count0.copy()
        del a[0]
        del b[-1]
        c=[x-y for(x,y) in zip(a,b)]
        sum = sum + len(c)-c.count(1)
        if count0[0]>0 and count0[-1]<n-1:
            sum +=2
        elif count0[0]>0 or count0[-1]<n-1:
            sum +=1
        else:
            sum +=0
        h=[i-1 if i>0 else 0 for i in h]
print(sum)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
dp=[10**9]*n
dp[0]=0
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
    for j in range(max(0,i-k),i):
        dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i])
print(dp[-1])


Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
memo=[-1]*(n+1)
def flog(n):
    if n<=0:
        memo[n]=0
        return 0
    if memo[n]!=-1:
        return memo[n]
    else:
        memo[n]=min(flog(n-1)+abs(h[n]-h[n-1]),flog(n-2)+abs(h[n]-h[n-2]))
        return memo[n]
print(flog(n-1))   


Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=[int(i) for i in input().split()]
memo=[-1]*(n+1)
def flog(n):
    if n<=0:
        memo[0]=0
        return 0
    if n==1:
        memo[1]=abs(h[0]-h[1])
        return memo[n]
    if memo[n]!=-1:
        return memo[n]
    else:
        memo[n]=min(flog(n-1)+abs(h[n]-h[n-1]),flog(n-2)+abs(h[n]-h[n-2]))
        return memo[n]
print(flog(n-1))

Fixed submission:
n=int(input())
h=[int(i) for i in input().split()]
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
dp=[0]*(W+1)
for i in range(N):
    w,v=map(int,input().split())
    for j in range(W,w-1,-1):
        dp[j]=max(dp[j],dp[j-w]+v)
print(dp[-1])

Fixed submission:
from numpy import *
N,W=map(int,input().split())
dp=zeros(W+1,dtype=int)
for i in range(N):
    w,v=map(int,input().split())
    dp[w:]=maximum(dp[:W-w+1]+v,dp[w:])
print(dp[-1])