Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
    else:
        return str(usable[0])


def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()

    Nstr = list(str(N))
    ans = ''
    flag = True
    for n in Nstr:
        n = int(n)
        if flag:
            if n in D:
                ans += minN(n, d)
                flag = False
            else:
                ans += str(n)
        else:
            ans += str(min(d))
    print(int(ans))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = numset.difference(D)

    for n in range(N, pow(10, 6) + 10):
        check = set(list(str(n)))
        ngflag = False
        for i in check:
            if int(i) in D:
                ngflag = True
                break
        if not ngflag:
            break
    print(n)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
import random
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
sa=set(a)
ans=[]
era=[1]*(10**6+1)
era[0]=0
ca=Counter(a)

k=2
while k<(10**6+1):
  if era[k]==1:
    for i in range(k,10**6+1,k):
      if i!=k:
        era[i]=0
      if i in sa:
        for t in range(ca[i]):
          ans.append(k)
  if k==2:
    k+=1
  else:
    k+=2

pflag=True
if len(ans)!=len(set(ans)):
  pflag=False
  
if pflag == False:
  setwise=a[0]
  for i in range(1,n):
    setwise=math.gcd(setwise,a[i])
  if setwise == 1:
    print("setwise coprime")
  else:
    print("not coprime")
else:
  print('pairwise coprime')


Fixed submission:
import math
n=int(input())
a=list(map(int,input().split()))
pflag=True
def prime_factorize(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
sosu=[1]*(10**6+1)
sosu[0]=0

k=2
while k<(10**6+1)**0.5+1:
  for i in range(2*k,10**6+1,k):
    sosu[i]=0
  if k==2:
    k+=1
  else:
    k+=2
gu=0
import copy
ans=copy.deepcopy(sosu)

for i in range(n):
  if gu>1:
    pflag=False
  if ans[a[i]]==0:
    ai = set(prime_factorize(a[i]))
    for j in ai:
      if ans[j]==0:
        pflag=False
        break
      else:
        ans[j]=0
  else:
    ans[a[i]]=0
  if a[i]%2==0:
    gu+=1
  ans[a[i]]=0
    
if pflag == False:
  setwise=a[0]
  for i in range(1,n):
    setwise=math.gcd(setwise,a[i])
  if setwise == 1:
    print("setwise coprime")
  else:
    print("not coprime")
else:
  print('pairwise coprime')
Buggy python submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]
ans[ch-1][cw-1]=0

qu = deque([])
qu.append((cw-1,ch-1))
while qu:
  x,y=qu.popleft()

  for i in range(max(x-2,0),min(x+3,w)):
    for j in range(max(y-2,0),min(y+3,h)):
      if (x==i and y==j):
        continue
      if maze[j][i]=="." and (ans[j][i]>ans[y][x] or ans[j][i]==-1):
        if (x==i and y==j+1) or (x==i+1 and y==j) or (x==i-1 and y==j) or (x==i and y==j-1):
          qu.appendleft((i,j))
          ans[j][i] = ans[y][x]
        elif ans[j][i]>ans[y][x]+1 or ans[j][i]==-1:
          ans[j][i]=(ans[y][x]+1)
          qu.appendleft((i,j))

print(ans[dh-1][dw-1])

  




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

