Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
num_list =  [int(i) for i in input().split()]
sum = 0
mod = 10 ** 9 + 7
for s in range(N):
    e = s + 1
    while e < N:
        result = num_list[s] * num_list[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result % mod
        e += 1
print(sum % mod)

Fixed submission:
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    #A*B + A * C = A*(B+C)で計算
    right -= number
    result += (number * right) % mod
print(result % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
num_list =  [int(i) for i in input().split()]
sum = 0
for s in range(N):
    e = s + 1
    while e < N:
        result = num_list[s] * num_list[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result
        e += 1
mod = 10 ** 9 + 7
print(sum % mod)

Fixed submission:
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    #A*B + A * C = A*(B+C)で計算
    right -= number
    result += (number * right) % mod
print(result % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
num = []
line = input().split()
for i in range(N):
    num.append(int(line[i]))

sum = 0
for s in range(N):
    e = s + 1
    while e < N:
        result = num[s] * num[e]
        #print(str(result) + " = " + str(num[s]) + "*" + str(num[e]))
        sum += result
        e += 1
mod = 10 ** 9 + 7
print(sum % mod)

Fixed submission:
N = int(input())
num_list =  [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
    #A*B + A * C = A*(B+C)で計算
    right -= number
    result += (number * right) % mod
print(result % mod)
Buggy python submission (verdict: Runtime Error):
line = input()
sum = 0
for i in range(len(line)):
  sum = sum + int(line[0])
 print(sum)

Fixed submission:
N=int(input())
if N % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
X = int(input())
if x >= 30:
  print("Yes")
else:
  print("No")

Fixed submission:
X = int(input())
if X >= 30:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
start = j = 7 % K
count = 1
while j != 0:
    j = 10 * j + 7
    j = j % K
    count += 1
    if j == start:
        print(-1)
        exit()
print(count)

Fixed submission:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

start = j = 7 % K
count = 1

#無限ループ
while True:
    #0の時
    if j == 0:
        print(count)
        exit()
        
    j = 10 * j + 7
    j = j % K
    count += 1
    
    #同じ数のループしているかチェック
    if j == start:
        print(-1)
        exit()

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
start = j = 7 % K
count = 1
while j != 0:
    j = 10 * j + 7
    j = j % K
    count += 1
    if j == start:
        print(-1)
        exit()
print(count)

Fixed submission:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

start = j = 7 % K
count = 1

#無限ループ
while True:
    #0の時
    if j == 0:
        print(count)
        exit()
        
    j = 10 * j + 7
    j = j % K
    count += 1
    
    #同じ数のループしているかチェック
    if j == start:
        print(-1)
        exit()
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
count = 0
for s, t in S, T:
  if s != t:
    count += 1
print(count)

Fixed submission:
S = input()
T = input()
count = 0
for i in range(len(S)):
  if S[i] != T[i]:
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
[N, K] = [int(i)  for i in input().split()]
price = [int(i)  for i in input().split()]
select_sum = sum(price)
for select  in itertools.combinations(price, K):
    if sum(select) < select_sum:
        select_sum = sum(select)
print(select_sum)

Fixed submission:
import itertools
[N, K] = [int(i)  for i in input().split()]
price = [int(i)  for i in input().split()]
price.sort()
sum = 0
for i in range(K):
    sum += price[i]
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
for num in line:
  if num == 0:
    print(0)
    exit()
  sum = sum * num
if sum > 10 ** 18:
  print(-1)
else:
  print(sum)

Fixed submission:
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
  print(0)
  exit()
for num in line:
  sum = sum * num
  if sum > 10 ** 18:
    print(-1)
    exit()
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
for num in line:
  sum = sum * num
if sum > 10 ** 18:
  print(-1)
else:
  print(sum)

Fixed submission:
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
  print(0)
  exit()
for num in line:
  sum = sum * num
  if sum > 10 ** 18:
    print(-1)
    exit()
print(sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())
sum = 1
for i in range(N):
  a = int(input())
  sum = sum * a
print(sum)

Fixed submission:
N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
  print(0)
  exit()
for num in line:
  sum = sum * num
  if sum > 10 ** 18:
    print(-1)
    exit()
print(sum)
Buggy python submission (verdict: Runtime Error):
input()
 N = N % 10
if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
     print('hon')
elif N == 3:
    print('bon')
else:
    print('pon')

Fixed submission:
N = int(input())
N = N % 10
if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
     print('hon')
elif N == 3:
    print('bon')
else:
    print('pon')
Buggy python submission (verdict: Runtime Error):
S = input()
if S[1] = "B":
  S[1] = "R"
else:
  S[1] = "B"
print(S)

Fixed submission:
S = input()
if S[1] == "B":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
s=input()
ans=0
if s[0]=="R" and s[1]=="R" and s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R" and s[2]!="R" or s[1]=="R" and s[2]=="R" and s[0]!="R":
    print(2)
elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    print(1)
else:
    print(0

Fixed submission:
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
s=input()
ans=0
if s[0]=="R" and s[1]=="R" and s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R" and s[2]!="R" or s[1]=="R" and s[2]=="R" and s[0]!="R":
    print(2)
elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
s=input()
ans=0
if s[0]=="R" and s[1]=="R" and s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R" and s[2]!="R" or s[1]=="R" and s[2]=="R" and s[0]!="R":
    print(2)
elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    print(1)
else:
    print(0

Fixed submission:
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
s=input()
ans=0
if s[0]=="R" and s[1]=="R" and s[2]=="R":
    print(3)
elif s[0]=="R" and s[1]=="R" and s[2]!="R" or s[1]=="R" and s[2]=="R" and s[0]!="R":
    print(2)
elif s[0]=="R" or s[1]=="R" or s[2]=="R":
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
for j in range(x,0,-1):
    if j not in p:
        ans1=j 
        break
        
for k in range(x,102):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)
            
            

    

Fixed submission:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
ans1=x 
ans2=x
for j in range(x,-100,-1):
    if j not in p:
        ans1=j 
        break
for k in range(x,200):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)

Buggy python submission (verdict: Runtime Error):
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
for i in range(1,102):
    if i==x:
        for j in range(i,0,-1):
            if j in p:
                continue 
            else:
                ans1=j
                break
        for k in range(i,102):
            if k in p:
                continue 
            else:
                ans2=k 
                break
        break 
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)
            
            

    

Fixed submission:
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,n=get_ints()
p=get_array()
ans1=x 
ans2=x
for j in range(x,-100,-1):
    if j not in p:
        ans1=j 
        break
for k in range(x,200):
    if k not in p:
        ans2=k 
        break
if ans2-x<x-ans1:
    print(ans2)
elif x-ans1<ans2-x:
    print(ans1)
else:
    print(ans1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
result = 0
a += [int(num) for num in input().split()]

for i in range(n-1):
    for j in range(i+1,n):
        result += a[i]*a[j]

print(result%1000000007)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]
cum_sum = [0]
ans,sum = 0,0

# 累積和を求める
for i in range(len(A)):
    cum_sum.append(cum_sum[i]+A[i])

for i in range(n):
    # A[i+1]+A[i+2]+...+A[n]を累積和で求める
    sum = (cum_sum[n]-cum_sum[i+1])%1000000007
    # A[i]*(A[i+1]+A[i+2]+...+A[n])の処理
    # なおA[i+1]=A[j],A[i+2]=A[j+2]...である
    ans += A[i]*sum
    # 1000000007で割る
    ans %= 1000000007   
print(ans)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
k = int(input())
#青＞緑＞赤
r,g,b = 0,0,0
for i,num in enumerate(a):
    if i==0:
        r = num
    elif i==1:
        g = num
    elif i==2:
        b = num

for i in range(k):
    if g<r:
        g *= 2
        count += 1
    elif b<g:
        b *= 2
        count += 1
    
    if b>g and g>r:
        break

if b>g and g>r:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
r,g,b = map(int,input().split())
k = int(input())
#青＞緑＞赤
count = 0
if g*(2**k)>r:
    while g<=r:
        g*=2
        count += 1
else:
    print("No")
    sys.exit(0)

if b*(2**(k-count))>g:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int,input().split()))
k = int(input())
#青＞緑＞赤
r,g,b = 0,0,0
for i,num in enumerate(a):
    if i==0:
        r = num
    elif i==1:
        g = num
    elif i==2:
        b = num

count = 0
while count<k:
    if g<r:
        g *= 2
        count += 1

    elif b<g:
        b *= 2
        count += 1
    
    if b>g and g>r:
        break

if b>g and g>r:
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
r,g,b = map(int,input().split())
k = int(input())
#青＞緑＞赤
count = 0
if g*(2**k)>r:
    while g<=r:
        g*=2
        count += 1
else:
    print("No")
    sys.exit(0)

if b*(2**(k-count))>g:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int,input().split()))
k = int(input())
#青＞緑＞赤
r,g,b = 0,0,0
for i,num in enumerate(a):
    if i==0:
        r = num
    elif i==1:
        g = num
    elif i==2:
        b = num

