Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
x = list(map(int, input().split()))
lists = []
ind = ((n-1) + 1) // 2
for i in range(n):
    if i == 0:
        ans = x[i + 1:]
        ans.sort()
        lists.append(ans[ind-1])
    else:
        ans = x[0:i] + x[i + 1:]
        ans.sort()
        lists.append(ans[ind - 1])
[print(x) for x in lists]


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)[n//2-1:n//2+1]
for i in x:print(y[i <= y[0]])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
lists = []
ind = ((n-1) + 1) // 2
for i in range(n):
    if i == 0:
        ans = x[i + 1:]
        ans.sort()
        lists.append(ans[ind-1])
    else:
        ans = x[0:i] + x[i + 1:]
        ans.sort()
        lists.append(ans[ind - 1])
tuple_lists = tuple(lists)
[print(x) for x in tuple_lists]


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)[n//2-1:n//2+1]
for i in x:print(y[i <= y[0]])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
lists = []
ind = ((n-1) + 1) // 2
for i in range(n):
    if i == 0:
        ans = x[i + 1:]
        ans.sort()
        lists.append(ans[ind-1])
    else:
        ans = x[0:i] + x[i + 1:]
        ans.sort()
        lists.append(ans[ind - 1])
tuple_lists = tuple(lists)
[print(x) for x in tuple_lists]


Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)[n//2-1:n//2+1]
for i in x:print(y[i <= y[0]])
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
lists = list(range(A,B+1))
ans = []
for i in range(K):
    if i < len(lists):
        ans.append(lists[i])
        ans.append(lists[(len(lists)-1)-i])
    else:
        break
m = set(ans)
lm = sorted(m)
for j in range(len(lm)):
    print(lm[j])

Fixed submission:
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
lists = list(range(A,B+1))
min_list = []
max_list = []
if K > len(lists):
        for m in range(len(lists)):
                print(lists[m])
else:
        for i in range(K):
                min_list.append(lists[i])
        for j in range(K,len(lists)):
                min_list.append(lists[j])
        for k in range(len(min_list)):
                print(min_list[k])

Fixed submission:
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
lists = list(range(A,B+1))
result = list(set(lists[:K] + lists[-K:]))
result.sort()
if K > len(lists):
        for j in range(len(lists)):
                print(lists[j])
else:
        for i in range(len(result)):
                print(result[i])

Fixed submission:
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
lists = list(range(A,B+1))
result = list(set(lists[:K] + lists[-K:]))
result.sort()
if K >= len(lists):
        for j in range(len(lists)):
                print(lists[j])
else:
        for i in range(len(result)):
                print(result[i])

Fixed submission:
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
lists = list(range(A,B+1))
result = list(set(lists[:K] + lists[-K:]))
for i in range(len(result)):
        print(result[i])

Fixed submission:
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(len(lists)):
    print(lists[i])
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
if abs(B-A) < K:
    for i in range(A,B+1):
        print(i)
    exit()
min_list = list(range(A,A+K))
max_list = list(range(B-K+1,B+1))
lists = list(set(min_list) | set(max_list))
lists.sort()
for i in range(lists):
    print(lists[i])

Fixed submission:
import collections
a,b,c = map(int,input().split())
lists = [str(a%2),str(b%2),str(c%2)]
abc = [a,b,c]
an = []
if len(set(lists)) != 1:

    d = collections.Counter(lists)
    jud = int(d.most_common()[0][0])
    for i in range(3):
        if jud == int(lists[i]):
            an.append(i)
    for i in an:
            abc[i] += 1
    cnt = 1
else:
    cnt = 0

while 1:
    Max = max(abc)
    count = 0
    for i in range(3):
        if Max == abc[i]:
            count += 1
    if count == 1:
        cnt += 1
        for i in range(3):
            if Max != abc[i]:
                abc[i] += 1

    elif count == 2:
        cnt += abs(max(abc) - min(abc)) // 2
        abc.sort()
        abc[0] += abs(max(abc) - min(abc))
    elif count == 3:
        break

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
for i in range(len(b) - 1):
    ans = sum(b) - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.deepcopy(a)
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
for i in range(len(b) - 1):
    ans = sum(b) - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.deepcopy(a)
sum = 0
ans = []
for i in range(n):
    sum = 0
    a = copy.deepcopy(a_copy)
    a.pop(i)
    sum += abs(a[0]) + abs(a[-1])
    for j in range(len(a) - 1):
        sum += abs(a[j] - a[j + 1])

    ans.append(sum)
for i in ans:
    print(i)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(str,input().split()))
a.sort()
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)


Fixed submission:
from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(str,input().split()))
a.sort()
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(str,input().split()))
a.sort()
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) == int(i):
        pass
    elif int(a.count(str(i))) > int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)


Fixed submission:
from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = input()
i = 0
while i<4:
    if N[0] == N[i]:
        count = count + 1
        i = i + 1
    else:
        i = i + 1
