Buggy python submission (verdict: Time Limit Exceeded):
import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
while True:
    b = abs(n-k)
    if b == 0:
        print(0)
        sys.exit()
    elif b == 1:
        print(1)
        sys.exit()
    elif n < b:
        print(n)
        sys.exit()
    n = b

Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    b = abs(n-k)
    if b == 0:
        print(0)
        sys.exit()
    elif b == 1:
        print(1)
        sys.exit()
    elif n < b:
        print(n)
        sys.exit()
    n = b
    min_N(n, k)

min_N(n, k)

Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    a = n
    while True:
        b = abs(a-k)
        if b == 0:
            print(0)
            sys.exit()
        elif b == 1:
            print(1)
            sys.exit()
        elif a < b:
            print(a)
            sys.exit()
        a = b
    print(a)
    sys.exit()
    
min_N(n, k)

Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif m == 0:
        print(0)
        sys.exit
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        
abs_N(n, k)


Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif m == 0:
        print(0)
        sys.exit
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        
abs_N(n, k)


Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        

abs_N(n, k)


Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        

abs_N(n, k)


Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

Buggy python submission (verdict: Runtime Error):
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        

abs_N(n, k)


Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

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


if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    a = n
    while True:
        b = abs(a-k)
        if a < b:
            print(a)
            sys.exit()
        elif b == 1:
            print(1)
            sys.exit()
        a = b
    print(a)
    sys.exit()
    
min_N(n, k)

Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))

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


if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    a = n
    while True:
        b = abs(a-k)
        if a < b:
            break
        elif b == 1:
            print(1)
            sys.exit()
        a = b
    print(a)
    sys.exit()
    
min_N(n, k)

Fixed submission:
import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))