count = 0
while count<k:
    if b<r or b<g:
        b *= 2
        count += 1
    elif g<r:
        g *= 2
        count += 1

if b>g and g>r:
    print("Yes")
else:
    print("No")


Fixed submission:
import sys
r,g,b = map(int,input().split())
k = int(input())
#青＞緑＞赤
count = 0
if g*(2**k)>r:
    while g<=r:
        g*=2
        count += 1
else:
    print("No")
    sys.exit(0)

if b*(2**(k-count))>g:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
index = 2
result=[]
for i in range(n-k):
    score1 = a[i]*a[i+1]*a[i+2]
    score2 = a[i+1]*a[i+2]*a[i+3]
    if score1<score2:
        result.append(True)
    else:
        result.append(False)
for j in result:
    if j:
        print("Yes")
    else:
        print("No")

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(k,n):
    if a[i-k] < a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
a=int(input())
if a%2==0:
  ans=(a/2)**2
  return
else:
  ans=((a-1)/2)*((a+1)/2)
  return
print(ans)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
a=int(input())
if(a%2==0):
  ans=(a/2)**2
  return ans
else:
  ans=((a-1)/2)*((a+1)/2)
  return ans
print(ans)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
a=int(input())
if(a%2==0):
  ans=(a/2)**2
  return
