Harryxun/stf_run huggingface dataset:
n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
z.sort()
pq_pattern = []
pq_counter = [1]*(n-1)

for i in range(n-1):
    #print([z[i+1][0] - z[i][0], z[i+1][1] - z[i][1]])
    if [z[i+1][0] - z[i][0], z[i+1][1] - z[i][1]] in pq_pattern:
        #print("YES!")
        pq_counter[pq_pattern.index([z[i+1][0] - z[i][0], z[i+1][1] - z[i][1]])] += 1
    else:
        pq_pattern.append([z[i+1][0] - z[i][0], z[i+1][1] - z[i][1]])
print(n - max(pq_counter))
#print(pq_counter)
#print(pq_pattern)
#print(z)


### FIXED CODE ###

import sys
import collections
n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
z.sort()
pq_pattern = []
pq_counter = [1]*(n-1)*n

if n == 1:
    print(1)
    sys.exit()

for i in range(n):
    for j in range(n):
        if not i == j:
            if [z[j][0] - z[i][0], z[j][1] - z[i][1]] in pq_pattern:
                #print("YES!")
                pq_counter[pq_pattern.index([z[j][0] - z[i][0], z[j][1] - z[i][1]])] += 1
            else:
                pq_pattern.append([z[j][0] - z[i][0], z[j][1] - z[i][1]])
print(n-max(pq_counter))
n = input()
A = list(map(int, input().split()))

_ = 0
while all(a % 2 == 0 for a in A):
    A = [i/2 for i in A]
    _ += 1
print(_)


### FIXED CODE ###

a = 0
s = input()
for i in s:
    if i == '1':
        a = a + 1