if count >= 3:
    print("Yes")
elif count <= 3:
    print("No")

Fixed submission:
N = input()
count = 0
if N[0]==N[1]==N[2] or N[1]==N[2]==N[3]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
list_N = list(range(1,N+1))
max = -9999
for i in range(N):
    if max < int(math.sqrt(list_N[i])):
        max = int(math.sqrt(list_N[i]))

print(max*max)

Fixed submission:
import math 
N = int(input())
print(math.floor(math.sqrt(N))**2)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
list_N = list(range(1,N+1))
max = -999999999
sqrt_N = []
for i in range(N):
    if max < int(math.sqrt(list_N[i])):
        max = int(math.sqrt(list_N[i]))

print(max*max)

Fixed submission:
import math 
N = int(input())
print(math.floor(math.sqrt(N))**2)
Buggy python submission (verdict: Runtime Error):
R,G = map(int,input().split())
print(2*G-R)

Fixed submission:
R = int(input())
G = int(input())
print(2*G-R)
Buggy python submission (verdict: Runtime Error):
N = input()
A = input()
print((N*N)-A)

Fixed submission:
N = int(input())
A = int(input())
print(N*N - A)

Buggy python submission (verdict: Runtime Error):
N,A = map(int,input().split())
print((N*N)-A)

Fixed submission:
N = int(input())
A = int(input())
print(N*N - A)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
min = a+b
if min >= a+c:
    min = a+c
elif min >= b+c:
    min = b+c
print(str(min)

Fixed submission:
a,b,c = map(int,input().split())
print(min(a+b,b+c,c+a))
Buggy python submission (verdict: Time Limit Exceeded):
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
n,m = map(int,input().split())
if n == m:
    ans = P(n,n) * P(m,m) * 2
    print(ans)
elif abs(n-m) > 1:
    print(0)
else:
    ans = P(n,n)*P(m,m)
    print(ans)

Fixed submission:
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
n,m = map(int,input().split())
mod = 10**9+7
if n == m:
    ans = P(n,n) * P(m,m) * 2
    print(ans%mod)
elif abs(n-m) > 1:
    print(0)
else:
    ans = P(n,n)*P(m,m)
    print(ans%mod)
Buggy python submission (verdict: Runtime Error):
r=int(input())
g=int(input())
b=int(input())
d=r*100+g*10+b
if d%4==0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r=int(input(""))
g=int(input(""))
b=int(input(""))
d=r*100+g*10+b
if d%4==0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r = int(input(""))
g = int(input(""))
b = int(input(""))
d = r*100 + g*10 + b
D = int(d)
if D % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r = int(input(""))
g = int(input(""))
b = int(input(""))
d = r*100 + g*10 + b
if d % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r = int(input(""))
g = int(input(""))
b = int(input(""))
d = r*100 + g*10 + b
if d % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r = int(input(""))
g = int(input(""))
b = int(input(""))
r = r * 100
g = g * 10
d = r + g + b
if d % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
r = int(input(""))
g = int(input(""))
b = int(input(""))

r = r * 100
g = g * 10
b = b * 1

d = r + g + b
if d % 4 == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
r, g, b = map(str, input().split())
ans = r + g + b
# print(ans)
ans_i = int(ans)
 
if ans_i % 4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(b))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(b))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split()))
if a+b >= 10:
            print("error")
else:
            print(str(a+b))

Fixed submission:
a,b= map(int,input().split())
if a+b >= 10:
            print("error")
else:
            print(str(a+b))

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split()))
if a+b >= 10:
            print("error")
else:
            print(a+b)

Fixed submission:
a,b= map(int,input().split())
if a+b >= 10:
            print("error")
else:
            print(str(a+b))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = abs(a_list[0] - c_list[0]) + abs(b_list[0] - d_list[0])
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])


Fixed submission:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999999999999999999999999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            ind = j
    lists.append(ind+1)
for i in range(len(lists)):
    print(lists[i])

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
max = 0
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            index = j
    lists.append(index+1)
for i in range(len(lists)):
    print(lists[i])


Fixed submission:
N,M = map(int,input().split())
a_list = []
b_list = []
c_list = []
d_list = []
lists = []
for i in range(N):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)
for i in range(M):
    c,d = map(int,input().split())
    c_list.append(c)
    d_list.append(d)
for i in range(N):
    min = 9999999999999999999999999
    for j in range(M):
        distance = abs(a_list[i] - c_list[j]) + abs(b_list[i] - d_list[j])
        if min > distance:
            min = distance
            ind = j
    lists.append(ind+1)