else:
  ans=((a-1)/2)*((a+1)/2)
  return
print(ans)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
a=input()
if(a%2==0):
  ans=(a/2)**2
  return
else:
  ans=((a-1)/2)*((a+1)/2)
  return
print(ans)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
a=input()
if(a%2==0):
  print((a/2)**2)
  return
else:
  print(((a-1)/2)*((a+1)/2))

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if a/2==0:
	i=(a+1)/2
	j=(a-1)/2
else:
	i=a/2
	j=a/2
print(i*j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if a%2==1:
	i=(a+1)/2
	j=(a-1)/2
else:
	i=a/2
	j=a/2
print(i*j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if(a%2==1):
	i=(a+1)/2
	j=(a-1)/2
else:
	i=a/2
	j=a/2
print(i*j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if(a%2==1):
	i=(a+1)/2
	j=(a-1)/2
else:
	i=a/2
	j=a/2
print(i+j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if(a%2==1)
	i=(a+1)/2
	j=(a-1)/2
else 
	i=a/2
	j=a/2
print(i+j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if(a%2==1)
	i=(a+1)/2
	j=(a-1)/2
else 
	i=a/2
	j=a/2
print(i+j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)

Buggy python submission (verdict: Runtime Error):
input(a)
if(a%2==1)
 i=(a+1)/2
 j=(a-1)/2
else 
 i=a/2
 j=a/2
print(i+j)

Fixed submission:
a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c=map(int, input().split())
k=max(a+b, a-b)

print(k)

Fixed submission:
a, b=map(int, input().split())
print(max(a*b,a+b,a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c=map(int, input().split())
m=max(max(a+b, a-b),a*b)
print(m)

Fixed submission:
a, b=map(int, input().split())
print(max(a*b,a+b,a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c=map(int,input().split())
m=max(max(a+b, a-b),a*b)
print(m)

Fixed submission:
a, b=map(int, input().split())
print(max(a*b,a+b,a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c=map(int,input().split())
m=max(a+b,a-b,a*b)
print(m)

Fixed submission:
a, b=map(int, input().split())
print(max(a*b,a+b,a-b))

Buggy python submission (verdict: Runtime Error):
a, b, c=map(int,input().split())
m=int(max(a+b,a-b,a*b))
print(m)

Fixed submission:
a, b=map(int, input().split())
print(max(a*b,a+b,a-b))
Buggy python submission (verdict: Runtime Error):
a=input()
print(48-a)

Fixed submission:
a=int(input())
print(48-a)
Buggy python submission (verdict: Runtime Error):
a, b, c, d=map(int,input().split())
if a+b<c+d:
  print("Right")
elif a+b=c+d:
  print("Balanced")
else:
  print("Left")

Fixed submission:
a, b, c, d=map(int,input().split())
if a+b<c+d:
  print("Right")
elif a+b==c+d:
  print("Balanced")
else:
  print("Left")

Buggy python submission (verdict: Runtime Error):
a, b, c, d=map(int,input().split())
if (a+b<c+d):
  print("Right")
elif (a+b=c+d):
  print("Balanced")
else:
  print("Left")

Fixed submission:
a, b, c, d=map(int,input().split())
if a+b<c+d:
  print("Right")
elif a+b==c+d:
  print("Balanced")
else:
  print("Left")

Buggy python submission (verdict: Runtime Error):
a, b, c, d=map(int,input().split())
if (a+b<c+d):
  print("Right")
elif(a+b=c+d):
  print("Balanced")
else:
  print("Left")

Fixed submission:
a, b, c, d=map(int,input().split())
if a+b<c+d:
  print("Right")
elif a+b==c+d:
  print("Balanced")
else:
  print("Left")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
s = []
mod = 998244353

for i in range(k):
    l,r = lr[i]
    for j in range(l, r+1):
        s.append(j)

li = [0]*(n+1)
li[0] = 1

for i in range(n):
    for j in s:
        if i+j > n:
            continue
        li[i+j] += li[i]
        li[i+j] %= mod

print(li[n-1])

Fixed submission:
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
s = []
mod = 998244353

dp = [0]*(n+1)
dpsum = [0]*(n+1)
dp[1] = 1
dpsum[1] = 1

for i in range(2,n+1):
    for j in lr:
        l, r = j
        li = i-r
        ri = i-l
        if ri < 0:
            continue
        li = max(1,li)
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1]+dp[i]

print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
lr = [list(map(int,input().split())) for _ in range(k)]
s = []
mod = 998244353

for i in range(k):
    l,r = lr[i]
    for j in range(l, r+1):
        s.append(j)

li = [0]*(n+1)
li[0] = 1

for i in range(n):
    for j in s:
        li[i] += li[i-j]
        li[i] %= mod

print(li[n-1])

Fixed submission:
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
s = []
mod = 998244353

dp = [0]*(n+1)
dpsum = [0]*(n+1)
dp[1] = 1
dpsum[1] = 1

for i in range(2,n+1):
    for j in lr:
        l, r = j
        li = i-r
        ri = i-l
        if ri < 0:
            continue
        li = max(1,li)
        dp[i] += dpsum[ri]-dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1]+dp[i]

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = map(int, input().split())

if abs(x)-d*k>=0:
    print(abs(x)-d*k)
    exit()


num = 0

while k>0:
    s = abs(x)
    s = s-d
    if abs(s)>=abs(x):
        break
    x = abs(s)
    k -= 1


if k == 0:
    print(abs(s))
    exit()

if k%2 == 0:
    print(abs(x))
else:
    print(abs(s))

Fixed submission:
x, k, d = map(int, input().split())
n = abs(x)//d

if n>=k:
    print(abs(x)-d*k)
else:
    if (k-n)%2 == 0:
        print(abs(abs(x)-d*n))
    else:
        print(abs(abs(x)-d*(n+1)))
Buggy python submission (verdict: Runtime Error):
import copy
h, w, k = map(int, input().split())
hw = []
mas = []
mas_su = 0

for i in range(h):
    hwi = input()
    masi = []
    for j in range(w):
        if hwi[j] == "#":
            masi.append(1)
        else:
            masi.append(0)

    mas_su += sum(masi)
    mas.append(masi)

l = 2**(h+w)
ans = 0

for i in range(l):
    test = copy.deepcopy(mas)
    num = 0
    for j in range(h+w):
        if ((i >> j) & 1):
            if j < h:
                for p in range(w):
                    if test[j][p]==1:
                        test[j][p] = 0
                        num += 1
            else:
                for p in range(h):
                    if test[p][j-w]==1:
                        test[p][j-w] = 0
                        num += 1
    if mas_su-num == k:
        ans += 1

print(ans)

Fixed submission:
import copy
h, w, k = map(int, input().split())
hw = []
mas = []
mas_su = 0

for i in range(h):
    hwi = input()
    masi = []
    for j in range(w):
        if hwi[j] == "#":
            masi.append(1)
        else:
            masi.append(0)

    mas_su += sum(masi)
    mas.append(masi)

l = 2**(h+w)
ans = 0

for i in range(l):
    test = copy.deepcopy(mas)
    num = 0
    for j in range(h+w):
        if ((i >> j) & 1):
            if j < h:
                for p in range(w):
                    if test[j][p]==1:
                        test[j][p] = 0
                        num += 1
            else:
                for p in range(h):
                    if test[p][j-h]==1:
                        test[p][j-h] = 0
                        num += 1
    if mas_su-num == k:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
li = list(range(1,n+1))
ab = [list() for _ in range(m)]

p = []
pi = list(range(1,n+1))

ih = dict(zip(li, h))

for i in range(m):
    a, b = map(int,input().split())
    c = ih[a]
    d = ih[b]
    if c>d:
        p.append(b)
    elif d>c:
        p.append(a)
    else:
        p.append(a)
        p.append(b)

p = set(p)

for i in p:
    pi.remove(i)

print(len(pi))

Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
li = list(range(1,n+1))
ab = [list() for _ in range(m)]

p = []

ih = dict(zip(li, h))

for i in range(m):
    a, b = map(int,input().split())
    c = ih[a]
    d = ih[b]
    if c>d:
        p.append(b)
    elif d>c:
        p.append(a)
    else:
        p.append(a)
        p.append(b)

print(n-len(set(p)))