Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 1:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
if a*b % 2 == 1:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
a, b =int(input().split())
if a*b % 2 == 1:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
a, b = int(input())
if a*b % 2 == 1:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
c=(a*b)%2
if c=1:
    print('Odd')
else: print('even')
Problem p03494 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
d=[]
for c in range(n):
  b=0
  while a[c]%2==0:
    a[c]=int(a[c]//2)
    b+=1
  d.append(b)
print(min(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
d=[]
for c in range(n):
  b=0
  while a[c]%2==0:
    a[c]=int(a[c]/2)
    b+=1
  d[c].append(b)
print(max(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
d=[]
for c in range(n):
  b=0
  while a[c]%2==0:
    a[c]=a[c]//2
    b+=1
  d[c].append(b)
print(max(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int, input().split()))
d=[]
for c in range(n):
  b=0
  while a[c]%2==0:
    a[c]=a[c]/2
    b+=1
  d[c].append(b)
print(max(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
d=list()
for c in range(n):
  b=0
  while a[c]%2==0:
    a[c]=a[c]/2
    b+=1
  d[c].append(b)
print(max(d))
Problem p03693 (python)

Fixed submission:
a,b,c= map(int, input().split())
if (100*a+10*b+c) % 4 == 0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
r,g,d=map(int, input().spilit)
if (100r+10g+d)%4==0:
  print("YES")
else: print("NO")

Buggy submission (verdict: Runtime Error):
r,g,d=map(int, input().spilit)
if (100r+10g+d)%4=0:
  print("YES")
else: print("NO")

Buggy submission (verdict: Runtime Error):
r,g,d=map(int, input().spilit)
if (100r+10g+d)%4=0:
  print('YES')
else: print('NO')

Buggy submission (verdict: Runtime Error):
r,g,d=map(int, input().spilit)
if (100r+10g+D)%4=0:
  print('YES')
else: print('NO')
Problem p02585 (python)

Fixed submission:
import sys
mINF = -float('inf')
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s)-1 for s in sys.stdin.readline().rstrip("\n").split()]
c = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
loop = []
for i in range(n):
    loop_costs = []
    lc = 0
    np = i
    while True:
        lc += c[p[np]]
        loop_costs.append(lc)
        np = p[np]
        if np == i:
            break
    loop.append(loop_costs)
ans = mINF
for i in range(n):
    loop_i = loop[i]
    if len(loop_i) < k:
        if loop_i[-1] > 0:
            q, mod = divmod(k, len(loop_i))
            if mod == 0:
                q = q - 1
                modmax = max(loop_i)
            else:
                modmax = max(loop_i[:mod])
            ans = max(ans,loop_i[-1]*q+modmax)
        else:
            ans = max(ans,max(loop_i))
    else:
        ans = max(ans,max(loop_i[:k]))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
mINF = -float('inf')
n,k = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s)-1 for s in sys.stdin.readline().rstrip("\n").split()]
c = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
loop = []
for i in range(n):
    loop_costs = []
    lc = 0
    np = i
    while True:
        lc += c[p[np]]
        loop_costs.append(lc)
        np = p[np]
        if np == i:
            break
    loop.append(loop_costs)
ans = mINF
for i in range(n):
    loop_i = loop[i]
    if len(loop_i) < k:
        if loop_i[-1] > 0:
            q, mod = divmod(k, len(loop_i))
            modmax = max(loop_i[:mod])
            ans = max(ans,loop_i[-1]*q+modmax)
        else:
            ans = max(ans,max(loop_i))
    else:
        ans = max(ans,max(loop_i[:k]))
print(ans)
Problem p02639 (python)

Fixed submission:
import sys
l = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
for i in range (5):
    if l[i] == 0:
        print(i+1)
        break

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
h,w,k = map(int, sys.stdin.readline().rstrip("\n").split())
sx,sy,gx,gy = map(int, sys.stdin.readline().rstrip("\n").split())
sx,sy,gx,gy = sx-1,sy-1,gx-1,gy-1
labyrinth = [line.rstrip("\n") for line in sys.stdin]
INF = float('inf')
footprint = [ [[(INF,INF)]*4 for j in range(w)] for i in range(h) ]
m = [(-1, 0), (0, 1), (1, 0), (0, -1)]
q = deque()
for d in range(4):
    footprint[sx][sy][d] = (1,0)
    q.append((sx,sy,d,1,0))
while q:
    x, y, d, c, kk = q.popleft()
    for nd in range(4):
        if nd == d:
            mx,my = m[d]
            nkk = 1 if kk == k else kk + 1
            nc = c + 1 if kk == k else c
        else:
            mx,my = 0,0
            nkk = 0
            nc = c + 1
        nx = x + mx
        ny = y + my
        if 0 <= nx < h and 0 <= ny < w and labyrinth[nx][ny] == '.' and footprint[nx][ny][nd] > (nc, nkk):
            footprint[nx][ny][nd] = (nc, nkk)
            if nc == c:
                q.appendleft((nx, ny, nd, nc, nkk))
            else:
                q.append((nx, ny, nd, nc, nkk))
ans = INF
for d in range(4):
    ans = min(ans, footprint[gx][gy][d][0])
ans = -1 if ans == INF else ans
print(ans)
Problem p02642 (python)

Fixed submission:
import sys
n = int(sys.stdin.readline().rstrip("\n"))
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a_max = max(a)
c = {num: 0 for num in a}
for num in a:
    c[num] += 1
d = {num: 0 for num in a}
for num in a:
    t = 2
    while num * t <= a_max:
        d[num*t] = 1
        t += 1
ans = 0
for num in a:
    if c[num] == 1 and d[num] == 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline().rstrip("\n"))
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a.sort()
a_true = [True]*n
a_set = set(a)
if 1 in a or len(a_set) == 1:
    print(0)
else:
    a_max = a[n-1]
    i = 0
    while a[i]*2 <= a_max:
        while i < n-1:
            if a[i] == a[i+1]:
                a_true[i] = False
                a_true[i+1] = False
            i += 1
        for j in range(i+1,n):
            if a[j] % a[i] == 0:
                a_true[j] = False
        i += 1
    while i < n-1:
        if a[i] == a[i+1]:
            a_true[i] = False
            a_true[i+1] = False
        i += 1
    print(len([i for i in range(0, n) if a_true[i]]))
Problem p02646 (python)

Fixed submission:
import sys
a,v = map(int, sys.stdin.readline().rstrip("\n").split())
b,w = map(int, sys.stdin.readline().rstrip("\n").split())
t = int(sys.stdin.readline().rstrip("\n"))
between = abs(b - a)
speed = v-w
if between <= speed*t:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
import sys
a,v = map(int, sys.stdin.readline().rstrip("\n").split())
b,w = map(int, sys.stdin.readline().rstrip("\n").split())
t = int(sys.stdin.readline().rstrip("\n"))
between = abs(b - a)
speed = w - v
if between <= speed*t
  print('YES')
else:
  print('NO')
Problem p02681 (python)

Fixed submission:
import sys
s = sys.stdin.readline().rstrip("\n")
t = sys.stdin.readline().rstrip("\n")
if s == t[:-1]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
n,m,x= map(int, sys.stdin.readline().rstrip("\n").split())
lines = [ [int(s) for s in line.split()] for line in sys.stdin ]
n = 3
price = -1
skill = {}
for i in range(2**n-1):
    i = format(i+1, 'b').zfill(n)
    price_ = 0
    for j in range (m):
        skill[j] = 0
    for j in range(n):
        if i[j] == '1':
            price_  += lines[j][0]
            for k in range(m):
                skill[k] = skill[k] + lines[j][k+1]
        for k in range(m):
            if skill[k] < x:
                break
        else:
            if price == -1:
                price = price_
            else:
                price = min(price, price_)
print(price)
Problem p03219 (python)

Fixed submission:
import sys
x,y = map(int, sys.stdin.readline().rstrip("\n").split())
print(x+y//2)

Buggy submission (verdict: Runtime Error):
x,y = map(int, sys.stdin.readline().rstrip("\n").split())
print(x+y/2)

Buggy submission (verdict: Runtime Error):
n, m =  map(int, input().split())
py = [map(int, input().split()) for _ in range(m)]
p, y = [list(i) for i in zip(*py)]
pre = {}
for i in range(m):
    if p[i] not in pre.keys():
        pre[p[i]] = []
    pre[p[i]].append(y[i])
for i in pre.keys():
    pre[i].sort()
for i in range(m):
    num = str(p[i]*(10**6)+(pre[p[i]].index(y[i])+1))
    while len(num) < 12:
        num = '0' + num
    print(num)
Problem p03433 (python)

Fixed submission:
n = int(input())
a = int(input())
n = n - 500*(n//500)
if n <= a:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
n = n - 500*(n//500)
if n =< a:
    print('Yes')
else:
    print('No')
Problem p03434 (python)

Fixed submission:
import sys
n = int(sys.stdin.readline())
a = [int(s) for s in sys.stdin.readline().split()]
a.sort(reverse=True)
a_sum = 0
b_sum = 0
for i in range(n):
    if i % 2 == 0:
        a_sum += a[i]
    else:
        b_sum += a[i]
print(a_sum - b_sum)

Buggy submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline())
a = [int(s) for s in sys.stdin.readline().split()]
a.sort(reverse=True)
a_sum = 0
b_sum = 0
for i in range(n):
    if i % 2 == 1:
        a_sum += a[i]
    else:
        b_sum += b[i]
print(a_sum - b_sum)
Problem p03644 (python)

Fixed submission:
import sys
n = int(sys.stdin.readline().rstrip("\n"))
i = 0
while 2**i <= n:
    i += 1
print(2**(i-1))

Buggy submission (verdict: Runtime Error):
n = int(sys.stdin.readline().rstrip("\n"))
i = 0
while True:
    if 2**i <= n:
        i += 1
    else:
        break
print(2**i)
Problem p02885 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
print(a-n*2)
Problem p02534 (python)

Fixed submission:
k = int(input())
str = ''
for _ in range(k):
  str += 'ACL'
print(str)

Buggy submission (verdict: Runtime Error):
k = input()
str = ''
for _ in range(k):
  str += 'ACL'
print(str)
Problem p02536 (python)

Fixed submission:
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
  a, b = map(int, input().split())
  uf.union(a-1,b-1)
  
print(uf.group_count() - 1)

Buggy submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
  a, b = map(int, input().split())
  uf.union(a,b)
  
print(uf.group_count() - 1)
Problem p02606 (python)

Fixed submission:
l, r, d = map(int, input().split())
cnt = 0
for i in range(l, r+1):
  if i % d == 0:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
l. r. d = map(int, input().split())
cnt = 0
for i in (l, r+1):
  if i % d == 0:
    cnt += 1
print(cnt)
Problem p02705 (python)

Fixed submission:
print(2*int(input())*3.141592653589)

Buggy submission (verdict: Runtime Error):
print(2*int(input()*3.141592653589))
Problem p02727 (python)

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

ra = list(map(int, input().split()))
gb = list(map(int, input().split()))
sc = list(map(int, input().split()))

ra.sort(reverse=True)
gb.sort(reverse=True)
sc.sort(reverse=True)

curr_red_min_val = ra[x-1]
curr_green_min_val = gb[y-1]
tmp_x = x
tmp_y = y

for i in range(c):
  if tmp_x > 0 and curr_red_min_val < curr_green_min_val:
    if sc[i] > curr_red_min_val:
      ra[tmp_x-1] = sc[i]
      tmp_x -= 1
      if tmp_x != 0:
        curr_red_min_val = ra[tmp_x-1]
      else:
        curr_red_min_val = ra[0]
  elif tmp_y > 0:
    if sc[i] > curr_green_min_val:
      gb[tmp_y-1] = sc[i]
      tmp_y -= 1
      if tmp_y != 0:
        curr_green_min_val = gb[tmp_y-1]
      else:
        curr_green_min_val = gb[0]
      
print(sum(ra[:x])+sum(gb[:y]))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())

ra = list(map(int, input().split()))
gb = list(map(int, input().split()))
sc = list(map(int, input().split()))

ra.sort(reverse=True)
gb.sort(reverse=True)
sc.sort(reverse=True)

curr_red_min_val = ra[x-1]
curr_green_min_val = gb[y-1]
tmp_x = x
tmp_y = y

for i in range(c):
  if tmp_x > 0 and curr_red_min_val < curr_green_min_val:
    if sc[i] > curr_red_min_val:
      ra[tmp_x-1] = sc[i]
      tmp_x -= 1
      if tmp_x != 0:
        curr_red_min_val = ra[tmp_x-1]
      else:
        curr_red_min_val = ra[0]
  else tmp_y > 0:
    if sc[i] > curr_green_min_val:
      gb[tmp_y-1] = sc[i]
      tmp_y -= 1
      if tmp_y != 0:
        curr_green_min_val = gb[tmp_y-1]
      else:
        curr_green_min_val = gb[0]
      
print(sum(ra[:x])+sum(gb[:y]))
Problem p02742 (python)

Fixed submission:
h, w = map(int, input().split())
if h == 1 or w == 1:
  print(1)
else:
  print(h*w//2 + (w*h % 2))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
if h == 1 or w == 1
  print(1)
else:
  print(h*w//2 + (w*h % 2))
Problem p03994 (python)

Fixed submission:
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = (ord("z") + 1 - ord(s[i])) % 26
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  tmp_val = ord(new_s[slen-1]) + k % 26
  if tmp_val > ord("z"):
    tmp_val -= 26
  new_s = new_s[:-1] + chr(tmp_val)

print(new_s)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
slen = len(s)
new_s = ""

for i in range(slen):
  val = ord("z") + 1 - ord(s[i])
  if k >= val:
    k -= val
    new_s += "a"
  else:
    new_s += s[i]
    
if k > 0:
  new_s = new_s[:-1] + chr(ord(s[slen-1]) + k)

print(new_s)
Problem p02573 (python)

Fixed submission:
from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(set)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].add(b)
    d[b].add(a)
    
visited = set()

def dfs(node):
    
    c = 0
    stack = deque([node])
    visited.add(node)
    while stack:
        n = stack.popleft()
        c+=1
        for i in d[n]:
            if  i not in visited:
                visited.add(i)
                stack.append(i)
                
    return c
    

ans = 1

for key in list(d.keys()):
    if key not in visited:

        c = dfs(key)
        ans = max(ans, c)
        


print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(list)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].append(b)
    d[b].append(a)
    
   
def dfs(node):
    
    s = set()
    stack = deque([node])
    while stack:
        
        n = stack.popleft()
        s.add(n)
        for i in d[n]:
            if i not in s and visited[i] == 0:
                stack.append(i)
                
    return s
    

keys = list(d.keys())
m = max(keys)
visited = [0]*(m+1)
ans = 0

for key in keys:
    if visited[key] == 0:
        s = dfs(key)
        ans = max(ans,len(s))
        for i in s:
            visited[i] = 1


print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, deque
n,m = list(map(int, input().split()))

d = defaultdict(list)

for _ in range(m):
    
    a,b = list(map(int, input().split()))
    d[a].append(b)
    d[b].append(a)
    
   
def dfs(node):
    
    s = set()
    stack = deque([node])
    while stack:
        
        n = stack.popleft()
        s.add(n)
        for i in d[n]:
            if i not in s and visited[i] == 0:
                stack.append(i)
                
    return s
    

keys = list(d.keys())
m = max(keys)
visited = [0]*(2*10**5+1)
ans = 0
for key in keys:
    if visited[key] == 0:
        ans +=1
        s = dfs(key)
        for i in range(key, m+1):
            if visited[i] == 0 and i not in s:
                visited[i] = 1


print(ans)
Problem p02576 (python)

Fixed submission:
N,X,T=map(int,input().split())
a=N//X
if N%X==0:
    print(a*T)
else:
    print(a*T+T)

Buggy submission (verdict: Runtime Error):
n=int(input())
a_list=list(map(int,input().split()))
ans=0
tmp=a_list[0]
for i in range(n-1):
    if tmp>a_list[i+1]:
        #print(tmp,ans)
        ans+=tmp-a_list[i+1]
    else:
        ans+=tmp-a_list[i]
        tmp=a_list[i+1]
print(ans)
Problem p02801 (python)

Fixed submission:
mojiretu="abcdefghijklmnopqrstuvwxyz"
C=input()
for i in range(25):
    if mojiretu[i]==C:
        print(mojiretu[i+1])

Buggy submission (verdict: Runtime Error):
mojiretu="abcdefghijklmnopqrstuvwxy"
C=input()
for i in range(25):
    if mojiretu[i]==C:
        print(mojiretu[i+1])
Problem p02909 (python)

Fixed submission:
S=str(input())
if S=="Sunny":
    print("Cloudy")
elif S=="Cloudy":
    print("Rainy")
else :
    print("Sunny")

Buggy submission (verdict: Runtime Error):
S=str(input())
if S=="Sunny":
    print("Cloudy")
elif S=="Cloudy":
    print("Rainy")
else :
    print(Sunny)
Problem p02921 (python)

Fixed submission:
s=str(input())
t=str(input())
count=0
for i in range(0,3):
    if s[i]==t[i]:
        count=count+1
print(count)

Buggy submission (verdict: Runtime Error):
a, b=list(map(int,input().split()))
count=0
for i in range(0,21):
    if i*a<= b:
        count=count+1
print(count)
Problem p03105 (python)

Fixed submission:
a_list=list(map(int,input().split()))
A=a_list[0]
B=a_list[1]
C=a_list[2]
if B//A <= C:
    answer=B//A
else:
    answer=C
print(answer)

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split())
ans_list=[]
C=min(A,B)+1
for i in range(1,C):
    if A%i == 0 and B%i == 0:
        ans_list.append(i)
print(ans_list[-K])
Problem p03126 (python)

Fixed submission:
N,M = map(int,input().split())
ans = [0]*M
for i in range(N):
    KA = list(map(int,input().split()))
    for j in range(1,len(KA)):
        ans[KA[j]-1] += 1
print(ans.count(N))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ans = [0]*M
for i in range(N):
    KA = list(map(int,input().split()))
    for j in range(1,len(KA)):
        ans[[KA[j]-1]] += 1
print(ans.count(N))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ans = []
for i in range(N):
    KA = list(map(int,input().split()))
    for j in range(1,len(KA)):
        ans[[KA[j]-1]] += 1
print(ans.count(N))
Problem p02534 (python)

Fixed submission:
if __name__=="__main__":
  k=int(input())
  print('ACL'*k)

Buggy submission (verdict: Runtime Error):
if __name__=="__main__":
  n=int(input())
  print('ACL'*k)
Problem p02576 (python)

Fixed submission:
n,x,k=map(int,input().split(' '))
temp=k
ans=0
while n>0:
    n-=x
    ans +=temp
    k+=k


print(ans)

Buggy submission (verdict: Runtime Error):
n,x,k=map(int,input().split(' '))

print(((n/x)+1))*k)
Problem p02582 (python)

Fixed submission:
S=input()
set_S=set(S)
if len(set_S)==1:
    ret=S.count('R')
else:
    if S[0]==S[1]=='R' or S[1]==S[2]=='R':
        ret=2
    else:
        ret=1
print(ret)

Buggy submission (verdict: Runtime Error):
X,K,D=list(map(int,input().split()))

def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0

def solve():
    if X>0:
        x_greedy=X-K*D
    elif X<0:
        x_greedy=X+K*D

    if sgn(X)==sgn(x_greedy):
        return print(abs(x_greedy))

    else:
        x_r=X%D
        x_l=x_r-D

        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))

