Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h,w,k=map(int,input().split())
S=[input() for i in range(h)]

LIS=[]

def saiki(x,st):
    if x==h-1:
        LIS.append(st)
        return
    else:
        saiki(x+1,st+st[-1])
        saiki(x+1,st+str(int(st[-1])+1))

saiki(0,"0")

DIC1={c:0 for c in "0123456789"}
DIC2={c:0 for c in "0123456789"}
ans=10**9
for cod in LIS:
    for ele in DIC1:
        DIC1[ele]=0
    cnt=int(cod[-1])
    end=False
    for i in range(w):
        for ele in DIC2:
            DIC2[ele]=0
        for q in range(h):
            if S[q][i]=="1":
                DIC2[cod[q]]+=1
        if max(DIC2.values())>k:
            end=True
            break
        flg=True
        for ele in DIC1:
            if DIC1[ele]+DIC2[ele]>k:
                flg=False
                break
        if flg:
            for ele in DIC1:
                DIC1[ele]+=DIC2[ele]
        else:
            for ele in DIC1:
                DIC1[ele]=DIC2[ele]
            cnt+=1
    if end:
        continue
    ans=min(ans,cnt)
    #print(cod,cnt)
print(ans)


Fixed submission:
h,w,k=map(int,input().split())
S=[input() for i in range(h)]

LIS=[]

def saiki(x,st):
    if x==h-1:
        LIS.append(st)
        return
    else:
        saiki(x+1,st+st[-1])
        saiki(x+1,st+str(int(st[-1])+1))

saiki(0,"0")

DIC1={c:0 for c in "0123456789"}
DIC2={c:0 for c in "0123456789"}
ans=10**9
for cod in LIS:
    for ele in DIC1:
        DIC1[ele]=0
    cnt=int(cod[-1])
    end=False
    for i in range(w):
        for ele in DIC2:
            DIC2[ele]=0
        for q in range(h):
            if S[q][i]=="1":
                DIC2[cod[q]]+=1
        if max(DIC2.values())>k:
            end=True
            break
        flg=True
        for ele in DIC1:
            if DIC1[ele]+DIC2[ele]>k:
                flg=False
                break
        if flg:
            for ele in DIC1:
                DIC1[ele]+=DIC2[ele]
        else:
            for ele in DIC1:
                DIC1[ele]=DIC2[ele]
            cnt+=1
    if end:
        continue
    ans=min(ans,cnt)
    #print(cod,cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=int(input())
  #while s%10==0:
  #    s//=10
  #s=9**800000
  s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
  s=input()
  #while s%10==0:
  #    s//=10
  #s=9**100
  #s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=int(input())
  #while s%10==0:
  #    s//=10
  s=9**800000
  s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
  s=input()
  #while s%10==0:
  #    s//=10
  #s=9**100
  #s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
while s%10==0:
    s//=10
s=str(s)
lens=len(s)

dp=[[0,0] for i in range(lens)]

dp[0][0]=int(s[0])
dp[0][1]=11-int(s[0])

for i in range(1,lens):
    dp[i][0]=min(dp[i-1][0]+int(s[i]),dp[i-1][1]+int(s[i]))
    dp[i][1]=min(dp[i-1][0]+11-int(s[i]),dp[i-1][1]+9-int(s[i]))

print(min(dp[-1]))

Fixed submission:
def main():
  s=input()
  #while s%10==0:
  #    s//=10
  #s=9**100
  #s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
while s%10==0:
    s//=10
s=str(s)
lens=len(s)

dp=[[0,0] for i in range(lens)]

dp[0][0]=int(s[0])
dp[0][1]=11-int(s[0])

for i in range(1,lens):
    dp[i][0]=min(dp[i-1][0]+int(s[i]),dp[i-1][1]+int(s[i]))
    dp[i][1]=min(dp[i-1][0]+11-int(s[i]),dp[i-1][1]+9-int(s[i]))

print(min(dp[-1]))

Fixed submission:
def main():
  s=input()
  #while s%10==0:
  #    s//=10
  #s=9**100
  #s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

L.sort()

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])    
    


Fixed submission:
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])

Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])    
    

Fixed submission:
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7

ans=0
cnt=[0 for i in range(61)]

