Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v_odd[1::2]
v_even[0::2]

v_odd_mc = Counter(v_odd).most_common()
v_even_mc = Counter(v_even).most_common()

v_odd_mc.append((0, 0))
v_even_mc.append((0, 0))

if v_odd_mc[0] != v_even_mc[0]:
    print(n-v_odd_mc[0][1]-v_even_mc[0][1])
else:
    print(n - max(v_odd_mc[0][1] + v_even_mc[1][1], v_odd_mc[1][0]+v_even_mc[0][1]))

Fixed submission:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()
 
v_odd_common.append((0,0))
v_even_common.append((0,0))
 
if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

n = int(input())
v = list(map(int, input().split()))

odd = defaultdict(int)
even = defaultdict(int)

nodd = 0
neven = 0
for ix in range(1, n+1):
    if ix & 1:
        odd[v[ix-1]] += 1
        nodd += 1
    else:
        even[v[ix-1]] += 1
        neven += 1

odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)
even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)

odd_top = odd_sorted[0]
even_top = even_sorted[0]

# solve

ans = 0

if odd_top[0] == even_top[0]:

    if len(odd) == len(even) == 1:
        ans = nodd
    else:
        if len(odd) == 1:
            ans += nodd - odd_top[1]
            ans += neven - even_sorted[1][1]

        elif len(even) == 1:
            ans += nodd - odd_sorted[1][1]
            ans += neven - even_top[1]

        else:
            odd_sec = odd_sorted[1]
            even_sec = even_sorted[1]

            # use others
            if nodd_sec[1] < neven_sec[1]:
                # use nodd_sec
                ans += nodd - odd_sec[1]
                ans += neven - even_top[1]
            else:
                ans += nodd - odd_top[1]
                ans += neven - even_sec[1]
else:
    ans += nodd - odd_top[1]
    ans += neven - even_top[1]

# print("odd_top", odd_top)
# print("even_top", even_top)
print(ans)

Fixed submission:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()
 
v_odd_common.append((0,0))
v_even_common.append((0,0))
 
if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

subst = set()
for fil_i in range(1, len(s)+1):
    for ix in range(0, len(s)):
        if ix + fil_i <= len(s):
            # print(ix,fil_i)
            # print(s[ix:ix+fil_i])
            subst.add(s[ix: ix + fil_i])
        else:
            break

ans = sorted(list(subst))
# print(ans)
print(ans[k-1])


Fixed submission:
s = input()
k = int(input())

# tle
subst = set()
for fil_i in range(1, k+1):
    for ix in range(0, len(s)):
        if ix + fil_i <= len(s):

            subst.add(s[ix: ix + fil_i])
        else:
            break

ans = sorted(list(subst))
print(ans[k-1])
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())

# cand = list(range(a, b+1))

S = sorted(list(set(cand[:k] + cand[-k:])))
# for i in res:
#     print(i)
# last = 0
# for so in range(a, a+k, 1):
#     if so <= b:
#         print(so)
#         last = so

# for lo in range(b-(k-1), b+1, 1):
#     if last < lo and lo <= b:
#         print(lo)

# S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)

Fixed submission:
a, b, k = map(int, input().split())
S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
cand = list(range(a, b+1))

# res = sorted(list(set(cand[:k] + cand[-k:])))
# for i in res:
#     print(i)
# last = 0
# for so in range(a, a+k, 1):
#     if so <= b:
#         print(so)
#         last = so

# for lo in range(b-(k-1), b+1, 1):
#     if last < lo and lo <= b:
#         print(lo)

S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)

Fixed submission:
a, b, k = map(int, input().split())
S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
cand = list(range(a, b+1))

# res = sorted(list(set(cand[:k] + cand[-k:])))
# for i in res:
#     print(i)
last = 0
for so in range(a, a+k, 1):
    if so <= b:
        print(so)
        last = so

for lo in range(b-(k-1), b+1, 1):
    if last < lo and lo <= b:
        print(lo)

Fixed submission:
a, b, k = map(int, input().split())
S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
cand = list(range(a, b+1))
res = sorted(list(set(cand[:k] + cand[-k:])))
for i in res:
    print(i)

Fixed submission:
a, b, k = map(int, input().split())
S=sorted(set(range(a,min(a+k,b+1))) | set(range(max(b+1-k,a),b+1)))
for _ in S:
    print(_)