if __name__=='__main__':
    solve()

Buggy submission (verdict: Runtime Error):
X,K,D=list(map(int,input().split()))

def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0

def solve():
    if X>0:
        x_greedy=X-K*D
    else:
        x_greedy=X+K*D

    if sgn(X)==sgn(x_greedy):
        return print(x_greedy)

    else:
        x_r=X%D
        x_l=x_r-D

        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))

if __name__=='__main__':
    solve()
Problem p02584 (python)

Fixed submission:
X,K,D=list(map(int,input().split()))
 
def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0
 
def solve():
    if X>0:
        x_greedy=X-K*D
    else:
        x_greedy=X+K*D
 
    if sgn(X)==sgn(x_greedy):
        return print(abs(x_greedy))
 
    else:
        x_r=X%D
        x_l=x_r-D
 
        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))
 
if __name__=='__main__':
    solve()

Buggy submission (verdict: Runtime Error):
X,K,D=list(map(int,input().split()))

def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0

def solve():
    if X>0:
        x_greedy=X-K*D
    elif X<0:
        x_greedy=X+K*D

    if sgn(X)==sgn(x_greedy):
        return print(x_greedy)

    else:
        x_r=X%D
        x_l=x_r-D

        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))

if __name__=='__main__':
    solve()

Buggy submission (verdict: Runtime Error):
X,K,D=list(map(int,input().split()))
memo=[]
def dfs(i,X):
    if i==K:
        memo.append(abs(X))
        return False
    if X>=0:
        if dfs(i+1,X-D):
            return True
    elif X<0:
        if dfs(i+1,X+D):
            return False

def solve():
    while dfs(0,X)!=False:
        print(min(memo))
        break

if __name__=='__main__':
    solve()

Buggy submission (verdict: Runtime Error):
X,K,D=list(map(int,input().split()))
memo=[]
def dfs(i,X):
    if i==K:
        memo.append(abs(X))
        return False
    
    if dfs(i+1,X+D):
        return True

    if dfs(i+1,X-D):
        return True

def solve():
    while dfs(0,X)!=False:
        print(min(memo))
        break

if __name__=='__main__':
    solve()