Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()

if S[0] == 'A' and (S[:3] + S[-2:]).count('C') == 1:
    a = 0
    c = 0
    ng = 0
    for ch in S:
        if ch == 'A':
            a += 1
        elif ch == 'C':
            c += 1
        elif not ch.islower():
            ng += 1
    if a == 1 and c == 1 and ng == 0:
        print("AC")
        sys.exit(0)
print("WA")


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()

if S[0] == 'A' and S[2:-1].count('C') == 1:
    S2 = S.replace('A', '').replace('C', '')
    if len(S2) == len(S) - 2 and S2.islower():
        print("AC")
        sys.exit(0)
print("WA")

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

if S[0] == 'A' and (S[:3] + S[-2:]).count('C') == 1:
    a = 0
    c = 0
    ng = 0
    for ch in S:
        if ch == 'A':
            a += 1
        elif ch == 'C':
            c += 1
        elif not ch.islower():
            ng += 1
    if a == 1 and c == 1 and ng == 0:
        print("AC")
        sys.exit(0)
print("WA")

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()

if S[0] == 'A' and S[2:-1].count('C') == 1:
    S2 = S.replace('A', '').replace('C', '')
    if len(S2) == len(S) - 2 and S2.islower():
        print("AC")
        sys.exit(0)
print("WA")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def debug_print(s):
    pass
    # print(s, end="")