if n%x==0:
  print(t*(n//x))
else:
  print(((n//x)+1)*t)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,m=map(int,input().split())
d_h=[0]*(h+1)
d_w=[0]*(w+1)
d=set()
for i in range(m):
  nh,nw=map(int,input().split())
  d_h[nh]+=1
  d_w[nw]+=1
  d.add((nh,nw))
ans=0
hantei=0
for i in range(1,h+1):
  hantei=0
  for j in range(1,w+1):
    if (i,j) in d:
      hantei=(d_h[i]+d_w[j]-1)
    else:
      hantei=(d_h[i]+d_w[j])
    if ans < hantei:
      ans=hantei
print(ans)

Fixed submission:
h,w,m=map(int,input().split())
d_h=[0]*(h+1)
d_w=[0]*(w+1)
d=[]
for i in range(m):
  nh,nw=map(int,input().split())
  d_h[nh]+=1
  d_w[nw]+=1
  d.append([nh,nw])
  
#print(d_h)
#print(d_w)

hantei=0
ans1=max(d_h)
memoh=set()
for i in range(1,h+1):
  hantei=d_h[i]
  if ans1==hantei:
    memoh.add(i)
    
hantei=0
ans2=max(d_w)
memow=set()
for j in range(1,w+1):
  hantei=d_w[j]
  if ans2 == hantei:
    memow.add(j)
ans = ans2+ans1-1
#print(memoh,memow)
count = len(memoh)*len(memow)
for hw in d:
  if hw[0] in memoh and hw[1] in memow:
    count-=1
if count>0:
  print(ans+1)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    suma += (a//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)

Fixed submission:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))

x0, x1 = 0, 10**9
while x0 + 1  < x1:
  x = (x0+x1)//2
  suma=0
  for i in a:
    if i%x==0:
      suma+=(i//x)-1
    else:
      suma += (i//x)
    
  if suma > k:
    x0 = x
  else:
    x1 = x
print(x1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
syaku=1
for i in range(k):
  syaku*=a[i]
now=syaku
for i in range(k,len(a)):
  pre=now
  now=now*a[i]//a[i-k]
  if pre<now:
    print("Yes")
  else:
    print("No")
  

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
#for i in range(k):
#  syaku*=a[i]
#now=syaku
for i in range(k,len(a)):
  #pre=now
  #now=now*a[i]//a[i-k]
  if a[i]>a[i-k]:
    print("Yes")
  else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
syaku=1
for i in range(k):
  syaku*=a[i]
now=syaku
for i in range(k,len(a)):
  pre=now
  now=now*a[i]//a[i-k]
  if pre<now:
    print("Yes")
  else:
    print("No")
  

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
#for i in range(k):
#  syaku*=a[i]
#now=syaku
for i in range(k,len(a)):
  #pre=now
  #now=now*a[i]//a[i-k]
  if a[i]>a[i-k]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  sb=[sa[i]]+sb
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=len(sb)
print(ans)


Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=(len(sb)+len(tb))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  sb=[sa[i]]+sb
  kb+=sa[i]
  if ans<len(sb):
    ans=len(sb)
print(ans)


Fixed submission:
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

sa=[]
ka=0
sb=[]
kb=0
for i in range(n):
  if ka+a[i]<=k:
    ka+=a[i]
    sa.append(a[i])
  else:
    break
for i in range(m):
  if kb+b[i]<=k:
    kb+=b[i]
    sb.append(b[i])
  else:
    break
ans=max(len(sa),len(sb))
tb=[]
for i in range(len(sa)):
  if sa[i]>k:
    break
  while kb+sa[i]>k:
    kb-=sb[-1]
    sb.pop(-1)
  tb.append(sa[i])
  kb+=sa[i]
  if ans<(len(sb)+len(tb)):
    ans=(len(sb)+len(tb))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
for i in range(1,n+1):
  #項数
  kousu=n//i
  #一般項
  an = i + (kousu-1)*i
  #和の公式
  sn = (i + an)*kousu//2
  ans += sn
print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1,n+1):
  #項数
  kousu=n//i
  #一般項
  an = i + (kousu-1)*i
  #和の公式
  sn = (i + an)*kousu//2
  ans += sn
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
ab=list(map(int,input().split()))
M=max(ab)
a=[]
for i in Counter(ab):
  if Counter(ab)[i]==1:
    a.append(i)
ans=set([])
a.sort()
ans_count=0
N=0
if len(a)==0:
  print(0)
else:
  for i in range(n):
    if not a[i] in ans:
      N=a[i]
      count=1
      ans.add(N)
      ans_count+=1
      for j in range(2*N,M+1,N):
        ans.add(j)
  print(ans_count)

Fixed submission:
from collections import Counter
n = int(input())
a = [int(v) for v in input().split()]
 
M = max(a)
d = [1 for i in range(M+1)]
for v in sorted(a):
    for j in range(2*v, M+1, v):
        d[j] = 0
ans = 0
c = Counter(a)
for i in a:
    if c[i]==1:
      ans += d[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
ab=list(map(int,input().split()))
a=[]
for i in Counter(ab):
  if Counter(ab)[i]==1:
    a.append(i)
ans=set([])
a.sort()
ans_count=0
N=10**9+1
if len(a)==0:
  print(0)
else:
  for i in range(n):
    if not a[i] in ans:
      N=a[i]
      count=1
      ans.add(N)
      ans_count+=1
      while N*count<10**6+1:
        count+=1
        ans.add(N*count)
  print(ans_count)

Fixed submission:
from collections import Counter
n = int(input())
a = [int(v) for v in input().split()]
 
M = max(a)
d = [1 for i in range(M+1)]
for v in sorted(a):
    for j in range(2*v, M+1, v):
        d[j] = 0
ans = 0
c = Counter(a)
for i in a:
    if c[i]==1:
      ans += d[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,50)):
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  if a[:n]==[n]*n:
    break
    
print(*a[:n]) 


Fixed submission:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,50)):
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  if a[:n]==[n]*n:
    break
    
print(*a[:n])

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,32)):
  
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  
  if a[:n]==[n]*n:
    break
print(*a[:n]) 


Fixed submission:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,50)):
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  if a[:n]==[n]*n:
    break
    