for i in range(len(lists)):
    print(lists[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
power = 1
mod = 10**9 + 7
for i in range(1,n+1):
    power *= i
ans = power % mod
print(ans)


Fixed submission:
import math
n=int(input())
mod = 10**9 + 7
ans = math.factorial(n)
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 1
mod = 10**9+7
for i in range(1,n+1):
    cnt *= i
print(cnt % mod)

Fixed submission:
import math
n=int(input())
mod = 10**9 + 7
ans = math.factorial(n)
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
m = 10**9 + 7
for i in range(1,N+1):
    power *= i
print(power % m)


Fixed submission:
import math
n=int(input())
mod = 10**9 + 7
ans = math.factorial(n)
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
print(power % (10**9 + 7))


Fixed submission:
import math
n=int(input())
mod = 10**9 + 7
ans = math.factorial(n)
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
cnt = 0
for i in range(a, b + 1):
    if i % x == 0:
        cnt += 1
print(cnt)


Fixed submission:
a,b,x = map(int,input().split())
zenbu = b // x +1
tmp = 0
if a % x == 0:
    tmp += 1
bubun = a // x +1
ans = zenbu - bubun + tmp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

if N == K:
    print(0)
elif N > K:
    if N % K == 0:
        print(0)
    else:
        SN = N
        PN = float('inf')
        while PN > N:
            PN = N
            N = abs(N-K)
        print(min(SN, PN))
        
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))


Fixed submission:
N, K = map(int, input().split())

# print(N % K)
# print(N % abs(N-K))

# SN = N
# PN = float('inf')
# while PN > N:
#     PN = N
#     N = abs(N-K)
#     print(PN, N)

if N == K:
    print(0)

elif N > K:
    val = N % K
    print(min(abs(val), abs(val-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))

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

if N == K:
    print(0)
elif N > K:
    if N % K == 0:
        print(0)
    else:
        SN = N
        PN = float('inf')
        while PN > N:
            PN = N
            N = abs(N-K)
        print(min(SN, PN))
        
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))


Fixed submission:
N, K = map(int, input().split())

# print(N % K)
# print(N % abs(N-K))

# SN = N
# PN = float('inf')
# while PN > N:
#     PN = N
#     N = abs(N-K)
#     print(PN, N)

if N == K:
    print(0)

elif N > K:
    val = N % K
    print(min(abs(val), abs(val-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
gap = abs(N - K)

if K == 1:
    print(0)
else:
    ans = N % gap
    print(ans)

Fixed submission:
N, K = map(int, input().split())

# print(N % K)
# print(N % abs(N-K))

# SN = N
# PN = float('inf')
# while PN > N:
#     PN = N
#     N = abs(N-K)
#     print(PN, N)

if N == K:
    print(0)

elif N > K:
    val = N % K
    print(min(abs(val), abs(val-K)))
else:
    SN = N
    PN = float('inf')
    while PN > N:
        PN = N
        N = abs(N-K)
    print(min(SN, PN))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = int(input())
readline = stdin.readline
A = list(readline().split())

def ncr(n):
    return n*(n-1) // 2

dmemo = {}
for a in A:
    dmemo.setdefault(a, 0)
    dmemo[a] += 1

cmemo = {}

for a in A:
    ans = 0
    for dk, dv in dmemo.items():
        if dk == a:
            dv -= 1
        
        if dv not in cmemo:
            val = ncr(dv)
            cmemo[dv] = val
        ans += cmemo[dv]
    print(ans)


Fixed submission:
from sys import stdin

N = int(input())
readline = stdin.readline
A = list(readline().split())

def ncr(n):
    return n*(n-1) // 2

dmemo = {}
for a in A:
    dmemo.setdefault(a, 0)
    dmemo[a] += 1

max_num = 0
cmemo = {}
for dk, dv in dmemo.items():
    if dv not in cmemo:
        val = ncr(dv)
        cmemo[dv] = val
    max_num += cmemo[dv]

for a in A:
    val = dmemo[a]
    a1 = ncr(val)
    a2 = ncr(val-1)
    ans = max_num - a1 + a2
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(input().split())


def ncr(n):
    return n*(n-1) // 2

dmemo = {}
for a in A:
    dmemo.setdefault(a, 0)
    dmemo[a] += 1

cmemo = {}

for a in A:
    ans = 0
    for dk, dv in dmemo.items():
        if dk == a:
            dv -= 1
        
        if dv not in cmemo:
            val = ncr(dv)
            cmemo[dv] = val
        ans += cmemo[dv]
    print(ans)


Fixed submission:
from sys import stdin

N = int(input())
readline = stdin.readline
A = list(readline().split())

def ncr(n):
    return n*(n-1) // 2

dmemo = {}
for a in A:
    dmemo.setdefault(a, 0)
    dmemo[a] += 1

max_num = 0
cmemo = {}
for dk, dv in dmemo.items():
    if dv not in cmemo:
        val = ncr(dv)
        cmemo[dv] = val
    max_num += cmemo[dv]

for a in A:
    val = dmemo[a]
    a1 = ncr(val)
    a2 = ncr(val-1)
    ans = max_num - a1 + a2
    print(ans)