Buggy python submission (verdict: Runtime Error):
A, B = list(map(int, input().split()))

ans = 0
for i in range(A, B+1):
  buf = str(i)
  is_par = true
  for u in range(buf.size()//2):
    if buf[u] != buf[-1-u]:
      is_par = false
      break
  if is_par:
    ans += 1
print(ans)
    

Fixed submission:
A, B = list(map(int, input().split()))

ans = 0
for i in range(A, B+1):
    buf = str(i)
    is_par = True
    for u in range(len(buf)//2):
        if buf[u] != buf[-1-u]:
            is_par = False
            break
    if is_par:
        ans += 1


print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input.split()))
b = list(map(int, input.split()))

ba = 0, bb = 0
for i in range(N):
    if a[i] > b[i]:
        ba += a[i] - b[i]
    if b[i] > a[i]:
        bb += (b[i] - a[i])//2

if bb >= ba:
    print("Yes")
else:
    print("No")

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ba = 0
bb = 0
for i in range(N):
    if a[i] > b[i]:
        ba += a[i] - b[i]
    if b[i] > a[i]:
        bb += (b[i] - a[i])//2

if bb >= ba:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
a, b = input().split()

import math
c = math.sqrt(int(a + b))
ok = c.is_instance(c, int)

if ok:
  print("Yes")
else:
  print("No")

Fixed submission:
a, b = input().split()
 
import math
c = math.sqrt(int(a + b))
ok = c.is_integer()
 
if ok:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

for _ in range(N):
    a, b = map(int, input().split())
    # B.append((a,b))
    A.append(a)
    B.append(b)

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B)).sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            break

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Fixed submission:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

for _ in range(N):
    a, b = map(int, input().split())
    # B.append((a,b))
    A.append(a)
    B.append(b)

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B))
    throw_lst.sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            print(ans)
            exit(0)

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = 2, 3
c = []

for _ in range(h):
    c.append(input())

if c[0][0] == c[1][2] and c[0][1] == c[1][1] and c[0][2] == c[1][0]:
    print("YES")
else:
    print("NO")



Fixed submission:
R = int(input())
G = int(input())
print(2*G-R)
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
# A *= 100
# B *= 100

max_solvent = 0
max_solute = 0
max_strength = 0.0

for na in range(0, 31):
    for nb in range(0, 31):
        for nc in range(0, 101):
            for nd in range(0, 101):

                solute = nc * C + nd * D
                solvent = 100 * na * A + 100 * nb * B

                # if not (any([na, nb]) and any([nc, nd])):
                    # continue
                if solvent == 0:
                    break

                if solute + solvent > F:
                    # print("exceeded")
                    break

                else:
                    # if (solvent/100) * E < solute:
                    if solvent/100 * E >= solute:
                    # print("exceeded2")
                    # break
                        strength = 100 * solute / (solute + solvent)
                        # print(strength, solvent+solute, solute)
                        if max_strength <= strength:
                            max_strength = strength
                            max_solute = solute
                            max_solvent = solute + solvent

print(max_solvent, max_solute)

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())
if a == b:
    print(c)
elif a == c:
    print(b)
else:
    print(a)

Fixed submission:
n = int(input())
a = int(input())
print(n*n-a)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100

max_solvent = 0
max_solute = 0
max_strength = 0.0

for na in range(0, 31):
    for nb in range(0, 31):
        for nc in range(0, 100):
            for nd in range(0, 100):

                solute = nc * C + nd * D
                solvent = na * A + nb * B

                if not (any([na, nb]) and any([nc, nd])):
                    continue

                if (solute + solvent) > F:
                    # print("exceeded")
                    continue

                if (solvent/100) * E < solute:
                    # print("exceeded2")
                    continue

                strength = float(solute) / (solute + solvent)
                # print(strength, solvent+solute, solute)

                if max_strength < strength:
                    max_strength = strength
                    max_solute = solute
                    max_solvent = solute + solvent

print(max_solvent, max_solute)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
# A *= 100
# B *= 100

max_solvent = 0
max_solute = 0
max_strength = 0.0