print(*a[:n])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans1=[]
ans2=[]
ans1+=a
ans2+=a
for i in range(min(k,32)):
  now=0
  ans2=[]
  ans2+=ans1
  kans=[0]*n
  for j in range(n):
    if j+ans2[j]+1<=n-1:
      kans[j+ans2[j]+1]-=1
    now+=1+kans[j]
    #基本kans[j]は0だが終点は-1
    ans1[j]=now
  now=0
  kans=[0]*n
  for j in range(1,n+1):
    if n-j-ans2[n-j]>=0:
      kans[n-j-ans2[n-j]-1]-=1
    now+=1+kans[n-j]
    #基本kans[j]は0だが終点は-1
    ans1[n-j]+=now-1
print(*ans1)
  
    
      
    

Fixed submission:
import itertools
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(min(k,50)):
  imos=[0]*(n+1)
  for j in range(n):
    imos[max(j-a[j],0)]+=1
    imos[min(j+a[j]+1,n)]-=1
  a=list(itertools.accumulate(imos))
  if a[:n]==[n]*n:
    break
    
print(*a[:n])
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      a=fractions.gcd(i,j)
      a=fractions.gcd(a,l)
      ans+=a
print(ans)

Fixed submission:
import math
k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    b=math.gcd(i,j)
    for l in range(1,k+1):
      a=math.gcd(b,l)
      ans+=a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
for i in range(n):
  a=list(map(str,input().split()))
  if a[0]=="1":
    s=s[::-1]
  else:
    if a[1]=="1":
      s=a[2]+s
    else:
      s+=a[2]
print(s)

Fixed submission:
s=input()
q=int(input())
que=[]
count=0
left=[]
right=[]
for i in range(q):
  qu=list(map(str,input().split()))
  if qu[0]=="1":
    count+=1
  que.append(qu)
han=0
for i in range(q):
  if que[i][0]=="1":
    han+=1
  else:
    if que[i][1]=="1":  
      if (count-han)%2==0:
        left.append(que[i][2])
      else:
        right.append(que[i][2])
    elif que[i][1]=="2":  
      if (count-han)%2==0:
        right.append(que[i][2])
      else:
        left.append(que[i][2])
ls="".join(left[::-1])
rs="".join(right)
if count%2==0:
  print(ls+s+rs)
else:
  print(ls+s[::-1]+rs)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
for i in range(n):
  a=list(map(str,input().split()))
  if a[0]=="1":
    s=s[::-1]
  else:
    if a[1]=="1":
      s=a[2]+s
    else:
      s+=a[2]
print(s)

Fixed submission:
s=input()
q=int(input())
que=[]
count=0
left=[]
right=[]
for i in range(q):
  qu=list(map(str,input().split()))
  if qu[0]=="1":
    count+=1
  que.append(qu)
han=0
for i in range(q):
  if que[i][0]=="1":
    han+=1
  else:
    if que[i][1]=="1":  
      if (count-han)%2==0:
        left.append(que[i][2])
      else:
        right.append(que[i][2])
    elif que[i][1]=="2":  
      if (count-han)%2==0:
        right.append(que[i][2])
      else:
        left.append(que[i][2])
