Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)

Buggy python submission (verdict: Runtime Error):
import math as m
def lcm(a,b):
    return (a*b)//m.gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)


Fixed submission:
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)

Buggy python submission (verdict: Runtime Error):
import math as m
def lcm(a,b):
    return (a*b)//m.gcd(a,b)
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l/i)
print(int(s%1000000007))

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)

Buggy python submission (verdict: Runtime Error):
import math as m
def lcm(a,b):
    return (a*b)//m.gcd(a,b)
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l/i)
print(int(s%1000000007))

Fixed submission:
from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
input()
a=[int(i) for i in input().split()]
l=a[0]
for i in a:
    l=lcm(i,l)
s=0
for i in a:
    s+=(l//i)
print(s%1000000007)
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    if N-K+1-i<0:
        print(0)
    else:
        print(int(combinations_count(N-K+1, i)*combinations_count(K-1, i-1)%1000000007))


Fixed submission:
import math
N,K = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

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 = 1000000007
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

for i in range(1,K+1):
    # print(i)
    if N-K+1-i<0:
        print(0)
    else:
        first = int(cmb(N-K+1, i,mod))
        last  = int(cmb(K-1, i-1,mod))
        print((first*last)%mod)

Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

for i in range(1,K+1):
    print(int(combinations_count(N-K+1, i)*combinations_count(K-1, i-1)%1000000007))

Fixed submission:
import math
N,K = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

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 = 1000000007
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

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

for i in range(1,K+1):
    # print(i)
    if N-K+1-i<0:
        print(0)
    else:
        first = int(cmb(N-K+1, i,mod))
        last  = int(cmb(K-1, i-1,mod))
        print((first*last)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

# print(A)
cur = 1
Npush = 0
History = []
while 1:
    History.append(cur)
    cur = A[cur-1]
    Npush+=1
    if cur == 2:
        break
    elif cur in History:
        Npush=-1
        break
    # print(cur)
print(Npush)


Fixed submission:
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

# print(A)
cur = 1
Npush = 0
# History = []
# while 1:
#     History.append(cur)
#     cur = A[cur-1]
#     Npush+=1
#     if cur == 2:
#         break
#     elif cur in History:
#         Npush=-1
#         break
for i in range(N+1):
    cur = A[cur-1]
    Npush += 1
    if cur == 2:
        break
    # print(cur)
if cur==2:
    print(Npush)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())
    ans = 1
    for i in range(1, int(m**0.9)+10):
        if m % i == 0 and m // i >= n:
            ans = max(ans, i)
    print(ans)
    
if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())
    ans = 1
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            if m >= i * n:
                ans = max(ans, i)
            if m >= (m // i) * n:
                ans = max(ans, m // i)
    print(ans)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n=int(input())
k=int(input())
print(n % k)

Fixed submission:
#-*-coding:utf-8-*-

def main():
    n, k = map(int, input().split())

    if n % k == 0:
        print(0)
    else:
        print(1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    r = int(input())
    if r < 2000:
        print('ABC')
    elif r >= 1200 ans r < 2800:
        print('ARC')
    else:
        print('AGC')

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    r = int(input())
    if r < 1200:
        print('ABC')
    elif r >= 1200 and r < 2800:
        print('ARC')
    else:
        print('AGC')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def is_all_odd(lists):
    odd_flag = 1
    for i in lists:
        if i % 2 != 0:
            odd_flag *= 1
        else:
            odd_flag *= 0
    if odd_flag == 1:
        return True
    else:
        return False

def main():
    #入力
    N = int(input())
    a = list(map(int, input().split()))
    print(a)

    #変数
    count = 0

    while not is_all_odd(a):
        devide_flag = 0
        for i in range(N):
            if a[i] % 2 == 0 and devide_flag == 0:
                a[i] = int(a[i]/2) 
                devide_flag = 1
            else:
                a[i] = a[i] * 3
        count += 1
        print(a)
    
    print(count)




if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    #入力
    N = int(input())
    a = list(map(int, input().split()))

    #変数
    count = 0

    for i in a:
        while i % 2 == 0:
            i /= 2
            count += 1 
            
    print(count)
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    s = input()
    K = int(input())

    dict_list = []


    abc_list = 'abcdefghijklmnopqrstuvwxyz'
    
    for abc in abc_list:
        dict_temp = []
        j = 1
        while True:
            for i in range(len(s)):
                if  i + j <= len(s) and s[i] == abc and len(s[i:i+j]) <= K:
                    dict_temp.append(s[i:i+j])
            j += 1
            if j > len(s):
                break
        dict_temp = list(set(dict_temp))
        dict_list += dict_temp
        dict_list.sort()
        if len(dict_list) >= K:
            print(dict_list[K-1])
            break
        
    #print(dict_list)
            

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    s = input()
    K = int(input())

    a = set()

    for i in range(len(s)):
        for j in range(K):
            a.add(s[i:i+j+1])
            if i + j > len(s):
                break
    a_list = list(a)
    a_list.sort()
    print(a_list[K-1])
            

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    s = input()
    K = int(input())

    dict_list = []

    abc_list = 'abcdefghijklmnopqrstuvwxyz'

    for abc in abc_list:
        j = 1
        dict_temp = []
        while True:
            for i in range(len(s)):
                if  i + j <= len(s) and s[i] == abc:
                    dict_temp.append(s[i:i+j])
            j += 1
            if j > len(s):
                break
        dict_temp = list(set(dict_temp))
        dict_temp.sort()
        dict_list += dict_temp
        if len(dict_list) >= K:
            print(dict_list[K-1])
            break
    #print(dict_list)
            

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    s = input()
    K = int(input())

    a = set()

    for i in range(len(s)):
        for j in range(K):
            a.add(s[i:i+j+1])
            if i + j > len(s):
                break
    a_list = list(a)
    a_list.sort()
    print(a_list[K-1])
            

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    A, B, C, X, Y = list(map(int, input().split()))

    dp = [[0 for i in range(Y+1)] for j in range(X+1)]


    
    for i in range(X+1):
        for j in range(Y+1):
            if i == 0 and j > 0:
                dp[i][j] = min(dp[i][j-1]+B, dp[i][j-1]+2*C)
            elif i > 0 and j == 0:
                dp[i][j] = min(dp[i-1][j]+A, dp[i-1][j]+2*C)
            elif i > 0 and j > 0:
                dp[i][j] = min(dp[i-1][j]+A, dp[i-1][j]+2*C, dp[i][j-1]+B, dp[i][j-1]+2*C, dp[i-1][j-1]+2*C)
    
    #for i  in range(X+1):
        #print(dp[i])
        
    print(dp[-1][-1])
                




if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    A, B, C, X, Y = list(map(int, input().split()))

    ABset = 2 * C
    min_price = 0

    #ABsetのほうがA,Bを個別に買うより安い場合
    if ABset <= A + B:
        if X >= Y:
            min_price += ABset * Y
            min_price += min(A * (X - Y), ABset * (X - Y))
        if X < Y:
            min_price += ABset * X
            min_price += min(B * (Y - X), ABset * (Y - X))
    else:
        min_price += A * X + B * Y

    print(min_price)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    N = int(input())
    x_list = list(map(int, input().split()))
    x_sort = x_list[:]
    x_sort.sort()
    med = (N // 2) -1
    threshold = x_sort[med]
    med_dict = {}

    for i in range(N):
        if x_list[i] in med_dict:
            print(med_dict[x_list[i]])
        elif x_list[i] > threshold:
            print(threshold)
        else:
            removed_x_list = x_list[:]
            removed_x_list.remove(x_list[i])
            removed_x_list.sort()
            median = removed_x_list[med]
            med_dict[x_list[i]] = median
            print(median)
    
if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    N = int(input())
    x_list = list(map(int, input().split()))
    x_list_sort = x_list[:]
    x_list_sort.sort()
    med1 = x_list_sort[(N//2)-1]
    med2 = x_list_sort[N//2]
    for i in x_list:
        if i <= med1:
            print(med2)
        elif i >= med2:
            print(med1)
            
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    N = int(input())
    x_list = list(map(int, input().split()))
    med_dict = {}

    med = (N // 2) -1

    for i in x_list:
        if i in med_dict:
            print(med_dict[i])
        else:
            removed_x_list = x_list[:]
            removed_x_list.remove(i)
            removed_x_list.sort()
            median = removed_x_list[med]
            med_dict[i] = median
            print(median)
    #print(med_dict)

    
if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    N = int(input())
    x_list = list(map(int, input().split()))
    x_list_sort = x_list[:]
    x_list_sort.sort()
    med1 = x_list_sort[(N//2)-1]
    med2 = x_list_sort[N//2]
    for i in x_list:
        if i <= med1:
            print(med2)
        elif i >= med2:
            print(med1)
            
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    a, b, k = list(map(int, input().split()))
    cnt = 1

    for i in range(a, b+1):
        if cnt <= k or cnt >= b - a + 2 - k:
            print(i)
        cnt += 1

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    a, b, k = list(map(int, input().split()))
    ab_set = set()
    cnt1 = 1
    cnt2 = 1
    
    for i in range(a, b+1):
        if cnt1 <= k:
            ab_set.add(i)
        else:
            break
        cnt1 += 1
        
    for j in range(b, a-1, -1):
        if cnt2 <= k:
            ab_set.add(j)
        else:
            break
        cnt2 += 1
    
    ab_list = list(ab_set)
    ab_list.sort()
    for i in ab_list:
        print(i)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_set = set(a_list)
    min_cnt = 0
    for i in a_set:
        cnt = a_list.count(i)
        if cnt - i >= 0:
            min_cnt += cnt - i
        else:
            min_cnt += cnt

    print(min_cnt)

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_set = set(a_list)
    cnt = Counter(a_list)

    min_cnt = 0
    for i in a_set:
        if cnt[i] - i >= 0:
            min_cnt += cnt[i] - i
        else:
            min_cnt += cnt[i]

    print(min_cnt)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n, k = map(int, input().split())
    a_list = list(input().split())
    a_set = set(a_list)

    c = Counter(a_list)

    cnt = 0
    for i in range(len(a_set) - k):
        cnt += c.most_common()[::-1][i][1]

    print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-
#from collections import Counter

def main():
    n, k = map(int, input().split())
    a_list = list(input().split())
    a_set = set(a_list)

    #c = Counter(a_list)
    dic = {}
    for i in a_list:
        dic.setdefault(i, 0)
        dic[i] += 1

    freq = sorted(dic.values())

    cnt = 0
    for i in range(len(a_set) - k):
        cnt += freq[i]
        #cnt += c.most_common()[::-1][i][1]

    print(cnt)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    f_list = []
    p_list = []
    #f_list = [list(map(int, input().split())) for i in range(n)]
    #p_list = [list(map(int, input().split())) for i in range(n)]

    for i in range(N):
        tmp=list(map(int, input().split()))
        f_list.append(tmp)
 
    for i in range(N):
        tmp=list(map(int, input().split()))
        p_list.append(tmp)

    max_profit = -10000000

    for i in range(1, 2 ** 10):
        binary = [0] * 10
        now = i 
        for j in range(10):
            binary[j] = now % 2
            now = now // 2
        profit = 0
        for j in range(n):
            one_cnt = 0
            for h in range(10):
                if f_list[j][h] * binary[h] == 1:
                    one_cnt += 1
            profit += p_list[j][one_cnt]
        if max_profit < profit:
            max_profit = profit
    print(max_profit)
    
    
if __name__ == '__main__':
    main()

Fixed submission:
#N,A,B=map(int, input().split())
 
#A=list(map(int, input().split()))
 
N=int(input())
 
F=[]
P=[]
 
for i in range(N):
    tmp=list(map(int, input().split()))
    F.append(tmp)
 
for i in range(N):
    tmp=list(map(int, input().split()))
    P.append(tmp)
 
max_sum=-1000000001
 
for i in range(1,1024):
    bin=[0]*10
    now=i
    for j in range(10):
        bin[j]=now%2
        now=now//2
    ans_sum=0
    for j in range(N):
        ans=0
        for h in range(10):
            if F[j][h]*bin[h]==1:
                ans+=1
        ans_sum+=P[j][ans]
    if max_sum<ans_sum:
        max_sum=ans_sum
 
print(max_sum)
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = []
    for _ in range(n):
        num = int(input())
        if num in a_list:
            a_list.remove(num)
        else:
            a_list.append(num)
    print(len(a_list))


if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = []
    for _ in range(n):
        a_list.append(int(input()))
    
    ans = 0
    cnt = Counter(a_list)
    for i in set(a_list):
        if cnt[i] % 2 != 0:
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b = []

    for i in range(n):
        if i % 2 != 0:
            b.insert(0, a_list[i])
        else:
            b.append(a_list[i])
    if len(a_list) % 2 != 0:
        b = b[::-1]
    print(' '.join(map(str, b)))


if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    p = [a_list[i] for i in range(0, n, 2)]
    q = [a_list[i] for i in range(1, n, 2)]

    if n % 2 == 0:
        print(' '.join(map(str, q[::-1] + p)))
    else:
        print(' '.join(map(str, p[::-1] + q)))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    arry = list(map(int, input().split()))
    i = int(''.join(arry))
    if i % 4 == 0:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    arry = list(input().split())
    i = int(''.join(arry))
    if i % 4 == 0:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())

    ab_list = []
    cd_list = []
    for _ in range(n):
        ab_list.append(list(map(int, input().split())))
    for _ in range(m):
        cd_list.append(list(map(int, input().split())))
    

    for i in ab_list:
        min_distance = 2 * 10 ** 8
        for j in range(m):
            distance = abs(i[0] - cd_list[j][0]) + abs(i[1] - cd_list[j][1])
            if distance < min_distance:
                min_distance = distance
                min_coord = j + 1
        print(min_coord)

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())

    ab_list = []
    cd_list = []
    for _ in range(n):
        ab_list.append(list(map(int, input().split())))
    for _ in range(m):
        cd_list.append(list(map(int, input().split())))
    
    for i in ab_list:
        min_distance = float('inf')
        for j in range(m):
            distance = abs(i[0] - cd_list[j][0]) + abs(i[1] - cd_list[j][1])
            if distance < min_distance:
                min_distance = distance
                min_coord = j + 1
        print(min_coord)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    k, s = map(int, input().split())

    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            for k in range(k+1):
                if i + j + k == s:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    k, s = map(int, input().split())

    ans = 0
    for i in range(k+1):
        for j in range(k+1):
            if 0 <= s - (i + j) <= k:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#-*-coding:utf-8-*-

def main():
    n = int(input())
    arry = [list(map(int, input().split())) for _ in range(n)]
    ans = [arry[0]]
    
    for i in range(1, n):
        a, b = arry[i]
        while True:
            if a >= ans[i-1][0] and b >= ans[i-1][1]:
                ans.append([a, b])
                break
            a += arry[i][0]
            b += arry[i][1]
            
    print(sum(ans[-1]))

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    n = int(input())
    arry = [list(map(int, input().split())) for _ in range(n)]
    ans = [arry[0]]

    for i in range(1, n):
        a, b = arry[i]
        if a >= ans[i-1][0] and b >= ans[i-1][1]:
            ans.append([a, b])
        else:
            num = max(-(-ans[i-1][0] // a), -(-ans[i-1][1] // b))
            a *= num
            b *= num
            ans.append([a, b])
    print(sum(ans[-1]))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#-*-coding:utf-8-*-

def main():
    arry = list(map(int, input().split))
    if arry.count(5) == 2 and arry.count(7) == 1:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Fixed submission:
#-*-coding:utf-8-*-

def main():
    arry = list(map(int, input().split()))
    if arry.count(5) == 2 and arry.count(7) == 1:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
# s_list = [input() for i in range(n)]
s_list = []
for i in range(n):
    s = input()
    if s not in s_list:
        s_list.append(s)
    else:
        pass
    
print(len(s_list))

Fixed submission:
n = int(input())
s_list = [input() for i in range(n)]
print(len(set(s_list)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
import math

if k == 1:
    print(0)
else:
    print(math.gcd(n, k))


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

if k == 1:
    print(0)
elif n < k:
    print(min(abs(n-k), abs(n)))
else:
    num = n // k
    n = n - num * k
    print(min(n, abs(n-k)))