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

Fixed submission:
from collections import defaultdict
import bisect


S = input()
T = input()

if set(T) - set(S):
    print(-1)
    exit()

dic = defaultdict(list)
leng_dic = defaultdict(int)

for pos, s in enumerate(S):
    dic[s].append(pos)
    leng_dic[s] += 1

length = len(S)
now = -1
count = 0
for t in T:
    if dic[t][-1] < now+1:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now+1)
    now = dic[t][idx]

ans = count*length + now + 1
print(ans)

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


S = input()
T = input()

if set(T) - set(S):
    print(-1)
    exit()

dic = defaultdict(list)
leng_dic = defaultdict(int)

for pos, s in enumerate(S):
    dic[s].append(pos)
    leng_dic[s] += 1

length = len(S)
now = -1
count = 0
for t in T:
    if dic[t][-1] < now:
        now = -1
        count += 1
    idx = bisect.bisect_left(dic[t], now+1)
    now = dic[t][idx]

ans = count*length + now + 1
print(ans)
Problem p03032 (python)

Fixed submission:
from collections import deque

n, k = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for t in range(k//2 + 1):
    hand = deque(V[:k-t])
    rest = deque(V[k-t:])
    cur_sum = sum(hand)

    for j in range(k-t+1):
        put_back = 0
        rev_hand = sorted(hand)

        for i in range(t):
            jewel = rev_hand[i]
            if jewel < 0:
                put_back -= jewel
            else:
                break

        candidate = cur_sum + put_back
        ans = max(candidate, ans)

        to_rest = hand.pop()
        rest.appendleft(to_rest)
        to_hand = rest.pop()
        hand.appendleft(to_hand)

        cur_sum += to_hand - to_rest

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

n, k = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for t in range(k//2 + 1):
    hand = deque(V[:k-t])
    rest = deque(V[k-t:])
    cur_sum = sum(hand)

    for j in range(k-t+1):
        put_back = 0
        rev_hand = sorted(hand)

        for i in range(t):
            jewel = rev_hand[i]
            if jewel < 0:
                put_back -= jewel
            else:
                break

        candidate = cur_sum + put_back
        ans = max(candidate, ans)

        to_rest = hand.pop()
        to_hand = rest.pop()
        hand.appendleft(to_hand)
        rest.appendleft(to_rest)
        cur_sum += to_hand - to_rest

print(ans)
Problem p03044 (python)

Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)

n = int(input())
seen = [-1]*(n+1)
path = defaultdict(dict)

for _ in range(n-1):
    u, v, w = map(int, input().split())
    path[u][v] = w
    path[v][u] = w


def dfs(seen, pos, color):
    if seen[pos] != -1:
        return
    else:
        seen[pos] = color
        change_color = 1 - color
        for nx in path[pos].keys():
            check = path[pos][nx]
            if check % 2 == 1:
                dfs(seen, nx, change_color)
            dfs(seen, nx, color)


dfs(seen, 1, 0)
for i in range(1, n+1):
    print(seen[i])

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

n = int(input())
seen = [-1]*(n+1)
path = defaultdict(dict)

for _ in range(n-1):
    u, v, w = map(int, input().split())
    path[u][v] = w
    path[v][u] = w


def dfs(seen, pos, color):
    if seen[pos] != -1:
        return
    else:
        seen[pos] = color
        for nx in path[pos].keys():
            check = path[pos][nx]
            if check % 2 == 1:
                color = 1 - color
            dfs(seen, nx, color)


dfs(seen, 1, 0)
for i in range(1, n+1):
    print(seen[i])

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

n = int(input())
seen = []
path = defaultdict(dict)

for _ in range(n-1):
    u, v, w = map(int, input().split())
    path[u][v] = w
    path[v][u] = w


def dfs(seen, pos, color):
    if seen[pos] == color:
        return
    elif seen[pos] == 1 - color:
        return False
    else:
        seen[pos] = color
        for nx in path[pos].keys():
            if path[pos][nx] % 2 == 1:
                color = 1 - color
            dfs(seen, nx, color)


for start in range(1, n + 1):
    seen = [-1] * (n+1)
    if dfs(seen, start, 0) is None:
        break

for i in range(1, n+1):
    print(seen[i])
Problem p03074 (python)

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

compress = []
now = '1'
count = 0
for s in S:
    if s != now:
        compress.append(count)
        now = s
        count = 1
    else:
        count += 1
compress.append(count)

length = len(compress)
candidate = sum(compress[:2*k+1])
ans = candidate
if length <= 2*k+1:
    print(ans)
    exit()

for i in range(0, length-2*k-1, 2):
    if 2*k+2+i < length:
        candidate += compress[2*k+1+i] + compress[2*k+2+i] - compress[i] - compress[i+1]
    else:
        candidate += compress[2*k+1+i] - compress[i] - compress[i+1]
    ans = max(ans, candidate)

print(ans)

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

compress = []
now = '1'
count = 0
for s in S:
    if s != now:
        compress.append(count)
        now = s
        count = 1
    else:
        count += 1
compress.append(count)

length = len(compress)
candidate = sum(compress[:2*k+1])
ans = candidate
if length <= 2*k+1:
    print(ans)
    exit()

for i in range(0, length-2*k-1, 2):
    if 2+k+2+i < length:
        candidate += compress[2*k+1+i] + compress[2*k+2+i] - compress[i] - compress[i+1]
    else:
        candidate += compress[2*k+1+i] - compress[i] - compress[i+1]
    ans = max(ans, candidate)

print(ans)
Problem p03076 (python)

Fixed submission:
sum_div = 0
M = []
for i in range(5):
    num = int(input())
    sum_div += num // 10
    mod = num % 10
    if mod != 0:
        M.append(mod)

if M:
    waiting = 10*(len(M)-1) + min(M)
else:
    waiting = 0
total = sum_div*10 + waiting
print(total)

Buggy submission (verdict: Runtime Error):
sum_div = 0
M = []
for i in range(5):
    num = int(input())
    sum_div += num // 10
    mod = num % 10
    if mod != 0:
        M.append(mod)

waiting = 10*(len(M)-1) + min(M)
total = sum_div*10 + waiting
print(total)
Problem p03128 (python)

Fixed submission:
from collections import defaultdict

n, m = map(int, input().split())
A = list(map(int, input().split()))
dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
usable = defaultdict(int)

for num in A:
    use = dic[num]
    if usable[use] < num:
        usable[use] = num

DP = [-1]*(n+10)
DP[0] = 0

for i in range(n):
    digits = DP[i]
    if digits < 0:
        continue

    for use in usable.keys():
        if i+use <= n and DP[i+use] < digits + 1:
            DP[i+use] = digits + 1
        else:
            continue

digits = DP[n]
num_of_match = n
ans = ''

for _ in range(n):
    if digits == 0:
        break

    for num in sorted(usable.values(), reverse=True):
        use = dic[num]
        if DP[num_of_match - use] == digits - 1:
            digits -= 1
            num_of_match -= use
            ans += str(num)
            break
        else:
            continue

print(ans)

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

n, m = map(int, input().split())
A = list(map(int, input().split()))
dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
usable = defaultdict(int)

for num in A:
    use = dic[num]
    if usable[use] < num:
        usable[use] = num

DP = [-1]*(n+1)
DP[0] = 0

for i in range(n):
    digits = DP[i]
    if digits < 0:
        continue

    for use in usable.keys():
        if i+use <= n and DP[i+use] < digits + 1:
            DP[i+use] = digits + 1
        else:
            continue

digits = DP[n]
num_of_match = n
ans = ''

for _ in range(n):
    if digits == 0:
        break

    for num in sorted(usable.values(), reverse=True):
        use = dic[num]
        if DP[num_of_match - use] == digits - 1:
            digits -= 1
            num_of_match -= use
            ans += str(num)
            break
        else:
            continue

print(ans)

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

n, m = map(int, input().split())
A = list(map(int, input().split()))
num_use_dic = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
usable = defaultdict(int)  # key: 使う本数, value: 整数
ans = []

for num in A:
    use = num_use_dic[num]
    if usable[use] < num:  # 使用本数が同じなら大きい数字のみ使えば良い
        usable[use] = num




def dfs(candidate, count):
    global ans
    if ans:
        return
    if count < 0:
        return
    if count == 0:
        ans = list(map(int, list(candidate)))
        return

    for use, num in sorted(usable.items()):
        dfs(candidate+str(num), count-use)


dfs('', n)
ans.sort(reverse=True)
print(''.join(map(str, ans)))
Problem p03163 (python)

Fixed submission:
n, W = map(int, input().split())
obj = [list(map(int, input().split())) for _ in range(n)]
DP = [[0]*2*W for _ in range(n+1)]

for i in range(1, n+1):
    for w in range(W+1):
        weight, value = obj[i-1]
        DP[i][w] = max(DP[i-1][w], DP[i][w])
        if w + weight <= W:
            DP[i][w + weight] = max(DP[i - 1][w] + value, DP[i][w + weight])

ans = max(DP[n])
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

W = int(input())
n, k = map(int, input().split())
width = []
importance = []

for _ in range(n):
    w, imp = map(int, input().split())
    width.append(w)
    importance.append(imp)

DP = [[[[0]*(W+1)] for _ in range(n+1)] for _ in range(k+1)]

for i in range(1, n+1):
    for w in range(1, W+1):
        for k in range(0, k):
            wid = width[i-1]
            imp = importance[i-1]

            if w + wid <= W:
                DP[i][w+wid][k+1] = DP[i-1][w][k] + imp
            DP[i][w] = max(DP[i][w], DP[i-1][w])

ans = np.argmax(DP[n])
print(ans)
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
if a * b % 2 == 1:
    print('Yes')
else:
    print('No')
Problem p03274 (python)

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

ans = []
for i in range(n-k+1):
    left = X[i]
    right = X[i+k-1]
    if left * right < 0:
        result = min(abs(left), abs(right)) * 2 + max(abs(left), abs(right))
    else:
        result = max(abs(left), abs(right))
    ans.append(result)

print(min(ans))

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

count_0 = X.count(0)

if k <= count_0:
    print(0)
    exit()

k -= count_0

neg = [x for x in X if x < 0]
pos = [x for x in X if x > 0]

neg_count = len(neg)
pos_count = len(pos)

if not neg:
    print(pos[k-1])
    exit()

if not pos:
    print(neg[-k])
    exit()

res = []
for left in range(1, min(neg_count, k)):
    time1 = neg[-left]
    right = k - left - 1
    if right >= pos_count:
        continue
    elif right < 0:
        res.append(abs(time1))
    else:
        time2 = pos[right]
        res.append(time2-time1*2)

for right in range(min(pos_count, k)):
    time1 = pos[right]
    left = k - right - 1
    if left >= neg_count:
        continue
    elif left <= 0:
        res.append(abs(time1))
    else:
        time2 = neg[-left]
        res.append(time1*2-time2)

print(min(res))

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

count_0 = X.count(0)

if k <= count_0:
    print(0)
    exit()

k -= count_0

neg = [x for x in X if x < 0]
pos = [x for x in X if x > 0]

neg_count = len(neg)
pos_count = len(pos)

if not neg:
    print(pos[k-1])
    exit()
if not pos:
  	print(neg[-k])
    exit()

res = []
for left in range(1, min(neg_count, k)):
    time1 = neg[-left]
    right = k - left - 1
    if right >= pos_count:
        continue
    elif right < 0:
        res.append(abs(time1))
    else:
        time2 = pos[right]
        res.append(time2-time1*2)

for right in range(min(pos_count, k)):
    time1 = pos[right]
    left = k - right - 1
    if left >= neg_count:
        continue
    elif left <= 0:
        res.append(abs(time1))
    else:
        time2 = neg[-left]
        res.append(time1*2-time2)


print(min(res))
Problem p03450 (python)

Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline
inf = float('INF')

n, m = map(int, input().split())
if m == 0:
    print('Yes')
    exit()
edges = defaultdict(list)

for i in range(m):
    left, right, dist = map(int, input().split())
    edges[left-1].append([right-1, dist])
    edges[right-1].append([left-1, -dist])

seen = [inf] * n
for node in range(n):
    if seen[node] != inf:
        continue

    seen[node] = 0
    todo = []
    while edges[node]:
        to, dis = edges[node].pop()
        todo.append([to, dis])
    while todo:
        new, dis = todo.pop()
        if seen[new] == inf:
            seen[new] = dis
        elif seen[new] != dis:
            print('No')
            exit()

        while edges[new]:
            to, n_dis = edges[new].pop()
            todo.append([to, dis + n_dis])

print('Yes')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
input = sys.stdin.readline


n, m = map(int, input().split())
if m == 0:
    print('Yes')
    exit()
edges = defaultdict(list)

for i in range(m):
    left, right, dist = map(int, input().split())
    edges[left-1].append((right-1, dist))
    edges[right-1].append((left-1, -dist))

seen = [None] * n
for node in range(n):
    if seen[node] is not None:
        continue

    seen[node] = 0
    todo = []
    while edges[node]:
        to, dis = edges[node].pop()
		seen[to] = dis
        todo.append([to, dis])
        
    while todo:
        new, dis = todo.pop()

        while edges[new]:
            to, n_dis = edges[new].pop()
            if seen[to] is None:
                seen[to] = dis + n_dis
            elif seen[to] != dis + n_dis:
                print('No')
                exit()
            todo.append([to, dis + n_dis])

print('Yes')
Problem p03469 (python)

Fixed submission:
print(input().replace('2017', '2018'))

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

x = -1
y = -1
z = -1

for a in range(n+1):  #10000
    for b in range(n-a+1):  #5000
        c = n-a-b
        if total == 10000 * a + 5000 * b + 1000 * c:
            x, y, z = a, b, c
            break

print(x, y, z)
Problem p03493 (python)

Fixed submission:
print(sum(int(s) for s in input()))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a_tuple = tuple(map(int, input().split()))
a_set = set(a_tuple)
count_list = []

if k >= len(a_set):
    print(0)
else:
    for i in a_set:
        count = a_tuple.count(i)
        count_list.append(count)
    count_list.sort()
    ans = sum(count_list[:len(a_set)-k])
    print(ans)
Problem p03624 (python)

Fixed submission:
text = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for s in text:
    alphabet = alphabet.replace(s, '')

if alphabet is '':
    print('None')
else:
    print(alphabet[0])

Buggy submission (verdict: Runtime Error):
text = input()
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for s in text:
    alphabet = alphabet.replace(s, '')

if alphabet is False:
    print('None')
else:
    print(alphabet[0])
Problem p02612 (python)

Fixed submission:
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print((n // 1000 + 1)*1000 - n)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(((n+999)//1000)*1000 - N)
Problem p02658 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
c = 1
flag = True
for _ in a:
    c *= _
    if c > 10**18:
        flag = False
        c = 1
    if c == 0:
        print(0)
        quit()
if flag:
    print(c)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
c = 1
for a in A:
	c *= a
    if c > 10**18:
         print("-1")
         quit()
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split())
c = 1
for a in A:
	c *= a
    if c > 10**18:
         print("-1")
         quit()
print(c)
Problem p02675 (python)

Fixed submission:
l = ["p","p","h","b","h","h","p","h","p","h"]
n = input()
print(l[int(n[-1])] + "on")

Buggy submission (verdict: Runtime Error):
l = ["p","p","h","b","h","h","p","h","p","h"]
n = input()
print(l[int(n[2])] + "on")
Problem p02761 (python)

Fixed submission:
N, M = map(int,input().split())
S = []
C = []
flag = True
if N == 1 and M == 0:
    print("0")
    quit()

for i in range(M):
    s,c = map(int,input().split())
    if s in S:
        if C[S.index(s)] != c:
            flag = False
            break
    if s == 1 and N > 1:
        if c == 0:
            flag = False
            break
    S.append(s)
    C.append(c)

if flag:
    n = [1] + [0 for i in range(N - 1)]
    for i in range(len(S)):
        n[S[i]-1] = C[i]
    print(*n, sep="")
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
S = "0" * N

for i in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and N != 1:
        print("-1")
        quit()
    elif S[s-1] == "0" or S[s-1] == str(c):
        S = S[0:s-1] + str(c) + S[s:-1]
    else:
        print("-1")
        quit()

if S[0] == "0" and N != 1:
    S = "1" + S[1:-1]

print(S)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
S = "0" * N
for i in range(M):
    s,c = map(int,input().split())
    if S[s-1] == "0" or S[s-1] == str(c):
        S = S[0:s-1] + str(c) + S[s:-1]
        print(S)
    else:
        print("-1")

if S[0] == "0" and N != 1:
    S = "1" + S[1:-1]

print(S)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
S = []
C = []
flag = True
for i in range(M):
    s,c = map(int,input().split())
    if s in S:
        if C[S.index(s)] != c:
            flag = False
            break
    if s == M:
        if c == 0:
            flag = False
            break
    S.append(s)
    C.append(c)

if flag:
    n = [1] + [0 for i in range(M - 1)]
    for i in range(len(S)):
        n[S[i]-1] = C[i]
    print(*n, sep="")
else:
    print("-1")
Problem p02789 (python)

Fixed submission:
N,M = map(int,input().split())
 
if N == M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())

if n == m:
  print("Yes")
else:
  print("No")
Problem p02945 (python)

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

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

Fixed submission:
S = input()
flag = False
for s in S:
  if flag:
    if temp == s:
      print("Bad")
      quit()
  temp = s
  flag = True
print("Good")

Buggy submission (verdict: Runtime Error):
S = input()
flag = False
for s in S:
  if flag:
    if temp = s:
      print("Bad")
      quit()
  temp = s
  flag = True
print("Good")
Problem p03471 (python)

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

flag = True

for i in range(Y // 10000 + 1):
    for k in range((Y - 10000*i) // 5000 + 1):
        l = int((Y - 10000*i - 5000*k) / 1000)
        if (i + k + l) == N:
            print(str(i) + " " + str(k) + " " + str(l))
            flag = False
            break
    if flag == False:
        break
if flag:
    print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())

flag = True
def f(x_1,x_2):
    global flag
    x_3 = int((Y - 10000*x_1 - 5000*x_2) / 1000)
    if x_1 + x_2 + x_3 == N:
        print(str(x_1) + " " + str(x_2) + " " + str(x_3))
        flag = False

for i in range(Y // 10000 + 1):
    spliting = i + int((Y - 10000*i) / 2 // 5000)
    
    if spliting <= N:
        for k in range(spliting + 1):
            f(i,k)
            if flag == False:
                break
    else:
        for k in range(spliting , (Y - 10000*a) // 5000 + 1):
            f(i,k)
            if flag == False:
                break
    if flag == False:
        break
    
if flag:
    print("-1 -1 -1")

Buggy submission (verdict: Runtime Error):
N, Y = map(int, input().split())

flag = True
def f(x_1,x_2):
    global flag
    x_3 = int((Y - 10000*x_1 - 5000*x_2) / 1000)
    if x_1 + x_2 + x_3 == N:
        print(str(x_1) + " " + str(x_2) + " " + str(x_3))
        flag = False

for i in range(Y // 10000 + 1):
    spliting = int((Y - 10000*i) / 2 // 5000)
    
    if spliting <= N:
        for k in range(spliting + 1):
            f(i,k)
            if flag == False:
                break
    else:
        for k in range(spliting , (Y - 10000*a) // 5000 + 1):
            f(i,k)
            if flag == False:
                break
    if flag == False:
        break
    
if flag:
    print("-1 -1 -1")
Problem p03281 (python)

Fixed submission:
n = int(input())

if n < 105:
	print(0)
elif n == 105 or n == 106:
	print(1)
else:
	if n % 2 == 0:
		length = int(n / 2) - 1
	else:
		length = int(n / 2)
	array = []
	answer = 1
	for i in range(53,length+1):
		number = i * 2 + 1
		for x in range(1,n+1):
			if number % x == 0:
				array.append(x)
		if len(array) == 8:
			answer += 1
		array.clear()
	print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())

if n < 105:
	print(0)
elif n == 105 or n == 106:
	print(1)
else:
	if n % 2 == 0:
		length = n / 2 - 1
	else:
		length = int(n / 2)
	array = []
	answer = 1
	for i in range(53,length+1):
		number = i * 2 + 1
		for x in range(1,n+1):
			if number % x == 0:
				array.append(x)
		if len(array) == 8:
			answer += 1
		array.clear()
	print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())

if n < 105:
	print(0)
elif n == 105 or n == 106:
	print(1)
else:
	if n % 2 == 0:
		length = n / 2 - 1
	else:
		length = n / 2
	array = []
	answer = 1
	for i in range(53,length+1):
		number = i * 2 + 1
		for x in range(1,n+1):
			if number % x == 0:
				array.append(x)
		if len(array) == 8:
			answer += 1
	print(answer)

Buggy submission (verdict: Runtime Error):
n = int(input())

if n < 105:
	print(0)
elif n == 105 or n == 106:
	print(1)
else:
	if n % 2 == 0:
		length = n / 2 - 1
	else:
		length = n / 2
	array = []
	answer = 1
	for i in range(53,length+1):
		number = i * 2 + 1
		for x in range(1,n+1):
			if number % x == 0:
				array.apped(x)
		if len(array) == 8:
			answer += 1
	print(answer)
Problem p02576 (python)

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

if (N%X==0):
    print(T * (N // X))
else:
    print(T * (N // X + 1))

Buggy submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

ch += 1
cw += 1
gh += 1
gw += 1

maze = ["#"*(W+4), "#"*(W+4)] + ["##" + input() + "##" for _ in range(H)] + ["#"*(W+4), "#"*(W+4)]
visited = [[-1]*(W+4) for _ in range(H+4)]
visited[ch][cw] = 0

walk = [[-1, 0], [1, 0], [0, -1], [0, 1]]
warp = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1], [-1, 0], [-1, 1], [-1, 2],
        [0, -2], [0, -1], [0, 1], [0, 2], [1, -2], [1, -1], [1, 0], [1, 1], [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]

stack_walk = [[ch, cw]]
stack_warp = [[ch, cw]]

while stack_walk or stack_warp:
    while stack_walk:
        h, w = stack_walk.pop()
        for dh, dw in walk:
            h_next = h + dh
            w_next = w + dw
            if maze[h_next][w_next]=="." and (visited[h_next][w_next]==-1 or visited[h_next][w_next] > visited[h][w]):
                visited[h_next][w_next] = visited[h][w]
                stack_walk.append([h_next, w_next])
                stack_warp.append([h_next, w_next])
    
    while stack_warp:
        h, w = stack_warp.pop()
        for dh, dw in warp:
            h_next = h + dh
            w_next = w + dw
            if maze[h_next][w_next]=="." and visited[h_next][w_next]==-1:
                visited[h_next][w_next] = visited[h][w] + 1
                stack_walk.append([h_next, w_next])
                stack_warp.append([h_next, w_next])

print(visited[gh][gw])