for i in range(n):
    now=A[i]
    bek=1
    for q in range(61):
        if now&1==0:
            ans+=cnt[q]*bek
        else:
            ans+=(i-cnt[q])*bek
        bek<<=1
        cnt[q]+=now&1
        now>>=1
    ans=ans%mod
    #print(ans)
print(ans)

Fixed submission:
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7

ans=0
cnt=[0 for i in range(61)]

for i in range(n):
    now=A[i]
    bek=1
    for q in range(61):
        if now&1==0:
            ans+=cnt[q]*bek
        else:
            ans+=(i-cnt[q])*bek
        bek=bek*2%mod
        cnt[q]+=now&1
        now>>=1
    ans=ans%mod
    #print(ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=input()

ans=0
import itertools
itr=itertools.product(list("1234567890"),repeat=3)

for it in itr:
    cnt=0
    for i in range(n):
        if S[i]==it[cnt]:
            cnt+=1
        if cnt==3:
            ans+=1
            break

print(ans)

Fixed submission:
n=int(input())
S=input()

ans=0
import itertools
itr=itertools.product(list("1234567890"),repeat=3)

for it in itr:
    cnt=0
    for i in range(n):
        if S[i]==it[cnt]:
            cnt+=1
        if cnt==3:
            ans+=1
            break

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())

ans={}
inp_list=[]
G=[0 for i in range(n+1)]
T=[[] for i in range(n+1)]
for i in range(n-1):
    #print(G)
    a,b=map(int,input().split())
    inp_list.append((a,b))
    T[a].append(b)
    T[b].append(a)

L=[len(ppp) for ppp in T]
mod=max(L)

def addd(x,mod):
    x+=1
    if x==mod+1:
        x=1
    return x

def tansa(now,color):
    #print(T)
    now_col=color
    for i in T[now]:
        if G[i]==0:
            if now_col==color:
                now_col=addd(now_col,mod)
            G[i]==now_col
            ans[(now,i)]=now_col
            T[i].remove(now)
            tansa(i,now_col)
            now_col=addd(now_col,mod)


tansa(1,0)

print(mod)

for i in range(n-1):
    print(ans[inp_list[i]])

Fixed submission:
import sys

sys.setrecursionlimit(100000)

n=int(input())

ans={}
inp_list=[]
G=[0 for i in range(n+1)]
T=[[] for i in range(n+1)]
for i in range(n-1):
    #print(G)
    a,b=map(int,input().split())
    inp_list.append((a,b))
    T[a].append(b)
    T[b].append(a)

L=[len(ppp) for ppp in T]
mod=max(L)

def addd(x,mod):
    x+=1
    if x==mod+1:
        x=1
    return x

def tansa(now,color):
    #print(T)
    now_col=color
    for i in T[now]:
        if G[i]==0:
            if now_col==color:
                now_col=addd(now_col,mod)
            G[i]==now_col
            ans[(now,i)]=now_col
            T[i].remove(now)
            tansa(i,now_col)
            now_col=addd(now_col,mod)


tansa(1,0)

print(mod)

for i in range(n-1):
    print(ans[inp_list[i]])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=[int(i) for i in input().split()]

A.sort()
#print(A)
for i in range(m):
    A[-1]=A[-1]//2
    if A[-1]<A[-2]:
        A.sort()
    #print(A)
print(sum(A))

Fixed submission:
n,m=map(int,input().split())
A=[int(i) for i in input().split()]

A.sort()
A.reverse()
#print(A)
if n==1:
    ans=A[0]//(2**m)
    print(ans)
else:
    A.append(0)
    big=A[0]
    stc=0
    now=0
    while m>0:
        A[now]=A[now]//2
        m-=1
        big=A[0]
        for i in range(n-1):
            if A[i+1]>=big and m>0:
                A[i+1]=A[i+1]//2
                m-=1
            else:
                A.sort()
                A.reverse()
                break
        #print(A)
    else:
        print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

def ZA(n,s):
    Z=[0 for i in range(n)]
    Z[0]=n
    i=1
    j=0
    cand=0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        Z[i]=j
        cand=max(cand,min(Z[i],i))
        if j==0:
            i+=1
            continue
        k=1
        while k<j and k+Z[k]<j:
            Z[i+k]=Z[k]
            cand=max(cand,min(Z[i],i))
            k+=1
        i+=k
        j-=k
    #print(Z)
    return cand