for na in range(0, 31):
    for nb in range(0, 31):
        for nc in range(0, 101):
            for nd in range(0, 101):

                solute = nc * C + nd * D
                solvent = 100 * na * A + 100 * nb * B

                # if not (any([na, nb]) and any([nc, nd])):
                    # continue
                if solvent == 0:
                    break

                if solute + solvent > F:
                    # print("exceeded")
                    break

                else:
                    # if (solvent/100) * E < solute:
                    if solvent/100 * E >= solute:
                    # print("exceeded2")
                    # break
                        strength = 100 * solute / (solute + solvent)
                        # print(strength, solvent+solute, solute)
                        if max_strength <= strength:
                            max_strength = strength
                            max_solute = solute
                            max_solvent = solute + solvent

print(max_solvent, max_solute)
Buggy python submission (verdict: Runtime Error):
x, a, b = list(map(int, input().split())
print("a" if abs(x-a) < abs(x-b) else "b")

Fixed submission:
x, a, b = list(map(int, input().split()))
print("A" if abs(x-a) < abs(x-b) else "B")
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[1], A[0])
if N >= 2:
    for a in A[2:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

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

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[1], A[0])
if N >= 2:
    for a in A[2:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

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

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[1], A[0])
if N >= 2:
    for a in A[2:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

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

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

P = "POSSIBLE"
IP = "IMPOSSIBLE"

A.sort()

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

t = gcd(A[1], A[0])
if N <= 2:
    for a in A[2:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)

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

P = "POSSIBLE"
IP = "IMPOSSIBLE"

M = max(A)

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

t = gcd(A[0], A[0])
if N > 1:
    for a in A[1:]:
        t = gcd(t, a)

if K%t == 0 and K <= M:
    print(P)
else:
    print(IP)
Buggy python submission (verdict: Runtime Error):
_ = input()
S = input()

needs_right = 0, needs_left = 0
for c in S:
    if c == '(':
        needs_right += 1
    else:
        if needs_right == 0:
            needs_left += 1
        else:
            needs_right -= 1

print('(' * needs_left + S + ')' * needs_right)



Fixed submission:
_ = input()
S = input()

needs_right = 0
needs_left = 0

for c in S:
    if c == '(':
        needs_right += 1
    else:
        if needs_right == 0:
            needs_left += 1
        else:
            needs_right -= 1

print('(' * needs_left + S + ')' * needs_right)
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input())
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( a+b)

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input())
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( a+b)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a[-1] == b[0] and b[-1] == c[0]:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
A
 
B


Fixed submission:
A,B = map(int, input().split())

ans = None

if A+B > 23:
  ans = A+B-24
else:
  ans = A+B
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = input().split()

if a == 'H'
  if b == 'H':
  	print('H')
  else:
    print('D')

else:
  if b == 'H':
    print('D')
  else:
    print('H')
 

Fixed submission:
a, b = input().split()
if a == 'H':
  print(b)
else:
  if b == 'H':
    print('D')
  else:
    print('H')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

from collections import Counter
ac = Counter(A)

ans = 0
td = dict()
for k, v in ac.items():
    da = v // 3
    ma = v % 3
    t = da + ma
    while t >= 3:
        da = v // 3
        ma = v % 3
        t = da + ma
    
    td[k] = t

ans = 0
two = 0
for k, v in td.items():
    if v == 1:
        ans += 1
    else:
        two += 1

if two % 2 == 0:
    ans += two
else:
    two -= 1

print(ans)

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

from collections import Counter
ac = Counter(A)

td = dict()
for k, v in ac.items():
    if v % 2 == 0:
        td[k] = 2
    else:
        td[k] = 1

ans = 0
two = 0
for k, v in td.items():
    if v == 1:
        ans += 1
    else:
        two += 1

if two % 2 == 0:
    ans += two
else:
    two -= 1
    ans += two

print(ans)
Buggy python submission (verdict: Runtime Error):
a, op, b = input().split()
if op = '+':
	ans = int(a)+int(b)
else:
	ans = int(a) - int(b)
print(ans)

Fixed submission:
a, op, b = input().split()
if op == '+':
	ans = int(a)+int(b)
else:
	ans = int(a)-int(b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())

ans = 0

