Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03165 (python)

Fixed submission:
s=input()
N=len(s)
t=input()
M=len(t)

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
def al(str):
    return alphabetlist.index(str)+1

dp=[[0 for i in range(0,M+1)] for i in range(0,N+1)]

for i in range(0,N):
    for j in range(0,M):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            if dp[i+1][j]>dp[i][j+1]:
                dp[i+1][j+1]=dp[i+1][j]
            else:
                dp[i+1][j+1]=dp[i][j+1]

ans=[]
i=N
j=M
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans.append(s[i-1])
        i-=1
        j-=1

ans=ans[::-1]
print(''.join(ans))

Buggy submission (verdict: Runtime Error):
s=input()
N=len(s)
t=input()
M=len(t)

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
def al(str):
    return alphabetlist.index(str)+1

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

firsts=N
for i in range(0,N):
    if s[i]==t[0]:
        firsts=i
        break

firstt=M
for i in range(0,M):
    if t[i]==s[0]:
        firstt=i
        break

for i in range(0,N):
    if i>=firsts:
        dp[i][0]=1

for i in range(0,M):
    if i>=firstt:
        dp[0][i]=1

for i in range(1,N):
    for j in range(1,M):
        if s[i]==t[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            if dp[i][j-1]>dp[i-1][j]:
                dp[i][j]=dp[i][j-1]
            else:
                dp[i][j]=dp[i-1][j]

ans=[]
i=N-1
j=M-1
while i>-1:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    else:
        while s[i]==t[j]:
            j-=1
        ans.append(s[i])
        i-=1
        
ans=ans[::-1]
print(''.join(ans))

Buggy submission (verdict: Runtime Error):
import copy,bisect

s=input()
N=len(s)
t=input()
M=len(t)

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

for i in range(0,N):
    if s[0:i+1].count(t[0])>0:
        dp[i][0]=1

for i in range(0,M):
    if t[0:i+1].count(s[0])>0:
        dp[0][i]=1

for i in range(1,N):
    for j in range(1,M):
        if s[i]==t[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            if dp[i][j-1])>dp[i-1][j]:
                dp[i][j]=dp[i][j-1]
            else:
                dp[i][j]=dp[i-1][j]

print(dp[N-1][M-1])

Buggy submission (verdict: Runtime Error):
import copy,bisect

s=input()
N=len(s)
t=input()
M=len(t)

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

for i in range(0,N):
    if s[0:i+1].count(t[0])>0:
        dp[i][0]=1

for i in range(0,M):
    if t[0:i+1].count(s[0])>0:
        dp[0][i]=1

for i in range(1,N):
    for j in range(1,M):
        if s[i]==t[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            if len(dp[i][j-1])>len(dp[i-1][j]):
                dp[i][j]=dp[i][j-1]
            else:
                dp[i][j]=dp[i-1][j]

print(dp[N-1][M-1])
Problem p03182 (python)

Fixed submission:
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
interval=[[] for i in range(0,N)]
for i in range(0,M):
    l,r,a=map(int,input().split())
    interval[l-1].append((r-1,a))

# N: 処理する区間の長さ
INF = 10**30-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

Max=[0 for i in range(0,N)]
for i in range(N-1,-1,-1):
    for j in range(0,len(interval[i])):
        r,a=interval[i][j]
        update(i,r+1,-a)
    Max[i]=max(-query(0,N),0)
    if i>0:
        update(i-1,i,-Max[i])

print(Max[0])

Buggy submission (verdict: Runtime Error):
import sys

input=sys.stdin.readline

N,M=map(int,input().split())
interval=[[] for i in range(0,N)]
for i in range(0,M):
    l,r,a=map(int,input().split())
    interval[l-1].append((r-1,a))

#A1 ... AnのBIT(1-indexed)
n=N+1
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

Max=[0 for i in range(0,N+2)]
for i in range(N,0,-1):
    for j in range(0,len(interval[i])):
        r,a=interval[i][j]
        BIT_update(i,a)
        BIT_update(r+1,-a)
    Max[i]=max(BIT_query(j) for j in range(1,N+1))
    if i>1:
        BIT_update(i-1,Max[i])
        BIT_update(i,-Max[i])

print(Max[1])
Problem p03233 (python)

Fixed submission:
import sys,random

input=sys.stdin.readline

N=int(input())
A=[-1]*N;B=[-1]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

ans=min(sum(A),sum(B))

temp=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)]
temp.sort()
#print(temp)
data=[0]*N
for i in range(N):
    val,id=temp[i]
    data[id]+=1
