Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#入力受け取り
N, K=map(int, input().split())

#N=aK+bとした時のbを求める
B=N%K

#bとK-bの小さい方を出力
print(min(b, K-b))


Fixed submission:
N, K=map(int, input().split())
tmp=N%K
print(min(tmp, K-tmp))
Buggy python submission (verdict: Runtime Error):
#キューを使います
from collections import deque

#関数f:入力xの1の位がyだとした時、「xの末尾に(y-1)を付加したもの」を出力
def f(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y-1) #yから1引いて、元の文字列の末尾に追加

#関数g:入力xの1の位がyだとした時、「xの末尾にyを付加したもの」を出力
def g(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y) #yを元の文字列の末尾に追加

#関数h:入力xの1の位がyだとした時、「xの末尾にy+1を付加したもの」を出力
def h(x):
  s=str(x) #文字列にする
  y=int(s[-1]) #末尾を取り出し数字に戻したものをyとする
  return s+str(y+1) #y+1を元の文字列の末尾に追加

#入力受け取り
K=int(input())

#キューの準備
q=deque()

#キューには1から9の整数を先に入れておく
for i in range(1, 10):
  q.append(i)
  
#キューから数字を取り出し、末尾に数字を付けることで作れるルンルン数をキューに追加する
#この操作をK-1回行う
for i in range(K-1):
  num=q.popleft()　#キューから数字を取り出す
  if v%10!=0: #末尾が0の時は、末尾から-1した数字を付加してもルンルン数とならないため除外
    q.append(f(num))
    
  q.append(g(num))
  
  if v%10!=9: #末尾が9の時は、末尾に+1した数字を付加してもルンルン数とならないため除外
    q.append(h(num))
    
print(q.popleft()) #K回目に出てくるルンルン数を出力

Fixed submission:
import heapq
K=int(input())
if K<10:
  print(K)
  exit()
  