for i in range(0, b//x+1):
    xi = x * i
    if xi >= a and xi <= b:
        # print(xi)
        ans += 1
    if xi > b:
        break

print(ans)


Fixed submission:
a, b, x = map(int, input().split())

# ans = 0
bx = b//x + 1
ax = (a-1)//x + 1
ans = bx - ax
print(ans)
Buggy python submission (verdict: Runtime Error):
W, H, N = list(map(int, input().split()))

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = max(xb, X[_])
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = min(xe, X[_])
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = max(yb, Y[_])
    else:
        # Yiより大きいを黒
        ye = min(ye, [_])
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)

Fixed submission:
W, H, N = list(map(int, input().split()))

X = [0] * N
Y = [0] * N
A = [0] * N

for _ in range(N):
    X[_], Y[_], A[_] = list(map(int, input().split()))

# print("test")
# print(W,H,N)

#solve
xb = 0
xe = W
yb = 0
ye = H

for _ in range(N):
    if A[_] == 1:
        # Xiより小さいを黒
        xb = max([xb, X[_]])
    elif A[_] == 2:
        # Xiより大きいを黒
        xe = min([xe, X[_]])
    elif A[_] == 3:
        # Yiより小さいを黒
        yb = max([yb, Y[_]])
    else:
        # Yiより大きいを黒
        ye = min([ye, Y[_]])
    
    # check
    if (xe - xb) <= 0 or (ye - yb) <= 0:
        print(0)
        import sys
        sys.exit()

ans = (xe - xb) * (ye - yb)
print(ans)
Buggy python submission (verdict: Runtime Error):
X = input()

cache = 0
ans = len(X)

for c in X:
    if c == 'S'
        cache += 1
    else:
        if cache > 0:
            cache -= 1
            ans -= 2

print(ans)

Fixed submission:
X = input()

cache = 0
ans = len(X)

for c in X:
    if c == 'S':
        cache += 1
    else:
        if cache > 0:
            cache -= 1
            ans -= 2

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global x,k,d
    if d==0:
        print(abs(x))
        return
    if x > 0:
        i = x//d
        if i<k:
            x -= d*i
        else:
            print(x-d*k)
            return
    elif x<0:
        i = -x//d
        if i<k:
            x += d*i
        else:
            print(abs(x+d*k))
            return
    else:
        if k%2==1:
            print(abs(d))
        else:
            print(0)
            return
    
    k -= i
    if k%2==1:
        if abs(x-d)<abs(x+d):
            print(abs(x-d))
        else:
            print(abs(x+d))
    else:
        print(abs(x))
    return

if __name__=='__main__':
    x,k,d = IL()
    solve()

Fixed submission:
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global x,k,d
    i = min(k,abs(x//d))
    if abs(x-d*i)<abs(x+d*i):
        x -= d*i
    else:
        x += d*i
    k -= i
    if k%2==1:
        if abs(x-d)<abs(x+d):
            print(abs(x-d))
        else:
            print(abs(x+d))
    else:
        print(abs(x))
    return

if __name__=='__main__':
    x,k,d = IL()
    solve()

Buggy python submission (verdict: Runtime Error):
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global x,k,d
    if x > 0:
        i = x//d
        if i<k:
            x -= d*i
        else:
            print(x-d*k)
            return
    elif x<0:
        i = -x//d
        if i<k:
            x += d*i
        else:
            print(abs(x+d*k))
            return
    else:
        if k%2==1:
            print(abs(d))
        else:
            print(0)
            return
    
    k -= i
    if k%2==1:
        if abs(x-d)<abs(x+d):
            print(abs(x-d))
        else:
            print(abs(x+d))
    else:
        print(abs(x))
    return

if __name__=='__main__':
    x,k,d = IL()
    solve()

Fixed submission:
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    global x,k,d
    i = min(k,abs(x//d))
    if abs(x-d*i)<abs(x+d*i):
        x -= d*i
    else:
        x += d*i
    k -= i
    if k%2==1:
        if abs(x-d)<abs(x+d):
            print(abs(x-d))
        else:
            print(abs(x+d))
    else:
        print(abs(x))
    return

if __name__=='__main__':
    x,k,d = IL()
    solve()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n,d = IL()
    d = d*d
    c = 0
    for _ in range(n):
        x,y = IL()
        if x*x + y*y <= d:
            c += 1

    print(c)
    exit()

Fixed submission:
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n,d = IL()
    d = d*d
    c = 0
    for _ in range(n):
        x,y = IL()
        if x*x + y*y <= d:
            c += 1

    print(c)
    exit()