ls="".join(left[::-1])
rs="".join(right)
if count%2==0:
  print(ls+s+rs)
else:
  print(ls+s[::-1]+rs)
Buggy python submission (verdict: Runtime Error):
s,t=map(str,input().split())
a,b=map(int,input().split())
ss=input()
if ss="s":
  a-=1
else:
  b-=1
print(a,b)


Fixed submission:
s,t=map(str,input().split())
a,b=map(int,input().split())
u=input()
if u==s:
  a-=1
elif u==t:
  b-=1
print(a,b)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.append(0)
h.sort()
for i in range(k):
  h.pop(-1)
print(sum(h))

Fixed submission:
n,k=map(int,input().split())
if n<k:
  k=n
h=list(map(int,input().split()))
h.append(0)
h.sort()
for i in range(k):
  h.pop(-1)
print(sum(h))
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[[10**9+1]*(h+1) for i in range(n+1)]
for i in dp:
  i[0]=0

for i in range(n):
  for j in range(h+1):
    if j-ab[i][0]>=0:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i][0]]+ab[i][1],(j//ab[i][0]+1)*ab[i][1])
    else:
      dp[i+1][j]=min(dp[i][j],ab[i][1])
print(dp[-1][h])

Fixed submission:
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
dp=[[10**9+1]*(h+1) for i in range(n+1)]
for i in dp:
  i[0]=0

for i in range(n):
  for j in range(h+1):
    if j-ab[i][0]>=0:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-ab[i][0]]+ab[i][1],(j//ab[i][0]+1)*ab[i][1])
    else:
      dp[i+1][j]=min(dp[i][j],ab[i][1])
print(dp[-1][h])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n>m:
  print("No")
else:
  print("Yes)

Fixed submission:
n,m=map(int,input().split())
if n>m:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2!=0:
  print(0)
else:
  a=0
  for i in range(1,26):
    a+=(n//(2*5**i))
print(a)

Fixed submission:
n=int(input())
if n%2!=0:
  print(0)
else:
  a=0
  for i in range(1,26):
    a+=(n//(2*5**i))
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

Fixed submission:
n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
count=0
count2=0
d=[]
hk3=0
hk2=0
hk1=0
for j in range(100,1000):
  k3=j//100
  k2=(j-k3*100)//10
  k1=j-k3*100-k2*10
  for i in range(n):
    if str(k3)==s[i]:
      hk3=1
    if str(k2)==s[i] and hk3==1:
      hk2=1
    if str(k1)==s[i] and hk2==1:
      hk1=1
    if hk1==1 and hk2==1 and hk3==1:
      d.append(j)
  hk1=0
  hk2=0
  hk3=0
for j in range(1,10):
  for i in range(n):
    if s[i]=="0":
      count=1
    if count==1 and s[i]=="0":
      count2=1
    if count2=0 and s[i]==str(j):
      d.append(j)
  count=0
  count2=0
for j in range(10,100):
  k2=j//10
  k1=j-k2*10
  for i in range(n):
    if s[i]=="0":
      count=1
    if str(k2)==s[i] and count=1:
      hk2=1
    if str(k1)==s[i] and hk2==1 and count=1:
      hk1=1
    if hk1==1 and hk2==1:
      d.append(j)
  count=0
  hk1=0
  hk2=0
print(len(set(d)))
      

Fixed submission:
n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ab=[list(map(int,input().split())) for i in range(n-1)]
edge=[[] for i in range(n+1)]
iro=0
for i in ab:
  edge[i[0]].append(i[1])
for i in edge:
  if (len(i)+1)>iro:
    iro=len(i)+1
color_list=list(range(1,iro+1))
ans=[[] for i in range(n+1)]
def DFS(x,pre,color,color_list,ans):
  count=-1
  color_list=list(range(1,iro+1))
  if len(edge[x])==0:
    #print(str(pre) + "→"+ str(x) +":" + str(color))
    ans[pre].append(color)
    return
  elif 1!=x:
    #print(str(pre) + "→"+ str(x) +":" + str(color))
    ans[pre].append(color)
  for i in edge[x]:
    a=color_list.pop(-1)
    if a==color:
      a=color_list.pop(-1)
    DFS(i,x,a,color_list,ans)
    
DFS(1,-1,iro,color_list,ans)
for i in ans:
  for j in i:
    print(j)

Fixed submission:
from collections import deque
n=int(input())
edge=[[] for i in range(n+1)]
ab=[]
ans=dict()
for i in range(n-1):
  a,b=map(int,input().split())
  ab.append([a,b])
  ans[(a,b)]=0
  edge[a].append(b)
  edge[b].append(a)
hantei=0  
for i in edge:
  if hantei<len(i):
    hantei=len(i)
iro=hantei
print(iro)
color_list=[0]*(n+1)
def bfs(x,ans):
  qu=deque([])
  qu.append(1)
  count=1
  while qu:
    now=qu.popleft()
    if now!=1:
      pre=qu.popleft()
    else:
      pre=0
    count=1
    for i in edge[now]:
      if i!=pre:
        qu.append(i)
        qu.append(now)
        if now!=1 and ans[(pre,now)]==count:
          count+=1
        ans[(now,i)]=count
        count+=1
  return ans
bfs(1,ans)
for i,j in ab:
  print(ans[(i,j)])
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
mod = 10**9+7
flflag=True

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans

N=a+b
R=min(a,b)
ans=0
if a>=0 and b>=0 and flflag==True:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)

Fixed submission:
x,y=map(int,input().split())
mod = 10**9+7
flflag=True

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans
if flflag:
  N=a+b
  R=min(a,b)
ans=0
if flflag==True and a>=0 and b>=0:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
f=[[0]*(10**3) for i in range(10**3)]
for i in range(x):
  for j in range(y):
    f[i][j]=f[i-1][j-2]+f[i-2][j-1]
print(f[x][y])

Fixed submission:
x,y=map(int,input().split())
mod = 10**9+7
flflag=True

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans
if flflag:
  N=a+b
  R=min(a,b)
ans=0
if flflag==True and a>=0 and b>=0:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
d=[[0]*x for i in range(y)]

def d(a,b):
  if a==1 and b==2:
    return 1
  elif a==2 and b==1:
    return 1
  elif a<1 and b<1:
    return 0
  return d(a-1,b-2)+d(a-2,b-1)

print(d(x,y)%(10**9+7))

Fixed submission:
x,y=map(int,input().split())
mod = 10**9+7
flflag=True

if (2*x-y)%3==0:
  a=(2*x-y)//3
else:
  flflag=False
if (2*y-x)%3==0:
  b=(2*y-x)//3
else:
  flflag=False

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans*=i%mod
    ans%=mod  
  return ans
if flflag:
  N=a+b
  R=min(a,b)
ans=0
if flflag==True and a>=0 and b>=0:
  ans=kaijou(N)
  ans1= (kaijou(N-R)*kaijou(R))%mod
  print((ans*pow(ans1,mod-2,mod))%mod)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
mini = (10** 12)+1
X=0
Y=0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
ans = make_divisors(n)
for i in range(len(ans)):
  for j in range(len(ans)):
    if mini>ans[i]-ans[j] and n==ans[i]*ans[j] and ans[i]>=ans[j]:
      mini =ans[i]-ans[j]
      X=ans[i]
      Y=ans[j]
print(X-1+Y-1)

Fixed submission:
n=int(input())
mini = (10** 12)+1
X=0
Y=0
t=0
K=0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors
ans = make_divisors(n)
ans.sort()
K+=len(ans)
if K%2:
  for i in range(int((K+1)/2)):
    t=-(i+1)
    if mini>ans[t]-ans[i] and n==ans[t]*ans[i] and ans[t]>=ans[i]:
      mini =ans[t]-ans[i]
      X=ans[t]
      Y=ans[i]
else:
  for i in range(int(K/2)):
    t=-(i+1)
    if mini>ans[t]-ans[i] and n==ans[t]*ans[i] and ans[t]>=ans[i]:
      mini =ans[t]-ans[i]
      X=ans[t]
      Y=ans[i]
print(X-1+Y-1)