ans=0
for i in range(n):
    ans=max(ans,ZA(n-i,s[i:]))
print(ans)

Fixed submission:
n=int(input())
s=input()

def ZA(n,s):
    Z=[0 for i in range(n)]
    Z[0]=n
    i=1
    j=0
    cand=0
    while i<n:
        while i+j<n and s[j]==s[i+j]:
            j+=1
        Z[i]=j
        cand=max(cand,min(Z[i],i))
        if j==0:
            i+=1
            continue
        k=1
        while k<j and k+Z[k]<j:
            Z[i+k]=Z[k]
            cand=max(cand,min(Z[i],i))
            k+=1
        i+=k
        j-=k
    #print(Z)
    return cand


ans=0
for i in range(n):
    ans=max(ans,ZA(n-i,s[i:]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L={}

for i in range(n):
    a,b=map(int,input().split())
    if a in L:
        L[a].append(b)
    else:
        L[a]=[b]

ans=0
tab=[0 for i in range(m)]
for i in range(m):
    if i+1 in L:
        tab.extend(L[i+1])
    tab.sort()
    ans+=tab.pop(-1)

print(ans)
    

Fixed submission:
import heapq
import queue

n,m=map(int,input().split())
L=[]
for inp in range(n):
    a,b=map(int,input().split())
    L.append((a,b))
L.sort(reverse=True)

pq=[]
heapq.heapify(pq)

    
ans=0
for i in range(1,m+1):
    while len(L)>0 and L[-1][0]==i:
        heapq.heappush(pq,L.pop()[1]*-1)
    #print(pq)
    if len(pq)==0:
        continue
    else:    
        ans-=heapq.heappop(pq)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L={}

for i in range(n):
    a,b=map(int,input().split())
    if a in L:
        L[a].append(b)
    else:
        L[a]=[b]

ans=0
tab=[0 for i in range(m)]
for i in range(m):
    if i+1 in L:
        tab.extend(L[i+1])
    tmax=max(tab)
    ans+=tmax
    tab.remove(tmax)

print(ans)
    

Fixed submission:
import heapq
import queue

n,m=map(int,input().split())
L=[]
for inp in range(n):
    a,b=map(int,input().split())
    L.append((a,b))
L.sort(reverse=True)

pq=[]
heapq.heapify(pq)

    
ans=0
for i in range(1,m+1):
    while len(L)>0 and L[-1][0]==i:
        heapq.heappush(pq,L.pop()[1]*-1)
    #print(pq)
    if len(pq)==0:
        continue
    else:    
        ans-=heapq.heappop(pq)

print(ans)
Buggy python submission (verdict: Runtime Error):
N=input()
lenN=len(N)
ans=0


for i in range(1,lenN,2):
    ans+=10**i*9//10
    #print(ans)

if lenN%2==1:
    ans+=int(N[1:])+1
    
print(ans)
    
    


#0をひかない

Fixed submission:
N=input()
lenN=len(N)
ans=0

for i in range(1,int(N)+1):
    if len(str((i)))%2==1:
        ans+=1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=int(input())
import math
sq=math.ceil(math.sqrt(s))

big=sq**2
sma=big-s

for i in range(math.floor(math.sqrt(big)),big+1):
    if big%i==0:
        big1=i
        big2=big//i
        break

#print(big1,big2)

if sma!= 0:
    
    for i in range(math.floor(math.sqrt(sma)),sma+1):
        if sma%i==0:
            sma1=i
            sma2=sma//i
            break
else:
    sma1=0
    sma2=0
#print(sma1,sma2)

x1=big1
y1=sma1
x2=sma2
y2=big2
x3=0
y3=0

print(x1,y1,x2,y2,x3,y3)

Fixed submission:
s=int(input())
import math
sq=math.ceil(math.sqrt(s))

big=sq**2
sma=big-s

for i in range(math.floor(math.sqrt(big)),big+1):
    if big%i==0:
        big1=i
        big2=big//i
        break

#print(big1,big2)


if sma!= 0:
    
    for i in range(math.floor(math.sqrt(sma)),0,-1):
        if sma%i==0:
            sma1=i
            sma2=sma//i
            break
else:
    sma1=0
    sma2=0
#print(sma1,sma2)

x1=big1
y1=sma1
x2=sma2
y2=big2
x3=0
y3=0

print(x1,y1,x2,y2,x3,y3)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
L=[[] for i in range(n+1)]

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
C=[k for i in range(n+1)]
V=[0 for i in range(n+1)]
mod=1_000_000_007
ans=1
que=[1]
V[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    ans=ans*C[now]%mod
    for nex in L[now]:
        if V[nex]==0:
            V[nex]=1
            que.append(nex)
        for nexnex in L[nex]:
            C[nexnex]-=1
        C[nex]-=1

print(ans)


Fixed submission:
n,k=map(int,input().split())
L=[[] for i in range(n+1)]

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
C=[k for i in range(n+1)]
V=[0 for i in range(n+1)]
mod=1_000_000_007
ans=1
que=[(1,0)]
V[1]=1
head=0

cnt=1
while len(que)>head:
    now=que[head]
    head+=1
    ans=ans*(k-now[1])%mod
    for i in range(len(L[now[0]])):
        nex=L[now[0]][i]
        if V[nex]==0:
            V[nex]=1
            que.append((nex,cnt))
            cnt+=1
    cnt=2

#ans=ans*pow(k-1,mod-2,mod)*k%mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
L=[[] for i in range(n+1)]

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
C=[k for i in range(n+1)]
V=[0 for i in range(n+1)]
mod=1_000_000_007
ans=1
que=[1]
V[1]=1
head=0

while len(que)>head:
    now=que[head]
    head+=1
    ans=ans*C[now]%mod
    for nex in L[now]:
        if V[nex]==0:
            V[nex]=1
            que.append(nex)
        for nexnex in L[nex]:
            C[nexnex]-=1
        C[nex]-=1

print(ans)

Fixed submission:
n,k=map(int,input().split())
L=[[] for i in range(n+1)]

for i in range(n-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
C=[k for i in range(n+1)]
V=[0 for i in range(n+1)]
mod=1_000_000_007
ans=1
que=[(1,0)]
V[1]=1
head=0

cnt=1
while len(que)>head:
    now=que[head]
    head+=1
    ans=ans*(k-now[1])%mod
    for i in range(len(L[now[0]])):
        nex=L[now[0]][i]
        if V[nex]==0:
            V[nex]=1
            que.append((nex,cnt))
            cnt+=1
    cnt=2

#ans=ans*pow(k-1,mod-2,mod)*k%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

import math

def boxball(box,ball):
    cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
    return cal%1000000007

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
        return cal%1000000007

#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)

Fixed submission:
n,k=map(int,input().split())

import math

def boxball(box,ball):
    if ball>=box:
        cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
        return cal%1000000007
    else:
        return 0

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        if ball>=box-2:
            cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
            return cal%1000000007
        else:
            return 0
#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())

import math

def boxball(box,ball):
    cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
    return cal%1000000007

def redball(box,ball):
    cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
    return cal%1000000007

#print(boxball(3,5),redball(3,5))

for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k)
    print(ans%1000000007)

Fixed submission:
n,k=map(int,input().split())

import math

def boxball(box,ball):
    if ball>=box:
        cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
        return cal%1000000007
    else:
        return 0

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        if ball>=box-2:
            cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
            return cal%1000000007
        else:
            return 0
#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
L=[int(i) for i in input().split()]

sumL=[None for i in range(n)]
sumL[0] = L[0]
for i in range(len(L)-1):
    sumL[i+1] = sumL[i] + L[i+1]

res=0

step=0
lenL=len(sumL)

for q in range(lenL):
    step=0
    for nums in sumL:
        step+=1
        if nums>=k:
            #print(len(sumL)-step+1)
            res+=lenL-step+1
            break
    else:
        break
    #print(sumL)
    sumL=sumL[step-1:]
    #print(sumL)
    lenL-=step-1
    k+=L[q]
    
    
    
print(res)


Fixed submission:
L=[i for i in input().split()]
x=L[0]
a=L[1]
if x<a:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Time Limit Exceeded):
import re
s=input()
s=re.sub("AC|BB|[^ABC][^ABC]|AX|BX|XB|XC","X",s)
s=re.sub("XX*","X",s)
#print(s)
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
    lastA=s.rfind("A")
    topA=s.find("A")
    topC=s.find("C")
    #print(s,lastA)
    #print(s[lastA:(lastA + 3)])
    if not s[lastA:(lastA + 3)] == "ABC":
        s=s[:lastA]
    s=s[topA:]
    
    s=re.sub("AC|BB|[^ABC][^ABC]|AX|BX|XB|XC","X",s)
    s=re.sub("XX*","X",s)
    #print(s)
print(c)

Fixed submission:
s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re
s=input()
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
    lastA=s.rfind("A")
    #print(s,lastA)
    #print(s[lastA:(lastA + 3)])
    if not s[lastA:(lastA + 3)] == "ABC":
        s=s[:lastA]
    #print(s)
print(c)

Fixed submission:
s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import re
s=input()
c=0
while "ABC" in s:
    t=re.subn("ABC","BCA",s)
    s=t[0]
    c+=t[1]
print(c)


Fixed submission:
s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
c=0
while "ABC" in s:
    s=s.replace("ABC","BCA",1)
    c+=1
print(c)

Fixed submission:
s=input()
i=1
new=[s[0]]
while i<len(s):
    if s[i]=="C" and s[i-1] == "B":
        new.pop()
        new.append("K")
    else:
        new.append(s[i])
    i+=1

cnt=0
ans=0
for i in range(len(new)-1,-1,-1):
    if new[i]=="A" and cnt > 0:
        ans+=cnt
    elif new[i]=="K":
        cnt+=1
    else:
        cnt=0
    
print(ans)
Buggy python submission (verdict: Runtime Error):
t,x=map(int,input().split)
print(t/x)

Fixed submission:
inp=list(map(int,input().split()))
print(inp[0]/inp[1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
H=[int(i) for i in input().split()]
H.append(0)
import math
dp=[math.inf for i in range(n+2)]
dp[0]=0

for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
    dp[i+2]=min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))

print(dp[n-1])

Fixed submission:
n=int(input())
H=[int(i) for i in input().split()]
H.append(0)
import math
dp=[1e10 for i in range(n+2)]
dp[0]=0

for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
    dp[i+2]=min(dp[i+2],dp[i]+abs(H[i+2]-H[i]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=[int(i) for i in input().split()]
H.extend([0 for i in range(k+1)])

dp=[1e10 for i in range(n+1)]
dp.extend([0 for i in range(k+1)])
dp[0]=0

for i in range(n-1):
    for q in range(1,k+1):
        dp[i+q]=min(dp[i+q],dp[i]+abs(H[i+q]-H[i]))
   

print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
H=[int(i) for i in input().split()]
H.extend([0 for i in range(k+1)])

dp=[1e10 for i in range(n+1)]
dp.extend([0 for i in range(k+1)])
dp[0]=0

for i in range(n-1):
    for q in range(1,k+1):
        dp[i+q]=min(dp[i+q],dp[i]+abs(H[i+q]-H[i]))
   

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W.append(a)
    V.append(b)

dp=[0 for i in range(w+1)]
for q in range(n):
    bq=q
    for i in range(w):
        bi=w-i-1
        if bi+W[bq]<=w:
            dp[bi+W[bq]]=max(dp[bi]+V[bq],dp[bi+W[bq]])
    #print(dp)

print(dp[-1])

Fixed submission:
n,w=map(int,input().split())
W=[]
V=[]
for i in range(n):
    a,b=map(int,input().split())
    W.append(a)
    V.append(b)

dp=[0 for i in range(w+1)]
for q in range(n):
    bq=q
    for i in range(w):
        bi=w-i-1
        if bi+W[bq]<=w:
            dp[bi+W[bq]]=max(dp[bi]+V[bq],dp[bi+W[bq]])
    #print(dp)

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
tab=[0 for i in range(n+1)]
for num in A:
    tab[num]+=1
tab.sort(reverse=True)
print(n-10 sum(tab[:k]))

Fixed submission:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
tab=[0 for i in range(n+1)]
for num in A:
    tab[num]+=1
tab.sort(reverse=True)
print(n-sum(tab[:k]))