nums=[1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(nums)
for i in range(K):
  value=heapq.heappop(nums)
  tmp=str(value)
  if tmp[-1]=='0':
    cand=[int(tmp+'0'), int(tmp+'1')]
  elif tmp[-1]=='9':
    cand=[int(tmp+'8'), int(tmp+'9')]
  else:
    h=int(tmp[-1])
    cand=[int(tmp+str(h-1)), int(tmp+str(h)), int(tmp+str(h+1))]
  for c in cand:
    heapq.heappush(nums, c)
print(value)
Buggy python submission (verdict: Runtime Error):
#関数f:入力xの1以外の約数をリストで出力
def f(x):
  out=set() #約数を保存するセット
  for i in range(1, (pow(x, 1/2)):
    #1-x**(1/2)未満の整数iについて、xを割り切れるか判定
    if x%i==0:
      #xをiで割り切れるのであれば、iとx/iを保存
      out.add(i)
      out.add(x//i)
      
  #x**(1/2)でxを割り切れる(つまりxが平方数)なら、出力にx**(1/2)を追加
  if x%(x**(1/2))==0:
    out.add(x**(1/2))
    
  #セットから昇順のリストに変換します
  out=list(out)
  out.sort()
  
  #昇順にした結果1が先頭に来ているため、インデックス1以降を出力
  return out[1:]

#入力受け取り
N=int(input())
ans=0 #最後に出力する変数

for K in f(N): #Nの1以外の約数について、操作の結果1になるかをそれぞれ調べる
    x=N #Nを直接書き換えると後に影響するため、ここではxとする
    #xをKで割り切れる間は、Kで割り続ける
    while x%K==0:
      x/=K
      
    #xをKで割り切れなくなったら、xからKを引けるだけ引く(=割って余りをとる)
    x%=K
    
    #操作後x=1となったならば、出力に1を足す
    if x==1:
        ans+=1
        
#(N-1)の1を除いた約数はすべて条件を満たすため、出力にf(N-1)の要素数を足す
ans+=len(f(N-1))

#出力
print(ans)

Fixed submission:
N=int(input())
if N==2:
    print(1)
    exit()

ans=0
def f(x):
    out=set()
    for i in range(1, int(x**(1/2))+1):
        if x%i==0:
            out.add(i)
            out.add(x//i)
    out=list(out)
    out.sort()
    return out[1:]

tmp=f(N)
for K in tmp:
    x=N
    while x>=K:
        if x%K==0:
            x=x//K
        else:
            x=x%K
            
    if x==1:
        ans+=1
        
tmp=f(N-1)
ans+=len(tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, X, Y=map(int, input().split())
ans=[0 for _ in range(N)]
link=[[]]+[[2]]+[[i-1, i+1] for i in range(2, N)]+[[N-1]]
link[X].append(Y)
link[Y].append(X)

def f(p, length, moto):
  ans[length]+=1
  for data in link[p]:
    if kisyutu[data]==0:
      kisyutu[data]=1
      q.append([data, length+1, p])

for i in range(1, N+1):
  kisyutu=[1]+[0 for i in range(N)]
  kisyutu[i]=1
  q=deque()
  for data in link[i]:
    q.append([data, 1, i])
    kisyutu[data]=1
  while len(q)>0:
    data=q.popleft()
    f(data[0], data[1], data[2])
    
ans=[ans[i]//2 for i in range(N)]
print(*ans[1:], sep='\n')

Fixed submission:
from collections import deque
N, X, Y=map(int, input().split())
ans=[0 for _ in range(N)]
link=[[]]+[[2]]+[[i-1, i+1] for i in range(2, N)]+[[N-1]]
link[X].append(Y)
link[Y].append(X)

def f(p, length, moto):
  ans[length]+=1
  for data in link[p]:
    if kisyutu[data]==0:
      kisyutu[data]=1
      q.append([data, length+1, p])

for i in range(1, N+1):
  kisyutu=[1]+[0 for i in range(N)]
  kisyutu[i]=1
  q=deque()
  for data in link[i]:
    q.append([data, 1, i])
    kisyutu[data]=1
  while len(q)>0:
    data=q.popleft()
    f(data[0], data[1], data[2])
    
ans=[ans[i]//2 for i in range(N)]
print(*ans[1:], sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
def f(nums, K, w):
  h=len(nums)
  counter=[nums[x][0] for x in range(h)]
  if max(counter)>K:
    return float('inf')
  
  out=0
  for i in range(1, w):
    for x in range(h):
      counter[x]+=nums[x][i]
      
    if max(counter)>K:
      out+=1
      counter=[nums[x][i] for x in range(h)]
      
  return out

H, W, K=map(int, input().split())
S=[input() for _ in range(H)]
S=[[int(S[i][j]) for j in range(W)] for i in range(H)]
ans=float('inf')
for p in range(2**(H-1)):
  q='0'+format(p, '0'+str(H-1)+'b')+'1'
  i=0
  c=0
  nums=[]
  while i<H:
    j=1
    while i+j<H and q[i+j]=='0':
      j+=1
    tmp=S[i:i+j]
    nums.append([sum([tmp[y][x] for y in range(j)]) for x in range(W)])
    i+=j
    
  cand=f(nums, K, W)+q.count('1')-1
  if ans>cand:
    ans=cand
    
print(ans)



Fixed submission:
def f(nums, K, w):
  h=len(nums)
  counter=[nums[x][0] for x in range(h)]
  if max(counter)>K:
    return float('inf')
  
  out=0
  for i in range(1, w):
    for x in range(h):
      counter[x]+=nums[x][i]
      
    if max(counter)>K:
      out+=1
      counter=[nums[x][i] for x in range(h)]
      
  return out

H, W, K=map(int, input().split())
S=[input() for _ in range(H)]
S=[[int(S[i][j]) for j in range(W)] for i in range(H)]
ans=float('inf')
for p in range(2**(H-1)):
  q='0'+format(p, '0'+str(H-1)+'b')+'1'
  i=0
  c=0
  nums=[]
  while i<H:
    j=1
    while i+j<H and q[i+j]=='0':
      j+=1
    tmp=S[i:i+j]
    nums.append([sum([tmp[y][x] for y in range(j)]) for x in range(W)])
    i+=j
    
  cand=f(nums, K, W)+q.count('1')-1
  if ans>cand:
    ans=cand
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])

Fixed submission:
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
order=1
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      s=c+s
    else:
      s=s+c
print(s) if order==1 else print(s[::-1])

Fixed submission:
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
order=1
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      s=c+s
    else:
      s=s+c
print(s) if order==1 else print(s[::-1])

Fixed submission:
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
order=1
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    tmp=list(tmp.split())
    if (tmp[1]=='1' and order==1) or (tmp[1]=='2' and order==-1):
      s=tmp[2]+s
    else:
      s=s+tmp[2]
print(s) if order==1 else print(s[::-1])

Fixed submission:
s=input()
q=int(input())
order=1
header=''
footer=''
for _ in range(q):
  tmp=input()
  if tmp=='1':
    order*=-1
  else:
    t, f, c=tmp.split()
    if (int(f)*order)%3==1:
      header=c+header
    else:
      footer=footer+c
s=header+s+footer
print(s) if order==1 else print(s[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
H, N=map(int, input().split())
dp=[0]+[float('inf') for _ in range(2*10**4)]
for _ in range(N):
  a, b=map(int, input().split())
  for i in range(a, H+a):
    dp[i]=min(dp[i-a]+b, dp[i])
    
print(min(dp[H:]))

Fixed submission:
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
anss=[]
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(anss))

Buggy python submission (verdict: Time Limit Exceeded):
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]
dp=[0]+[float('inf') for _ in range(2*10**4)]
for a, b in AB:
  for i in range(a, H+a):
    dp[i]=min(dp[i-a]+b, dp[i])
    
print(min(dp[H:]))

Fixed submission:
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
anss=[]
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(anss))

Buggy python submission (verdict: Runtime Error):
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(nums))

Fixed submission:
H, N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

nums=[-1]*20001
for i in range(N):
  if nums[AB[i][0]]<0:
    nums[AB[i][0]]=AB[i][1]
  else:
    nums[AB[i][0]]=min(AB[i][1], nums[AB[i][0]])
  
for i in range(1, H):
  if nums[i]>0:
    for j in range(N):
      if nums[i+AB[j][0]]>0:
        if nums[i+AB[j][0]]>nums[i]+AB[j][1]:
          nums[i+AB[j][0]]=nums[i]+AB[j][1]
      else:
        nums[i+AB[j][0]]=nums[i]+AB[j][1]
      
anss=[]
for i in range(H, 20000):
  if nums[i]>0:
    anss.append(nums[i])
    
print(min(anss))
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
import numpy as np
N=int(input())
l=[i+1 for i in range(N)]
P=np.array(list(map(int, input().split())))
Q=np.array(list(map(int, input().split())))
counter=0
for t in permutations(l):
  tmp=np.array(t)
  if all(P==tmp):
    a=counter
    
  if all(Q==tmp):
    b=counter
    
  counter+=1
  
print(abs(a-b))

Fixed submission:
from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))

Buggy python submission (verdict: Runtime Error):
from itertools import permutations
import numpy as np
N=int(input())
l=[i+1 for i in range(N)]
P=np.array(list(map(int, input().split())))
Q=np.array(list(map(int, input().split())))
counter=0
for t in permutations(l):
  tmp=np.array(t)
  if sum(P==tmp)==N:
    a=counter
    
  if sum(Q==tmp)==N:
    b=counter
    
  counter+=1
  
print(abs(a-b))

Fixed submission:
from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
import numpy as np
N=int(input())
l=[i+1 for i in range(N)]
P=np.array(list(map(int, input().split())))
Q=np.array(list(map(int, input().split())))
counter=0
for t in permutations(l):
  tmp=np.array(t)
  if sum(P==tmp)==N:
    a=counter
    
  if sum(Q==tmp)==N:
    b=counter
    
  counter+=1
  
print(abs(a-b))

Fixed submission:
from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))
Buggy python submission (verdict: Runtime Error):
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/C-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])
  