print(a)
s=int(input())
print(s //60*60 +':'+s //60%60+':'s//60%60)


### FIXED CODE ###

S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 60
print(str(h)+":"+str(m)+":"+str(s))
import fractions
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(set(a))
n=len(a)
#print(a)
for i in range(n):
    a[i]=a[i]//2
f2=1
f=a[0]
for i in range(n):
    f=fractions.gcd(f,a[i])
for i in range(n):
    f2*=a[i]
f2=f2//(f*(n-1))
ans=0
for i in range(n):
    if f2/a[i]%2!=1:
        print(ans)
        break
else:
    ans=m//f2
    print((ans+1)//2)

### FIXED CODE ###

import fractions
from functools import reduce
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=a[i]//2
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
f2=lcm_list(a)

ans=0
for i in range(n):
    if f2//a[i]%2!=1:
        print(ans)
        break
else:
    ans=m//f2
    print((ans+1)//2)
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

X,N = I()
p = l()
p.sort()
for i in range(N):
    if p[i] > X:
        if abs(p[i]-X) > abs(p[i-1]-X):
            print(p[i-1])
            exit()
        else:
            print(p[i])
            exit()
print(p[-1])

### FIXED CODE ###

import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
import bisect
X,N = I()
if N == 0:
    print(X)
    exit()
p = l()
A = [i for i in range(-1,102)]
for i in range(N):
    if p[i] in A:
        A.remove(p[i])
i = bisect.bisect_left(A,X)
if abs(A[i-1]-X) > abs(A[i]-X):
    print(A[i])
else:
    print(A[i-1])
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
C = []
for i in range(1,N):
  B.append(gcd(A[0],A[i]))
  C.append(gcd(A[1],A[i]))
B.sort()
C.sort()
print(B[1],C[1])


### FIXED CODE ###

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
C = [A[N-1]]
for i in range(1,N):
  B.append(gcd(A[i],B[i-1]))
  C.append(gcd(A[N-i-1],C[i-1]))
D = [C[N-2]]
for j in range(N-2):
  D.append(gcd(B[j],C[N-j-3]))
D.append(B[N-2])
print(max(D))
#!/usr/bin/env python
# -*- coding: utf-8 -*-

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    print(ans, x, idx)
    if idx == 1:
        return ans + (0, 0, 1, 2, 3, 3, 3)[x] + [0, 1][cnt >= 1]
    if x == (al[idx] // 2) + 1:
        return ans + bl[idx - 1] + 1 + [0, 1][cnt >= 1]
    elif x > (al[idx] // 2) + 1:
        ans += bl[idx - 1]
        x -= (al[idx] // 2)
        cnt += 1
    return solve2(ans, x, idx - 1, cnt)


def solve():
    n, x = map(int, input().split())
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    if idx == 1:
        if x >= 5:
            return ans + 3
        return ans + (0, 0, 1, 2, 3, 3)[x]
    if x >= al[idx - 1] + 1:
        ans += bl[idx - 1]
        x -= al[idx - 1] + 1
        if x >= 1:
            ans += 1
            x -= 1
    else:
        x -= 1
        if x <= 0:
            return ans
    return solve2(ans, x, idx - 1, cnt)


def solve(n, x):
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    n, x = map(int, input().split())
    solve(n, x)
import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))

Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if A.count(0)!=1:
    print(0)
  else:
    for ch_n in range(1,(N-1)//2+1):
      if A.count(ch_n*2)!=2:
        break
      else:
        A.remove(ch_n*2)
        A.remove(ch_n*2)
    else:
      #exp=(N-1)//2
      
      #exp_quotient_32=exp//32
      #exp_rem_32=exp%32
      #Rem_ans_Devide_N=1
      #for _ in range(exp_quotient_32):
      #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)
else:
  for ch_n in range(1,N//2+1):
    if A.count(ch_n*2-1)!=2:
      break
    else:
      A.remove(ch_n*2-1)
      A.remove(ch_n*2-1)
  else:
    #exp=N//2
    
    #exp_quotient_32=exp//32
    #exp_rem_32=exp%32
    #Rem_ans_Devide_N=1
    #for _ in range(exp_quotient_32):
    #  Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    #print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    #sys.exit()
  print(0)




### FIXED CODE ###

import sys
input=sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
A.sort()
Devide_N=10**9+7
Rem_2_32_DN=(2**32)%Devide_N

if N%2==1:
  if (A[0]!=0 or A[1]==0 if N>2 else A[0]!=0):
    print(0)

  else:
    del A[0]
    for ch_n in range(1,(N-1)//2+1):
      if A[0]!=ch_n*2 or A[1]!=ch_n*2:
        break
      else:
        del A[0:2]
    else:
      exp=(N-1)//2
      
      exp_quotient_32=exp//32
      exp_rem_32=exp%32
      Rem_ans_Devide_N=1
      for _ in range(exp_quotient_32):
        Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
        
      print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
      sys.exit()
    print(0)

else:
  for ch_n in range(1,N//2+1):
    if A[0]!=ch_n*2-1 or A[1]!=ch_n*2-1:
      break
    else:
      del A[0:2]
  else:
    exp=N//2
    
    exp_quotient_32=exp//32
    exp_rem_32=exp%32
    Rem_ans_Devide_N=1
    for _ in range(exp_quotient_32):
      Rem_ans_Devide_N=(Rem_ans_Devide_N*Rem_2_32_DN)%Devide_N
      
    print((Rem_ans_Devide_N*2**(exp_rem_32))%Devide_N)
    sys.exit()
  print(0)
N = int(input())
A = list(map(int,input().split()))
import fractions
X = A[0]
for i in range(1, N):
    X = X * A[i] // fractions.gcd(X, A[i])

output = 0
for i in range(N):
    output += int(X/A[i])
    if output > 10**9+7:
        output = output % (10**9+7)
print(output)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

import fractions

X = A[0]
for i in range(1, N):
    X = X*A[i] // fractions.gcd(X, A[i])

output = 0
D =10**9+7
X = X%D

for i in range(N):
    output += X*pow(A[i],D-2,D)%D
    output = output % (10**9+7)
print(int(output))
print(( N // X + 1 ) * T )


### FIXED CODE ###

N, X, T = map(int,input().split())

A = N % X

if ( A ) == 0:
    print(( N // X ) * T )
elif ( N % X ) != 0:
    print(( N // X + 1 ) * T )
k,s = map(int,input().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        z = s-x-y
        if z>=0 and z<=k:
            count += 1

print(count)

### FIXED CODE ###

k,s = map(int,input().split())

count = 0
for i in range(k+1):
    for j in range(k+1):
        z = s-i-j
        if z>=0 and z<=k:
            count += 1

print(count)
a, b, c,= map(int, input().split())
n = 0
if a = 1:
  n = n + 1
elif b = 1:
  n = n + 1
elif c = 1:
  n = n + 1
print(n)

  

### FIXED CODE ###

print(input().count("1"))
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
C.sort()
 
ans = 0
for i in range(n):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    ans += a*(N-c)
print(ans)

### FIXED CODE ###

import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort()
C.sort()
 
ans = 0
for i in range(N):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    ans += a*(N-c)
print(ans)
N = int(input())
A = list(map(int,input().split()))
if A[0] == A[1]:
    pre = 0
elif A[0] > A[1]:
    pre = -1
else:
    pre = 1
prevalue = A[1]
ans = 0
for a in A[2:]:
    if a > prevalue:
        if pre == -1:
            ans += 1
            pre = 0
        else:
            pre = 1
    elif a < prevalue:
        if pre == 1:
            ans += 1
            pre = 0
        else:
            pre = -1
    prevalue = a
print(ans+1)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
if N == 1:
    print(1)
else:
    if A[0] == A[1]:
        pre = 0
    elif A[0] > A[1]:
        pre = -1
    else:
        pre = 1
    prevalue = A[1]
    ans = 0
    for a in A[2:]:
        if a > prevalue:
            if pre == -1:
                ans += 1
                pre = 0
            else:
                pre = 1
        elif a < prevalue:
            if pre == 1:
                ans += 1
                pre = 0
            else:
                pre = -1
        prevalue = a
    print(ans+1)
h,w = map(int,input(),split())
for i in range(h):
    a = input().split()
    if "snuke" in a:
        ans = chr(ord('A') + j)+str(i)

print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = [list(input().split()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == 'snuke':
            print(chr(ord('A') + j) + str(1 + i))
            break
N = int(input())
X = list(map(int, input().split()))
total = 0
p = []
for i in range(min(X),max(X)):
    for j in X:
        total += (i-j)**2
    p.append(total)
    total =0

print(min(p))

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
total = 0
p = []
for i in range(min(X),max(X)+1):
    for j in X:
        total += (i-j)**2
    p.append(total)
    total = 0

print(min(p))
H, W = map(int, input().split())
while true:
 if H ==0 and W == 0:
  break
 for h in range(H):
  if h%2 == 0:
   print("#."*(W//2) + "#"*(W%2))
  else:
   print(".#"*(W//2) + "."*(W%2))
 print()

 H, W = map(int, input().split())

### FIXED CODE ###

H, W = map(int, input().split())
while True:
 if H == 0 and W == 0:
  break
 for h in range(H):
  if h%2 == 0:
   print("#."*(W//2) + "#"*(W%2))
  else:
   print(".#"*(W//2) + "."*(W%2))
 print()

 H, W = map(int, input().split())
N = int(input())
L = list(map(int,input().strip().split()))
L_sort = L.sort()
count = 0
for i in range(N-2):
	for j in range(i+1 , N):
    	for k in range(j+1 , N):
        	if L_sort(i) + L_sort(j) > L_sort(k):
            	count += 1
print(count)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))

L.sort()
count = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):             
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            if L[i] + L[j] > L[k]:
                count += 1

print(count)
_,a=open(0)
c=1
d=[3]+[0]*10**6
for a in map(int,a.split()):
  c=c*dp[a]%(10**9+7)
  d[a]-=1
  d[a]+=1
print(c)

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
c=1
d=[0]*3
for b in a:
  c=c*sum(t==b for t in d)%(10**9+7)
  for i,t in enumerate(d):
    if t==b:
      d[i]+=1
      break
print(c)
n,k = map(int,input().split())

A = list(map(int,input().split()))
t = 0
c = 0
ans = [0] * n
L = []
for _ in range(k):
    if ans[t] == 1:
        t += k%c
        t = L[t]
        break
    else:
        ans[t] = 1
        L.append(t)
        print(L)
        t = A[t]-1
        c += 1

print(t+1)

### FIXED CODE ###

n,k = map(int,input().split())

A = list(map(int,input().split()))
t = 0
c = 0
ans = [0] * n
L = []
s = 0
for _ in range(k):
    if ans[t] == 1:
        n = len(L) - L.index(t)
        temp = (k-c)%n
        t = L[L.index(t):][temp]
        break
    else:
        ans[t] = 1
        L.append(t)
        t = A[t]-1
        c += 1
print(t+1)
import sys
si = sys.stdin.readline


def main():
    n = int(si())
    ans = [0 for _ in range(n+1)]
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                v = ((x+y+z)**2+x**2+y**2+z**2)//2
                if v > 10000:
                    break
                ans[v] += 1

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


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from itertools import permutations as pm
from math import factorial as fact
si = sys.stdin.readline


def main():
    ans = dict()
    n = int(si())
    for x in range(1, 100):
        for y in range(x, 100):
            for z in range(y, 100):
                value = ((x+y+z)**2+x**2+y**2+z**2)//2
                if value > 10000:
                    break
                if x == y and y == z:
                    cases = 1
                elif x != y and y != z and z != x:
                    cases = 6
                else:
                    cases = 3
                if value in ans:
                    ans[value] += cases
                else:
                    ans[value] = cases

    for i in range(1, n+1):
        if i in ans:
            print(ans[i])
        else:
            print(0)


if __name__ == '__main__':
    main()
スコード 

Copy
Copy
# a<=bとみなせるので探索回数は√nでよい
import math
n = int(input())
r_n = int(math.sqrt(n))+1
m = 10 ** 12
for i in range(1,r_n):
  if n % i == 0 and m > i + n / i - 2:
    m = i + n / i - 2
 
print(int(m))

### FIXED CODE ###


# a<=bとみなせるので探索回数は√nでよい
import math
n = int(input())
r_n = int(math.sqrt(n))+1
m = 10 ** 12
for i in range(1,r_n):
  if n % i == 0 and m > i + n / i - 2:
    m = i + n / i - 2
 
print(int(m))
def f(x):
    if dp[x] != -1:
        return dp[x]

    t = 0
    for v in V[x][1]:
        t = max(t, f(v)+1)

    dp[x] = t
    return dp[x]

n, m = map(int, input().split())

dp = [-1]*(n+1)
V = [[i, []] for i in range(n+1)]

for i in range(m):
    x, y = map(int, input().split())
    V[x][1].append(y)

t = 0
for i in range(1, n+1):
    t = max(t, f(i))
print(t)


### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n, m = map(int, input().split())

dp = [-1 for _ in range(n)]
V = [[] for _ in range(n)]

for _ in range(m):
    x, y = map(int, input().split())
    V[x-1].append(y-1)

def f(x):
    if dp[x] != -1:
        return dp[x]

    t = 0
    for v in V[x]:
        t = max(t, f(v)+1)

    dp[x] = t
    return dp[x]

t = 0
for i in range(n):
    t = max(t, f(i))

print(t)
X=int(input())
N=10**3
i=-10
res=[]

while(i<N):
  j=-10
  while(j<N):
    if(i**5 - j**5==X):
      res.append(i)
      res.append(j)
      break
    j+=1
  if(1<len(res)):
    break
  i+=1

print(str(res[0])+" " +str(res[1]))

### FIXED CODE ###

X=int(input())
N=10**3
i=-1000
res=[]

while(i<N):
  j=-1000
  while(j<N):
    if(i**5 - j**5==X):
      res.append(i)
      res.append(j)
      break
    j+=1
  if(1<len(res)):
    break
  i+=1

print(str(res[0])+" " +str(res[1]))
a=str(input())
b=str(input())

ans=[]
ans.append(len(b))
for i in range(len(a)-len(b)+1):
    dif=0
    k=a.find(b[i])
    for j in range(len(b)):
        if a[i+j]!=b[j]:
            dif+=1
            ans.append(dif)
print(min(ans))

### FIXED CODE ###

D,T,S=map(int,input().split())
if D/S<=T:
  print("Yes")
else:
  print("No")
n = int(input())
ret = [0 for _ in range(1,21)]
def f(x,y,z):
	return x*x + y*y + z*z + x*y + y*z + x*z

for x in range(1,n+1):
	for y in range(1,n+1):
		for z in range(1,n+1):
			if f(x,y,z) > n:
				z = 1
				break
			ret[f(x,y,z)-1] += 1
		if f(x,y,z) > n:
			y = 1
			break
	if f(x,y,z) > n:
		x = 1
		break

for i in ret:
	print(i)

### FIXED CODE ###

n = int(input())
ret = [0 for _ in range(1,n+1)]
def f(x,y,z):
	return x*x + y*y + z*z + x*y + y*z + x*z

for x in range(1,n+1):
	for y in range(1,n+1):
		for z in range(1,n+1):
			if f(x,y,z) > n:
				z = 1
				break
			ret[f(x,y,z)-1] += 1
		if f(x,y,z) > n:
			y = 1
			break
	if f(x,y,z) > n:
		x = 1
		break

for i in ret:
	print(i)
n = int(input())
l = list(map(int,input().split()))

count = 0

while True:
  for i in n:
    if l[i]%2 == 0:
      l[i]//2
    else:
      print(count)
      exit()
  count += 1
  

### FIXED CODE ###

n = int(input())
l=list(map(int,input().split()))
count=0
while True:
    for i in range(n):
        if l[i]%2==0:
            l[i]=l[i]//2
        else:
            print(count)
            exit()
    count+=1
a,b,c,x,y = map(int, input().split())
kei = 0
if c > a/2 + b/2:
    kei = a * x + b*y

elif c*2 =< a+ b and a >= c*2 and b >= c*2:
    kei += c * (min(x,y)*2)
    if x > y:
        kei += c * ((x - y)*2)
    else:
        kei += c * ((y - x)*2)

elif c =< a/2 + b/2:
    kei += c * (min(x,y)*2)
    if x > y:
        kei += a * (x -y)
    else:
        kei += b *(y-x)


print(kei)

### FIXED CODE ###

a,b,c,x,y = map(int, input().split())
kei = 0
if c >= a/2 + b/2:
    kei = a * x + b*y

elif c*2 <= a+ b and a >= c * 2 and x > y:
    kei += c * (min(x,y)*2)
    kei += c * ((x - y)*2)

elif c*2 <= a+ b and b >= c * 2 and x < y:
    kei += c * (min(x,y)*2)
    kei += c * ((y - x)*2)

elif c <= a/2 + b/2:
    kei += c * (min(x,y)*2)
    if x > y:
        kei += a * (x -y)
    else:
        kei += b *(y-x)


print(kei)
import sys
input = sys.stdin.readline
import numpy as np
N,W=map(int,input().split())
max_Vi = 10**3
max_Wi = W
dp=[max_Wi+1]*(N*max_Vi+1)
dp[0]=0
for i in range(N):
  wi,vi=map(int,input().split())
  dp[vi:]=np.minimum(dp[vi:],dp[:-vi]+wi)
print(np.max(np.where(dp <= W)))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
N,W=map(int,input().split())
dp=np.ones(10**5+1, dtype='int64')
dp[0]=0
dp[1:]=dp[1:]*(10**9+1)
for i in range(N):
  wi,vi=map(int,input().split())
  dp[vi:]=np.minimum(dp[vi:],dp[:-vi]+wi)
print(np.max(np.where(dp <= W)))
data = input()

flag1 = 0
flag2 = 0

for i in range(3):
  if data[i] = '5':
    flag1 += 1
  elif data[i] = '7':
    flag2 += 1

if flag1 == 1 and flag2 == 2:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

data = input().split()
 
flag1 = 0
flag2 = 0
 
for i in range(3):
  if data[i] == '5':
    flag1 += 1
  elif data[i] == '7':
    flag2 += 1
 
if flag1 == 2 and flag2 == 1:
  print('YES')
else:
  print('NO')
n,k=map(int,input().split())
if n>k and k>1:
    val=n-k
    print(n%val)
elif n>k and k==1:
	print(0)
else:
    val=k-n
    print(k%val)


### FIXED CODE ###

n,k=map(int,input().split())

if k==1:
    print(0)
elif n>k:
    print(k-(n%k))
else:
    val=k-n
    if n<val:
        print(n)
    else:
        print(val)
n,k = map(int, input().split())
li = []
i = 0
for i<k:
  li.append(int(input()))
  i += 1
else:
  Li = list(n)
  while li&Li:
    n += 1
    Li = list(n)
  else: print("".join(Li))

### FIXED CODE ###

n,k = map(str, input().split())
li = list(map(str, input().split()))
Li = list(n)
while len(set(Li)&set(li)):
  n = int(n)+1
  Li = list(str(n))
else: print("".join(Li))
A,B,C,K = map(int, input().split())
if A >= K:
	print(K)
	return
K -= A
if B >= K:
	print(A)
	return
K -= B
print(A - K)

### FIXED CODE ###

A,B,C,K = map(int, input().split())
if A >= K:
	print(K)
	exit()
K -= A
if B >= K:
	print(A)
	exit()
K -= B
print(A - K)
M = input().split()
i = 0
a = None
b = None
for i in range(int(M[0])):
    a += str(M[1])
alfa = int(a)
for i in range(M[1]):
    b += str(M[0])
beta = int(b)
delta = min(a,b)
print(delta)

### FIXED CODE ###

M = input().split()
i = 0
a = ''
b = ''
c = [0,0]
for i in range(int(M[0])):
    a += str(M[1])
for i in range(int(M[1])):
    b += str(M[0])
c[0] = int(a)
c[1] = int(b)  
c.sort()
print(str(c[1]))
import numpy as np
from collections import deque
n=int(input())
edge=np.array(list(list(map(int,input().split())) for _ in range(n-1)))
color=np.zeros(n-1)
d=deque()


s=1
d.append(s)
while d:
  c=1
  s=d.popleft()
  check=[]
  seen=[]
  for i in range(n-1):
    if s in edge[i]:
      e=edge[i][edge[i]!=s]
      if color[i]==0:
        d.append(e[0])
        check.append(i)
      else:
        seen.append(color[i])
  for j in check:
    if c not in seen:
      color[j]=c
      c+=1
    else:
      while c in seen:
        c+=1
      color[j]=c
      c+=1
print(int(max(color)))
print(" ".join(list(map(lambda x: str(int(x)), color))))        
    


### FIXED CODE ###

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[[] for _ in range(n)]
k=0
used=[-1]*n
seen=[-1]*n
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])
    k=max(k,len(node[pair[0]]),len(node[pair[1]]))
print(k)
ans={}
d=deque()
d.append(0)
while d:
    i=d.pop()
    seen[i]=1
    res=1
    for j in node[i]:
        if seen[j]==1:
            continue
        d.appendleft(j)
        if res!=used[i]:
            ans[(i,j)]=res
        else:
            res+=1
            ans[(i,j)]=res
        used[j]=res
        res+=1
for pair in v:
    a,b=pair
    if (a,b) in ans:
        print(ans[(a,b)])
    else:
        print(ans[(b,a)])