def solve2(A, B, C, D):
    def before_C(v):
        if v > C:
            tmp = v - ( (v - C) // B ) * B
            if tmp == C and tmp + B <= v:
                tmp += B
            return tmp
        else:
            return v
    if B > A:
        debug_print("(1)")
        return "No"
    if B > D:
        debug_print("(2)")
        return "No"
    if B <= C:
        debug_print("(3)")
        return "Yes"

    seen = set()
    while True:
        A = before_C(A)
        A -= B
        if A < 0:
            return "No"
        if A <= C:
            A += D
        if A in seen:
            return "Yes"
        seen.add(A)

def solve():
    A, B, C, D = map(int, input().split())
    return solve2(A, B, C, D)

    
T = int(input())
for t in range(T):
    print(solve())



Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 解説pdf https://img.atcoder.jp/agc026/editorial.pdf を見た



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a



def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return "No"
    else:
        return "Yes"


T = int(input())
for t in range(T):
    A, B, C, D = map(int, input().split())
    print(solve(A, B, C, D))
Buggy python submission (verdict: Runtime Error):
# 後ろから順に考える
# 最後のA_Kは必ず2である必要がある
# A_Kの前には2~3人である必要がある
# ...

K = int(input())
As = list(map(int, input().split()))
As.reverse()

fail = False
if As[0] != 2:
    fail = True
else:
    mn = 2
    mx = 3
    for a in As[1:]:
        # 今 [mn, mx] = [4, 13], a = 3だとする
        # a人組をつくったあとにありうる数は3の倍数なので、ここでは6, 9, 12のみありうる
        if mn % a != 0:
            mn = (mn // a) * a + a
        if mx % a != 0:
            mx = (mx // a) * a
        if mn > mx:
            fail = True
            break

        # mxを修正
        mx = mx + (a - 1)
if fail:
    print(-1)
else:

Fixed submission:
# 後ろから順に考える
# 最後のA_Kは必ず2である必要がある
# A_Kの前には2~3人である必要がある
# ...

K = int(input())
As = list(map(int, input().split()))
As.reverse()

fail = False
if As[0] != 2:
    fail = True
else:
    mn = 2
    mx = 3
    for a in As[1:]:
        # 今 [mn, mx] = [4, 13], a = 3だとする
        # a人組をつくったあとにありうる数は3の倍数なので、ここでは6, 9, 12のみありうる
        if mn % a != 0:
            mn = (mn // a) * a + a
        if mx % a != 0:
            mx = (mx // a) * a
        if mn > mx:
            fail = True
            break

        # mxを修正
        mx = mx + (a - 1)
if fail:
    print(-1)
else:
    print(mn, mx)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    for a in range(1, 3501):
        N1 = 4*a - N
        N2 = N * a
        if N1 < 0: continue
        # print("N1, N2 = ", N1, N2)
        for b in range(1, 3501):
            N3 = b * N1 - N2
            N4 = b * N2
            g = gcd(N3, N4)
            N3 //= g
            N4 //= g
            if N3 == 1:
                print(a, b, N4)
                return

# for N in range(2, 100):
#     # print("N:::", N)
#     solve(N)
    
solve(N)



Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    for a in range(1, 3501):
        N1 = 4*a - N
        N2 = N * a
        if N1 < 0: continue
        for b in range(1, 3501):
            N3 = b * N1 - N2
            N4 = b * N2
            if N4 > 0 and N3 > 0 and N4 % N3 == 0:
                print(a, b, N4//N3)
                return
    
solve(N)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def get_a(N):
    a = 1
    while True:
        if N < 4 * a:
            return a, 4*a-N, N*a
        a += 1

def get_b(N1, N2):
    b = 1
    while True:
        if N2 < b * N1:
            return b, b*N1-N2, b*N2
        b += 1

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    a, N1, N2 = get_a(N)
    # print("a,N1,N2 = ", a, N1, N2)
    b, N1, N2 = get_b(N1, N2)
    # print("b,N1,N2 = ", b, N1, N2)
    g = gcd(N1,N2)
    N1 //= g
    N2 //= g
    assert(N1 == 1)
    print(a, b, N2)

# for N in range(2, 100):
#     print("N:::", N)
#     solve(N)

solve(N)



Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    for a in range(1, 3501):
        N1 = 4*a - N
        N2 = N * a
        if N1 < 0: continue
        for b in range(1, 3501):
            N3 = b * N1 - N2
            N4 = b * N2
            if N4 > 0 and N3 > 0 and N4 % N3 == 0:
                print(a, b, N4//N3)
                return
    
solve(N)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, K = map(int, input().split())
As = list(sorted(set(map(int, input().split()))))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

for i in range(len(As)-1):
    diff = As[i+1] - As[i]
    if i == 0:
        unit = diff
    else:
        unit = gcd(unit, diff)

ok = False
for a in As:
    if (a - K) % unit == 0 and K <= a:
        ok = True

if ok:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, K = map(int, input().split())
As = list(sorted(set(map(int, input().split()))))

def gcd(a, b):
    while b:
    	a, b = b, a % b
    return a

# corner
if len(As) == 1:
    if K == As[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:        
    for i in range(len(As)-1):
        diff = As[i+1] - As[i]
        if i == 0:
            unit = diff
        else:
            unit = gcd(unit, diff)
    
    ok = False
    for a in As:
        if (a - K) % unit == 0 and K <= a:
            ok = True
    
    if ok:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007

def solve2(Xs, Ys):
    cell_num = (len(Xs) - 1) * (len(Ys) - 1)
    if len(Xs) < 2 or len(Ys) < 2:
        return 0

    area = (Xs[-1] - Xs[0]) * (Ys[-1] - Ys[0])
    ans = area * cell_num
    ans %= MOD
    return ans

def solve(Xs, Ys):
    if len(Xs) <= 3 and len(Ys) <= 3:
        return solve2(Xs, Ys)

    ans = solve2(Xs, Ys)
    for i in range(1, len(Xs) // 2):
        ans += solve2(Xs[i:-i], Ys)
        ans %= MOD
    for i in range(1, len(Ys) // 2):
        ans += solve2(Xs, Ys[i:-i])
        ans %= MOD
    ans += solve(Xs[1:-1], Ys[1:-1])
    ans %= MOD
    return ans

N, M = map(int, input().split())
Xs = list(map(int, input().split()))
Ys = list(map(int, input().split()))
print(solve(Xs, Ys))


Fixed submission:
#!/usr/bin/env python3
#
# まず1次元で考える
#   |  |   |  |
#   a  b   c  d
# とあるとき、長さの合計は
#  (b-a) + (c-a) + (d-a) + (c-b) + (d-b) + (d-c)
# = 3d + c - b - 3a
# これは、各点の座標を、<自分より左にある点の数> - <自分より右にある点の数> でかけたものの和である
#
# もとめる面積は X座標、Y座標それぞれについて蒸気を計算した積

MOD = 1000000007

def len_sum(Xs):
    size = len(Xs)
    ret = 0
    n = len(Xs) - 1
    # 負の値にMODをとることを防ぐため、座標の大きい点から計算する
    for x in reversed(Xs):
        ret += n * x
        ret %= MOD
        n -= 2
    return ret

def solve(Xs, Ys):
    x_len_sum = len_sum(Xs)
    y_len_sum = len_sum(Ys)
    return (x_len_sum * y_len_sum) % MOD

N, M = map(int, input().split())
Xs = list(map(int, input().split()))
Ys = list(map(int, input().split()))
print(solve(Xs, Ys))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
@functools.lru_cache(maxsize = None)
def func(N, X):
    g = gcd(N, X)
    if g == 1:
        if X > N // 2:
            return func(N, N - X)
        if N == 2:
            return 3
        if N == 3:
            return 6
        return X * 3 + func(N-X, X)
    else:
        return g * func(N//g, X//g)

N,X = map(int,input().split())
print(func(N,X))


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
# @functools.lru_cache(maxsize = None)
# def func(N, X):
#     g = gcd(N, X)
#     if g == 1:
#         if X > N // 2:
#             return func(N, N - X)
#         if N == 2:
#             return 3
#         if N == 3:
#             return 6
#         return X * 3 + func(N-X, X)
#     else:
#         return g * func(N//g, X//g)


def func_fast(N, X):
    g = gcd(N, X)
    if g == 1:
        return 3 * N - 3
    else:
        return g * func_fast(N // g, X // g)

N,X = map(int,input().split())
print(func_fast(N,X))

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
@functools.lru_cache(maxsize = None)
def func(N, X):
    g = gcd(N, X)
    if g == 1:
        if X > N // 2:
            return func(N, N - X)
        if N == 2:
            return 3
        if N == 3:
            return 6
        return X * 3 + func(N-X, X)
    else:
        return g * func(N//g, X//g)

N,X = map(int,input().split())
print(func(N,X))
        
    


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
# @functools.lru_cache(maxsize = None)
# def func(N, X):
#     g = gcd(N, X)
#     if g == 1:
#         if X > N // 2:
#             return func(N, N - X)
#         if N == 2:
#             return 3
#         if N == 3:
#             return 6
#         return X * 3 + func(N-X, X)
#     else:
#         return g * func(N//g, X//g)


def func_fast(N, X):
    g = gcd(N, X)
    if g == 1:
        return 3 * N - 3
    else:
        return g * func_fast(N // g, X // g)

N,X = map(int,input().split())
print(func_fast(N,X))
Buggy python submission (verdict: Runtime Error):
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(1, n+1):
        if i % 2 == 1 and a[i-1] % 2 == 1:
            ans += 1
    print(ans)
    return




n = RN()
a = RA()
solve()


Fixed submission:
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(l, r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return





l, r, d = RA()
solve()

Buggy python submission (verdict: Runtime Error):
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(l, r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return





l, r, d = RA()
solve()


Fixed submission:
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(l, r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return





l, r, d = RA()
solve()
Buggy python submission (verdict: Time Limit Exceeded):
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    count = 0
    for i in range(n):
        for div in divisors[a[i]]:
            if (div in hm and (div!=a[i] or hm[a[i]]>1)) or ((a[i] // div in hm) and (div!=1 or hm[a[i]]>1)):
                count -= 1
                break
        count += 1
    print(count)
    return


def get_divisors():
    divisors = [[] for _ in range(10**6+1)]
    for i in range(1, 10**3+1):
        for j in range(i, 10**6+1, i):
            divisors[j].append(i)
    return divisors



n = RN()
a = RA()
hm = {}
for ai in a:
    if not ai in hm:
        hm[ai] = 0
    hm[ai] += 1
divisors = get_divisors()
solve()


Fixed submission:
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    count = 0
    for i in range(n):
        for div in divisors[a[i]]:
            if (div in hm and (div!=a[i] or hm[a[i]]>1)) or ((a[i] // div in hm) and (div!=1 or hm[a[i]]>1)):
                count -= 1
                break
        count += 1
    print(count)
    return


def get_divisors():
    divisors = [[] for _ in range(mxa+1)]
    for i in range(1, 10**3+1):
        for j in range(i, mxa+1, i):
            divisors[j].append(i)
    return divisors


n = RN()
a = RA()
mxa = max(a)
hm = {}
for ai in a:
    if not ai in hm:
        hm[ai] = 0
    hm[ai] += 1
divisors = get_divisors()
solve()
Buggy python submission (verdict: Runtime Error):
import sys


input = lambda: sys.stdin.readline()[:-1]
RI = lambda x=int: x(input())
RA = lambda x=int: map(x, input().split())
RSS = lambda: input().split()


def solve():
    ans = []
    for i in s:
        if i == "P":
            ans.append("P")
        else:
            ans.append("D")
    print("".join(ans))
    return



s = RS()
solve()

Fixed submission:
print(input().replace("?", "D"))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline.strip()
RS = input
RI = lambda x=int: x(RS())
RA = lambda x=int: map(x, RS().split())
RSS = lambda: RS().split()


def solve():
    ans = []
    for i in s:
        if i == "P":
            ans.append("P")
        else:
            ans.append("D")
    print("".join(ans))
    return



s = RS()
solve()

Fixed submission:
print(input().replace("?", "D"))
Buggy python submission (verdict: Runtime Error):
import math

def solve():
    ans = [-1 for i in range(n+1)]
    remaining = set(range(1, n+1))
    remaining.remove(1)
    last_visited = [1]
    last_visited2 = []
    c = 0
    while remaining:
        print(remaining)
        for r in last_visited:
            for ad in adj[r]:
                if ad in remaining:
                    last_visited2.append(ad)
                    remaining.remove(ad)
                    ans[ad] = r
        last_visited = last_visited2
        last_visited2 = []
        c += 1
    if -1 in ans[2:]:
        print("No")
        return
    print("Yes")
    for i in ans[2:]:
        print(i)
    return

n, m = [int(ii) for ii in input().split()]
adj = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = [int(ii) for ii in input().split()]
    adj[a].append(b)
    adj[b].append(a)
solve()

Fixed submission:
import math

def solve():
    ans = [-1 for i in range(n+1)]
    remaining = set(range(1, n+1))
    remaining.remove(1)
    last_visited = [1]
    last_visited2 = []
    while remaining:
        c = len(remaining)
        for r in last_visited:
            for ad in adj[r]:
                if ad in remaining:
                    last_visited2.append(ad)
                    remaining.remove(ad)
                    ans[ad] = r
        last_visited = last_visited2
        last_visited2 = []
        if len(remaining) == c:
            print("No")
            return
    print("Yes")
    for i in ans[2:]:
        print(i)
    return

n, m = [int(ii) for ii in input().split()]
adj = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = [int(ii) for ii in input().split()]
    adj[a].append(b)
    adj[b].append(a)
solve()
Buggy python submission (verdict: Runtime Error):


def solve():
    hm = {}
    steps = k
    curr = 0
    loopsize = 0
    pre = 0
    while not str(curr) in hm and steps > 0:
        hm[str(curr)] = pre
        pre+=1
        curr = a[curr] - 1
        steps -= 1
        loopsize += 1
    loopsize -= hm[str(curr)]
    steps %= loopsize
    while steps > 0:
        curr = a[curr] - 1
        steps -= 1
    print(curr + 1)
    return



n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()


Fixed submission:


def solve():
    hm = {}
    steps = k
    curr = 0
    loopsize = 0
    pre = 0
    while not str(curr) in hm and steps > 0:
        hm[str(curr)] = pre
        pre+=1
        curr = a[curr] - 1
        steps -= 1
        loopsize += 1
    if str(curr) in hm:
        loopsize -= hm[str(curr)]
    steps %= loopsize
    while steps > 0:
        curr = a[curr] - 1
        steps -= 1
    print(curr + 1)
    return



n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()
Buggy python submission (verdict: Runtime Error):



def solve():
    ans = ["0"]*len(s)
    ans[0] = "1"
    for i in range(len(s)):
        a = ((s[i]== 1) and c[i]==0)
        b = False
        for j in range(len(s)):
            b = b or (s[i] == s[j] and (not i==j) and not c[i]==c[j])
        if a or b:
            print(-1)
            exit()
        ans[s[i]-1] = str(c[i])
    ans = "".join(ans)
    print(ans)



    return




n, m = [int(s) for s in input().split(" ")]
s = []
c = []
for i in range(m):
    si, ci = [int(s) for s in input().split(" ")]
    s.append(si)
    c.append(ci)
solve()


Fixed submission:



def solve():
    ans = ["0"]*n
    if not n==1:
        ans[0] = "1"
    for i in range(len(s)):
        a = ((s[i]== 1) and c[i]==0) and (not n == 1)
        b = False
        for j in range(len(s)):
            b = b or (s[i] == s[j] and (not i==j) and not c[i]==c[j])
        if a or b:
            print(-1)
            exit()
        ans[s[i]-1] = str(c[i])
    ans = "".join(ans)
    print(ans)



    return




n, m = [int(s) for s in input().split(" ")]
s = []
c = []
for i in range(m):
    si, ci = [int(s) for s in input().split(" ")]
    s.append(si)
    c.append(ci)
solve()
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = map(int, input().split())

for i in range(k):
    if x < 0:
        x += d
    else:
        x -= d

print(abs(x))

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

x = abs(x)
kk = x // d

if kk >= k:
    print(str(x - (d * k)))
    exit()

k -= kk

if k % 2 == 0:
    print(str(x - (d * kk)))
else:
    print(str(abs(x - (d * (kk + 1)))))
Buggy python submission (verdict: Runtime Error):
def main():
    s = input()
    t = input()
    ans = 100000000
    for i in range(0,len(s)-len(t)):
        cnt = 0
        for sub_s,sub_t in zip(s[i:len(t)+i],t):
            if sub_s != sub_t:
                cnt += 1
        if cnt < ans:
            ans = cnt
    print(cnt)
    

if __name__ == "__main__":
    main()

Fixed submission:
s = input()
t = input()

stri = []
mincount = 1e9
for i in range(len(s)-len(t)+1):
    count = 0
    for j in range(len(t)):
        if(s[i+j] != t[j]):
            count+= 1
    mincount = min(mincount,count) 
print(mincount)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    k = int(input())
    seven = 7
    cnt = 0
    if k%2==0:
        print(-1)
        return 
    while seven != 0:
        seven %= k
        cnt += 1 
        if seven != 0:
            seven = seven * 10 + 7
    print(cnt)
    return

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    k = int(input())
    seven = 7
    already = set()
    cnt = 0
    if k%2==0:
        print(-1)
        return 
    while seven != 0:
        if seven in already:
            print(-1)
            return 
        seven %= k
        already.add(seven)
        cnt += 1 
        if seven != 0:
            seven = seven * 10 + 7
    print(cnt)
    return

if __name__ == '__main__':
    main()