Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k == 1:
    print(0)
elif k == 2:
    if n % 2 == 0:
        print(0)
    else:
        print(1)
elif k == 3:
    if n%3 == 0:
        print(0)
    elif n%3 == 1:
        print(1)
    else:
        print(1)
elif k == 4:
    if n%4 == 0:
        print(0)
    elif n%4 == 1:
        print(1)
    elif n%4 == 2:
        print(2)
    else:
        print(1)
elif k == 5:
    if n%5 == 0:
        print(0)
    elif n%5 == 1:
        print(1)
    elif n%5 == 2:
        print(2)
    elif n%5 == 3:
        print(2)
    else:
        print(1)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k == 1:
    print(0)
elif k == 2:
    if n % 2 == 0:
        print(0)
    else:
        print(1)
elif k == 3:
    if n%3 == 0:
        print(0)
    elif n%3 == 1:
        print(1)
    else:
        print(2)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k == 1:
    print(0)
elif k == 2:
    if n % 2 == 0:
        print(0)
    else:
        print(1)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if k == 1:
    print(0)
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

while n > k:
    n = n-k
if n < k-n:
    print(n)
else:
    print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
        
else:
    while n > k:
        n = n-k
    if n < k-n:
        print(n)
    else:
        print(k-n)

Fixed submission:
n, k = map(int, input().split())
if n < k:
    if n < k-n:
        print(n)
    else:
        print(k-n)
else:
    n = n%k
    if n < k-n:
        print(n)
    else:
        print(k-n)