S=sum(temp[i][0] for i in range(N))

for i in range(N):
    if data[i]==2:
        test=S
        ans=min(ans,test)
    elif data[i]==1:
        if temp[N-1][1]!=i:
            test=S+max(A[i],B[i])-temp[N-1][0]
        else:
            test=S+max(A[i],B[i])-temp[N-2][0]
        ans=min(ans,test)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input=sys.stdin.readline

N=int(input())
A=[-1]*N;B=[-1]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())

ans=min(sum(A),sum(B))

temp=[(A[i],i) for i in range(N)]+[(B[i],i) for i in range(N)]
temp.sort()
data=[0]*N
for i in range(N):
    val,id=temp[i]
    data[id]+=1
S=sum(temp[i][0] for i in range(N))

for i in range(N):
    if data[i]==2:
        test=S
    elif data[i]==1:
        if temp[N-1][1]!=i:
            test=S+max(A[i],B[i])-temp[N-1][0]
        else:
            test=S+max(A[i],B[i])-temp[N-2][0]
    ans=min(test,ans)

print(ans)
Problem p03241 (python)

Fixed submission:
import math

N,M=map(int,input().split())

d=[]
i=1
while math.sqrt(M)>=i:
    if M%i==0:
        d.append(i)
        if i**2!=M:
            d.append(M//i)
    i=i+1
d.sort()#Mの約数列

m=0
i=0
while  len(d)-1>=i and M//N>=d[i]:
    if  M%d[i]==0:
        m=d[i]
    i=i+1
print(m)

Buggy submission (verdict: Runtime Error):
import math

N,M=map(int,input().split())

d=[]
i=1
while math.sqrt(M)>=i:
    if M%i==0:
        d.append(i)
        if i**2!=M:
            d.append(M//i)
    i=i+1
d.sort()#Mの約数列

m=0
i=0
while  M//N>=d[i]:
    if M%d[i]==0:
        m=d[i]
    i=i+1
print(m)
Problem p03256 (python)

Fixed submission:
import sys

input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    s=input()
    dic={"A":[0 for i in range(N)],"B":[0 for i in range(N)]}
    edge=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
        dic[s[a]][b]+=1
        dic[s[b]][a]+=1

    que=set([])
    check=0
    for i in range(N):
        if dic["A"][i]==0 or dic["B"][i]==0:
            que.add(i)


    while que:
        v=que.pop()
        check+=v+1
        dic["A"][v]=float("inf")
        dic["B"][v]=float("inf")
        for nv in edge[v]:
            dic[s[v]][nv]-=1
            if dic["A"][nv]==0 or dic["B"][nv]==0:
                que.add(nv)

    if check==N*(N+1)//2:
        print("No")
    else:
        print("Yes")

if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    s=input()
    dic={"A":[0 for i in range(N)],"B":[0 for i in range(N)]}
    edge=[[] for i in range(N)]

    for i in range(M):
        a,b=map(int,input().split())
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
        dic[s[a]][b]+=1
        dic[s[b]][a]+=1

    que=set([])
    check=0
    for i in range(N):
        if dic["A"][i]==0 or dic["B"][i]==0:
            que.add(i)
            dic["A"][v]=float("inf")
            dic["B"][v]=float("inf")

    while que:
        v=que.pop()
        check+=v+1
        for nv in edge[v]:
            dic[s[v]][nv]-=1
            if dic["A"][nv]==0 or dic["B"][nv]==0:
                dic["A"][v]=float("inf")
                dic["B"][v]=float("inf")
                que.add(nv)

    if check==N*(N+1)//2:
        print("No")
    else:
        print("Yes")

if __name__=="__main__":
    main()
Problem p03297 (python)

Fixed submission:
from fractions import gcd
for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    g=gcd(b,d)
    r=a%g
    if r>=b-d and c>=b-(g-r) and a>=b:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
from math import gcd
for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    g=gcd(b,d)
    r=a%g
    if r>=b-d and c>=b-(g-r) and a>=b:
        print("Yes")
    else:
        print("No")
Problem p03321 (python)

Fixed submission:
N,M=map(int,input().split())
edge=[set([]) for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cedge=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if j not in edge[i] and j!=i:
            cedge[i].append(j)

ans=[]
def is_bipartgraph():
    color=[0]*N
    used=[False]*N
    for i in range(N):
        if not used[i]:
            stack=[(i,1)]
            black=0
            white=0
            while stack:
                v,c=stack.pop()
                color[v]=c
                black+=(not used[v])*(c==1)
                white+=(not used[v])*(c==-1)
                used[v]=True
                for nv in cedge[v]:
                    if color[nv]==color[v]:
                        return False
                    elif color[nv]==0:
                        stack.append((nv,-c))
            ans.append([black,white])
    return True

if is_bipartgraph():
    dp=[[False for i in range(0,N+1)] for j in range(len(ans))]
    a,b=ans[0]
    dp[0][a],dp[0][b]=True,True
    for i in range(1,len(ans)):
        a,b=ans[i]
        for j in range(0,N+1):
            test=False
            if j>=a:
                test=test|dp[i-1][j-a]
            if j>=b:
                test=test|dp[i-1][j-b]
            dp[i][j]=test
    ans=0
    for i in range(0,N+1):
        if dp[-1][i] and abs(ans-N/2)>abs(i-N/2):
            ans=i
    ans2=N-ans
    print(ans*(ans-1)//2+ans2*(ans2-1)//2)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
edge=[set([]) for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].add(b-1)
    edge[b-1].add(a-1)

cedge=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if j not in edge[i] and j!=i:
            cedge[i].append(j)

ans=[]
def is_bipartgraph():
    color=[0]*N
    used=[False]*N
    for i in range(N):
        if not used[i]:
            stack=[(i,1)]
            black=0
            white=0
            while stack:
                v,c=stack.pop()
                used[v]=True
                color[v]=c
                black+=(c==1)
                white+=(c==-1)
                for nv in cedge[v]:
                    if color[nv]==color[v]:
                        return False
                    elif color[nv]==0:
                        stack.append((nv,-c))
            ans.append([black,white])
    return True

if is_bipartgraph():
    dp=[[False for i in range(0,N+1)] for j in range(len(ans))]
    a,b=ans[0]
    dp[0][a],dp[0][b]=True,True
    for i in range(1,len(ans)):
        a,b=ans[i]
        for j in range(0,N+1):
            test=False
            if j>=a:
                test=test|dp[i-1][j-a]
            if j>=b:
                test=test|dp[i-1][j-b]
            dp[i][j]=test
    ans=0
    for i in range(0,N+1):
        if dp[-1][i] and abs(ans-N/2)>abs(i-N/2):
            ans=i
    ans2=N-ans
    print(ans*(ans-1)//2+ans2*(ans2-1)//2)
else:
    print(-1)
Problem p03406 (python)

Fixed submission:
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
dp=[[0 for i in range(2**N)] for j in range(M+1)]

dp[0][0]=g1[2**N-1]

for i in range(1,M+1):
    for j in range(2**N):
        dp[i][j]=dp[i-1][j]
        for k in range(N):
            if j>>k &1==0 and 2**N-A[i]-j>=2**k-1:
                dp[i][j]=(dp[i][j]+((-1)*((g1[2**N-A[i]-j]*g2[2**N-A[i]+1-(j+2**k)])%mod)*((dp[i-1][j+2**k]+g1[2**N-1-j-2**k])*2**k)%mod)%mod)%mod

#for i in range(M+1):
    #print(dp[i])
print((dp[M][0]*pow(2,N,mod))%mod)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N,M=map(int,input().split())
A=[0]+list(map(int,input().split()))
start=time.time()
dp=[[0 for i in range(2**N)] for j in range(M+1)]

dp[0][0]=g1[2**N-1]

for i in range(1,M+1):
    for j in range(2**N):
        dp[i][j]=dp[i-1][j]
        for k in range(N):
            if j>>k &1==0 and 2**N-A[i]-j>=2**k-1:
                dp[i][j]=(dp[i][j]+((-1)*((g1[2**N-A[i]-j]*g2[2**N-A[i]+1-(j+2**k)])%mod)*((dp[i-1][j+2**k]+g1[2**N-1-j-2**k])*2**k)%mod)%mod)%mod

#for i in range(M+1):
    #print(dp[i])
print((dp[M][0]*pow(2,N,mod))%mod)
Problem p03441 (python)

Fixed submission:
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

antena=[]
for i in range(N):
    if len(edge[i])>2:
        antena.append(i)

if not antena:
    print(1)
    exit()

parent=[-1]*N
root=antena[0]

def dfs(v,pv):
    parent[v]=pv
    for i in edge[v]:
        if i!=pv:
            dfs(i,v)

dfs(root,-1)

antena=set(antena)

q=[root]
sub=[]
while q:
    while q:
        x=q.pop()
        if x in antena:
            v=x
            while parent[v] not in antena and parent[v]!=-1:
                antena.add(parent[v])
                v=parent[v]
        for nv in edge[x]:
            if nv!=parent[x]:
                sub.append(nv)

        if not q:
            q=sub
            sub=[]
            break

ans=0
for u in antena:
    if len(edge[u])==1:
        ans+=1
    elif len(edge[u])==2:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check==1:
            ans+=1
    else:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check>=len(edge[u])-1:
            continue
        else:
            ans+=len(edge[u])-1-check
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

antena=[]
for i in range(N):
    if len(edge[i])>2:
        antena.append(i)

if not antena:
    print(1)
    exit()

parent=[-1]*N
root=antena[0]

def dfs(v,pv):
    parent[v]=pv
    for i in edge[v]:
        if i!=pv:
            dfs(i,v)

dfs(root,-1)

antena=set(antena)

q=[root]
sub=[]
while q:
    while q:
        x=q.pop()
        if x in antena:
            v=x
            while parent[v] not in antena and parent[v]!=-1:
                antena.add(parent[v])
                v=parent[v]
        for nv in edge[x]:
            if nv!=parent[x]:
                sub.append(nv)

        if not q:
            q=sub
            sub=[]
            break

ans=0
for u in antena:
    if len(edge[u])==1:
        ans+=1
    elif len(edge[u])==2:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check==1:
            ans+=1
    else:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check>=len(edge[u])-1:
            continue
        else:
            ans+=len(edge[u])-1-check
print(ans)
Problem p03528 (python)

Fixed submission:
K=38
#K=int(input())
N=K**2-K+1

print(N,K)
_res=[[-1 for j in range(K-1)] for i in range((K-1)**2)]
rest=[[-1 for j in range(K-1)] for i in range(K-1)]

id=K
start=0
while N>id:
    for j in range(K-1):
        _res[(K-1)*j+(start+j*((id-1)//(K-1)))%(K-1)][(id-1)//(K-1)-1]=id
    id+=1
    start=(start+1)%(K-1)

rest=[[_res[j][i] for j in range(K-1)] for i in range(K-1)]

ans=[[i for i in range(K)]]
for i in range(K-1):
    for j in range(K-1):
        tmp=[i]+_res[(K-1)*i+j]
        ans.append(tmp)
for i in range(K-1):
    tmp=[K-1]+rest[i]
    ans.append(tmp)

for i in range(N):
    ans[i]=[ans[i][j]+1 for j in range(K)]

for i in range(N):
    print(*ans[i])

def check():
    ids=[[] for i in range(N)]
    for i in range(N):
        ans[i].sort()
        if ans[i][0]<0 or ans[i][-1]>N-1:
            exit(print("WA1"))
        for j in range(1,K):
            if ans[i][j]==ans[i][j-1]:
                exit(print("WA2"))
        for j in range(K):
            ids[ans[i][j]].append(i)
    for i in range(N):
        if len(ids[i])!=K:
            exit(print("WA3"))
    p=set([])
    for i in range(N):
        for j in range(len(ids[i])):
            for k in range(j):
                a,b=ids[i][j],ids[i][k]
                if (a,b) in p:
                    print("WA4")
                    print(ans[a])
                    print(ans[b])
                    exit()

                p.add((a,b))

#check()

Buggy submission (verdict: Runtime Error):
K=38
K=int(input())
N=K**2-K+1

print(N,K)
_res=[[-1 for j in range(K-1)] for i in range((K-1)**2)]
rest=[[-1 for j in range(K-1)] for i in range(K-1)]

id=K
start=0
while N>id:
    for j in range(K-1):
        _res[(K-1)*j+(start+j*((id-1)//(K-1)))%(K-1)][(id-1)//(K-1)-1]=id
    id+=1
    start=(start+1)%(K-1)

rest=[[_res[j][i] for j in range(K-1)] for i in range(K-1)]

ans=[[i for i in range(K)]]
for i in range(K-1):
    for j in range(K-1):
        tmp=[i]+_res[(K-1)*i+j]
        ans.append(tmp)
for i in range(K-1):
    tmp=[K-1]+rest[i]
    ans.append(tmp)

for i in range(N):
    ans[i]=[ans[i][j]+1 for j in range(K)]

for i in range(N):
    print(*ans[i])

def check():
    ids=[[] for i in range(N)]
    for i in range(N):
        ans[i].sort()
        if ans[i][0]<0 or ans[i][-1]>N-1:
            exit(print("WA1"))
        for j in range(1,K):
            if ans[i][j]==ans[i][j-1]:
                exit(print("WA2"))
        for j in range(K):
            ids[ans[i][j]].append(i)
    for i in range(N):
        if len(ids[i])!=K:
            exit(print("WA3"))
    p=set([])
    for i in range(N):
        for j in range(len(ids[i])):
            for k in range(j):
                a,b=ids[i][j],ids[i][k]
                if (a,b) in p:
                    print("WA4")
                    print(ans[a])
                    print(ans[b])
                    exit()

                p.add((a,b))

#check()
Problem p03558 (python)

Fixed submission:
K=int(input())
a=K
while a%2==0:
    a//=2
while a%5==0:
    a//=5
if a==1:
    print(1)
else:
    mod=set([])
    a=1
    while a not in mod:
        mod.add(a)
        a*=10
        a%=K

    mod=list(mod)
    n=len(mod)
    wei=pow(2,K)-1
    check=1
    ans=0
    for j in range(0,n):
        ans=ans|(check<<mod[j])
    check=ans
    for i in range(1,46):
        if check>>0 &1==1:
            print(i)
            exit()
        ans=check
        for j in range(0,n):
            ans=ans|(check<<mod[j])
        ans1=ans&wei
        ans2=ans>>K
        check=ans1|ans2

Buggy submission (verdict: Runtime Error):
K=int(input())

if K%10==0:
    print(1)
else:
    mod=set([])
    i=0
    while pow(10,i,K) not in mod:
        mod.add(pow(10,i,K))
        i+=1

    mod=list(mod)
    mod.sort(reverse=True)

    ans=0
    for i in range(0,len(mod)):
        ans+=K//mod[i]
        K%=mod[i]

    print(ans)
Problem p03607 (python)

Fixed submission:
N=int(input())
a =[]
for _ in range(0,N):
    a.append(int(input()))
b =[]
f=0
s=0
a.sort()
for i in range(0,N):
    if i==0:
        b.append(1)
    elif a[i]==a[i-1]:
        if b[f]==1:
            b[f]=0
        else:
            b[f]=1
    else:
        b.append(1)
        f=f+1
for i in range(0,len(b)):
    s=s+b[i]
print(s)

Buggy submission (verdict: Runtime Error):
N=int(input())
a =[]
for _ in range(0,N):
    a.append(input())
s=0
x=0
b=[0]*(10**9)
for i in range(0,N):
    x=int(a[i])
    if b[x]==0:
        b[x]=1
    else:
        b[x]=0
y=int(max(a))
for i in range(0,y):
    s=s+b[i]
print(s)
Problem p03721 (python)

Fixed submission:
N,K=map(int,input().split())
a =[0]*N
b =[0]*N
for i in range(0,N):
    a[i],b[i] =map(int,input().split())
c=[0]*(10**6)
for i in range(0,N):
    c[a[i]]=c[a[i]]+b[i]
s=0
i=1
while s<K:
    s=s+c[i]
    x=i
    i=i+1
print(x)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a =[0]*N
b =[0]*N
for i in range(0,N):
    a[i],b[i] =map(int,input().split())
c=[0]*(10**6)
for i in range(0,N):
    c[a[i]]=c[a[i]]+b[i]
s=0
i=1
while s<K:
    s=s+c[i]
    x=a[i-1]
    i=i+1
print(x)
Problem p03913 (python)

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

ans=N

for i in range(-10,10):
    x=int(N**.5)+i
    if x>0:
        test=x+A+(N-1)//x+1
        ans=min(ans,test)

for n in range(2,41):
    for i in range(2*n,int(N**(1/n))+1000):
        test=i+n*A
        q=i//n
        r=i%n
        prod=pow(q,n-r)*pow(q+1,r)
        test+=(N-1)//prod+1
        ans=min(ans,test)

print(ans)

Buggy submission (verdict: Runtime Error):
N,A=map(int,input().split())

ans=N
for n in range(1,41):
    for i in range(2*n,N**(1/n)+100):
        test=i+n*A
        q=i//n
        r=i%n
        prod=pow(q,n-r)*pow(q+1,r)
        test+=(N-1)//prod+1
        ans=min(ans,test)

print(ans)