if c>M:
  print(0)
else:
  print(int((M/C-1)/2)+1)

Fixed submission:
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/c-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

def f(x):
  out=0
  while x%2==0:
    out+=1
    x//=2
  return out

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])
  
p=[f(a[i]) for i in range(N)]
p.sort()
for i in range(N-1):
  if p[i]!=p[i+1]:
    print(0)
    exit()
    
if c>M:
  print(0)
else:
  print(int((M/c-1)/2)+1)

Buggy python submission (verdict: Runtime Error):
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

p=func(b[0], b[1])
for i in range(2, N):
  p=func(p, b[i])
  
if M-p<0:
  print(0)
else:
  print((M-p)//(2*p)+1)

Fixed submission:
import fractions
def func(x, y):
  tmp=fractions.gcd(x, y)
  return x*y//tmp

N, M=map(int, input().split())
if N==1:
  a=int(input())
  c=a//2
  if c>M:
    print(0)
  else:
    print(int((M/c-1)/2)+1)
  exit()

a=list(map(int, input().split()))
b=[a[i]//2 for i in range(N)]

def f(x):
  out=0
  while x%2==0:
    out+=1
    x//=2
  return out

c=func(b[0], b[1])
for i in range(2, N):
  c=func(c, b[i])
  
p=[f(a[i]) for i in range(N)]
p.sort()
for i in range(N-1):
  if p[i]!=p[i+1]:
    print(0)
    exit()
    
if c>M:
  print(0)
else:
  print(int((M/c-1)/2)+1)
Buggy python submission (verdict: Runtime Error):
MOD=10**9+7

N=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Fixed submission:
MOD=10**9+7

N=int(input())
if N==1:
  C=int(input())
  print(2*C%MOD)
  exit()
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7

N=int(input())
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
for i in range(N):
  out+=(pow(2, N-1)+pow(2, N-2)*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))

Fixed submission:
MOD=10**9+7

N=int(input())
if N==1:
  C=int(input())
  print(2*C%MOD)
  exit()
C=list(map(int, input().split()))
C.sort(reverse=True)
out=0
tmp1=pow(2, N-1, MOD)
tmp2=pow(2, N-2, MOD)
for i in range(N):
  out+=(tmp1+tmp2*i)*C[i]
  out%=MOD
  
out=out*pow(2, N, MOD)
print(int(out%MOD))
Buggy python submission (verdict: Runtime Error):
MOD=10**9+7
N=int(input())
A=list(map(int, input().split()))
huts=[0]*3
out=1
for i in range(N):
  out*=huts.count(A[i])
  huts[huts.index(A[i])]+=1
print(out%MOD)

Fixed submission:
MOD=10**9+7
N=int(input())
A=list(map(int, input().split()))

huts=[0, 0, 0]
out=1
for i in range(N):
  out*=huts.count(A[i])
  if out==0:
    print(0)
    exit()
  huts[huts.index(A[i])]+=1
print(out%MOD)
Buggy python submission (verdict: Runtime Error):
N=int(input())
ab=[list(map(int, input().split())) for i in range(N-1)]
link=[[] for i in range(N+1)]
for i in range(0, N-1):
  link[ab[i][0]].append([ab[i][1], i])
  link[ab[i][1]].append([ab[i][0], i])
  
out=[0]*(N-1)
def f(num, prenum=0, prec=0):
  postc=1
  for postnum, linknum in link[num]:
    if postnum==prenum:
      continue
    if postc==prec:
      postc+=1
      
    out[linknum]=postc
    f(postnum, num, postc)
    postc+=1
    
f(1)

print(max(out))
for i in range(N-1):
  print(out[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N=int(input())
ab=[list(map(int, input().split())) for i in range(N-1)]
link=[[] for i in range(N+1)]
for i in range(0, N-1):
  link[ab[i][0]].append([ab[i][1], i])
  link[ab[i][1]].append([ab[i][0], i])
  
out=[0]*(N-1)
def f(num, prenum=0, prec=0):
  postc=1
  for postnum, linknum in link[num]:
    if postnum==prenum:
      continue
    if postc==prec:
      postc+=1
      
    out[linknum]=postc
    f(postnum, num, postc)
    postc+=1
    
f(1)

print(max(out))
for i in range(N-1):
  print(out[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N=int(input())
l=[list(map(int, input().split())) for i in range(N-1)]

net=np.zeros((N+1, N+1))
for i in range(N-1):
  net[l[i][0], l[i][1]]=1
  
net=net+net.T
num_c=np.max(np.sum(net, axis=1))

print(int(num_c))

c_net=np.zeros((N+1, N+1, num_c))
for i in range(N-1):
  a=l[i][0]
  b=l[i][1]
  
  j=0
  while np.sum(c_net[a, :, j]==1)>0 or np.sum(c_net[b, :, j]==1)>0:
    j+=1
    if j>=num_c-1:
      break
    
  c_net[a, b, j]=1
  c_net[b, a, j]=1
  print(j+1)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N=int(input())
ab=[list(map(int, input().split())) for i in range(N-1)]
link=[[] for i in range(N+1)]
for i in range(0, N-1):
  link[ab[i][0]].append([ab[i][1], i])
  link[ab[i][1]].append([ab[i][0], i])
  
out=[0]*(N-1)
def f(num, prenum=0, prec=0):
  postc=1
  for postnum, linknum in link[num]:
    if postnum==prenum:
      continue
    if postc==prec:
      postc+=1
      
    out[linknum]=postc
    f(postnum, num, postc)
    postc+=1
    
f(1)

print(max(out))
for i in range(N-1):
  print(out[i])
Buggy python submission (verdict: Runtime Error):
print((int(input)-1)//2)

Fixed submission:
print((int(input())-1)//2)
Buggy python submission (verdict: Runtime Error):
S=input()
n=len(S)

def sums(a):
  return (a+1)*a//2

def f(s):
  n=len(s)
  i=0
  while i<n and s[i]=='<':
    i+=1
  if i==n:
    return sums(i)
  else:
    j=i+1
    while j<n and s[j]=='>':
      j+=1
    if i>(j-i):
      temp=sums(i)+sums(j-i-1)
    else:
      temp=sums(j-i)+sums(i-1)
      
    if j<n:
      temp+=f(s[j:])
      
    return temp

if S[0]=='<':
  ans=f(S)
else:
  i=0
  while i<n and S[i]=='>':
    i+=1
    
  if i==n:
    ans=sums(i)
  else:
    ans=sums(i)+f(S[i:])
    
print(ans)

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

def f(a):
  return a*(a+1)//2

ans=0
i=0
if S[i]=='>':
  while i<n and S[i]=='>':
    i+=1
    
  ans+=f(i)
  
while i<n:
  j=i+1
  while j<n and S[j]=='<':
    j+=1
    
  if j==n:
    ans+=f(j-i)
    i=j+1
  else:
    k=j+1
    while k<n and S[k]=='>':
      k+=1
      
    if j-i>k-j:
      ans+=f(j-i)+f(k-j-1)
    else:
      ans+=f(j-i-1)+f(k-j)
      
    i=k
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)

Fixed submission:
import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

C=[[-A[i]*F[i], A[i], F[i]] for i in range(N)]

heapq.heapify(C)

for _ in range(K):
  tmp=heapq.heappop(C)
  if tmp[1]==0:
    print(0)
    exit()
    
  a=tmp[1]-1
  heapq.heappush(C, [-a*tmp[2], a, tmp[2]])
  
tmp=heapq.heappop(C)
print(-tmp[0])

Fixed submission:
import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

C=[[-A[i]*F[i], A[i], F[i]] for i in range(N)]

heapq.heapify(C)

for _ in range(K):
  tmp=heapq.heappop(C)
  a=max(tmp[1]-1, 0)
  heapq.heappush(C, [-a*tmp[2], a, tmp[2]])
  
tmp=heapq.heappop(C)
print(-tmp[0])

Fixed submission:
import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)