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

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

dp = [0] * N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split())) + [100 for _ in range(100)]

# dp = [0] * N
# dp[1] = abs(H[1]-H[0])
#
# # loop
# for i in range(2, N):
#     dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
#
# print(dp)
# print(dp[N-1])

dp = [0] * N
dp[1] = abs(H[1]-H[0])

# rec
def func(i):
    #print(f'i: {i}')
    if i >= N:
        return 0
    else:
        dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
        func(i+1)

func(2)
#print(dp)
print(dp[N-1])

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

dp = [0] * N
dp[1] = abs(H[1]-H[0])

def func(i):
    if i >= N:
        return 0
    else:
        dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
        func(i+1)

func(2)
print(dp[N-1])

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

dp = [0] * N
dp[1] = abs(H[1]-H[0])

def func(i):
    if i == N:
        return 0
    else:
        dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
        func(i+1)

func(2)
print(dp[N-1])

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

dp = [0] * N
dp[1] = abs(H[1]-H[0])

def func(i):
    if i == N:
        return 0
    else:
        dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
        return func(i+1)

func(2)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

N = int(input())
H = [-1] + list(map(int, input().split()))

def func(i):
    if i == 0:
        return 0
    else:
        if i - 2 < 0:
            return 0
        elif i - 1 < 0:
            return 0
        elif i > N:
            return 0
        else:
            return min((func(i-1)+abs(H[i-1]-H[i]), func(i-2)+abs(H[i-2]-H[i])))

print(func(N))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

N = int(input())
H = [-1] + list(map(int, input().split()))

def func(i):
    if i == 0:
        return 0
    else:
        if i - 2 < 0:
            return 0
        elif i - 1 < 0:
            return 0
        else:
            return min((func(i-1)+abs(H[i-1]-H[i]), func(i-2)+abs(H[i-2]-H[i])))

print(func(N))

Buggy submission (verdict: Runtime Error):
N = int(input())
H = [-1] + list(map(int, input().split()))

def func(i):
    if i == 0:
        return 0
    else:
        if i - 2 < 0:
            return 0
        elif i - 1 < 0:
            return 0
        else:
            return min((func(i-1)+abs(H[i-1]-H[i]), func(i-2)+abs(H[i-2]-H[i])))

print(func(N))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)

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

edges = [[] for _ in range(n+1)]
for _ in range(m):
    x, y = map(int, input().split())
    edges[x].append(y)

dp = [-1 for _ in range(n+1)]

def longest_path(u):
    if dp[u] != -1:
        return dp[u]
    d = 0
    for v in edges[u]:
        d = max(d, 1+longest_path(v))
    dp[u] = d
    return d

for u in range(1, n+1):
    longest_path(u)

print(max(dp))

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

edges = [[] for _ in range(n+1)]
for _ in range(m):
    x, y = map(int, input().split())
    edges[x].append(y)

dp = [-1 for _ in range(n+1)]

def longest_path(u):
    if dp[u] != -1:
        return dp[u]
    d = 0
    for v in edges[u]:
        d = max(d, 1+longest_path(v))
    dp[u] = d
    return d

for u in range(1, n+1):
    longest_path(u)

print(max(dp))

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

edges = [[] for _ in range(n+1)]
for _ in range(m):
    x, y = map(int, input().split())
    edges[x].append(y)

dp = [-1 for _ in range(n+1)]

def longest_path(u):
    if dp[u] != -1:
        return dp[u]
    d = 0
    for v in edges[u]:
        d = max(d, 1+longest_path(v))
    dp[u] = d
    return d

for u in range(n+1):
    longest_path(u)

print(max(dp))
Problem p03170 (python)

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

# dp[i]: 残りがi個の状態で先手が勝つかどうか
dp = [0 for _ in range(K+1)]

# dp[i] = 0: 残りi個で先手が負ける
# dp[i] = 1: 残りi個で先手が勝つ
# dp[i] = -1: 残りi個でも不明
  
for i in range(K + 1):
    # 遷移先: i-aで、そのとき手番は後手
    # どのi-aも1 = 後手がかならず勝つ = 負け
    # 1つでも0がある = 1つでも勝ち筋がある = (その手を打てば)勝ち
    # どのi-aにも遷移できない = 打てない = 負け
    for a in A:
        # 遷移先が存在し、かつそれが勝ち筋
        if i - a >= 0 and not dp[i - a]:
            dp[i] = 1
            break

if dp[K]:
    print('First')
else:
    print('Second')

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

# dp[i]: 残りがi個の状態で先手が勝つかどうか
dp = [-1 for _ in range(K+1)]

# dp[i] = 0: 残りi個で先手が負ける
# dp[i] = 1: 残りi個で先手が勝つ
# dp[i] = -1: 残りi個でも不明

for i in range(K + 1):
    # 遷移先: i-aで、そのとき手番は後手
    # どのi-aも1 = 後手がかならず勝つ = 負け
    # 1つでも0がある = 1つでも勝ち筋がある = (その手を打てば)勝ち
    # 
    # どのi-aにも遷移できない = 打てない = 負け
    if all([i - a < 0 for a in A]):
        dp[i] = 0
    else:
        if all([dp[i - a] == 1 for a in A]):
            dp[i] = 0
        elif any([dp[i - a] == 0 for a in A]):
            dp[i] = 1
        else:
            dp[i] |= int(not dp[i-a])

if dp[K]:
    print('First')
else:
    print('Second')
Problem p03211 (python)

Fixed submission:
numbers = list(input())
y = 753
result = []
for i in range(len(numbers)-2):
    x = int(''.join(numbers[i:i+3]))
    d = abs(x-y)
    result.append(d)
print(min(result))

Buggy submission (verdict: Runtime Error):
numbers = list(input())
y = 753
result = []
for i in range(len(numbers)-3):
    x = ''.join([int(x) for x in numbers[i:i+3]])
    d = abs(x-y)
    result.append(d)
print(min(result))
Problem p03262 (python)

Fixed submission:
from functools import reduce
N, X = map(int, input().split())
loc = list(map(int, input().split()))


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


print(reduce(gcd, [abs(l-X) for l in loc]))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from math import gcd
N, X = map(int, input().split())
loc = list(map(int, input().split()))

print(reduce(gcd, [abs(l-X) for l in loc]))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))
mem = {}

def prime_factors(n):
    if mem.get(n) is not None:
        return mem[n]
    else:
        i = 2
        factors = []
        while i*i <= n:
            if n % i == 0:
                factors.append(i)
                n = n // i
            else:
                i += 1
        if n > 1:
            factors.append(n)
        mem[n] = factors
    return factors


def find_shared_factors(factor1, factor2):
    counters = [Counter(factor1), Counter(factor2)]
    if len(factor2) == 0:
        return factor1
    elif len(factor1) == 0:
        return factor2
    else:
        return list(reduce(lambda x,y: x&y, counters).elements())

factors = []
for l in loc:
    factors = find_shared_factors(prime_factors(abs(l-X)), factors)
for i in range(N):
    for j in range(N):
        if i < j:
            factors = find_shared_factors(prime_factors(abs(loc[i]-loc[j])), factors)

r = reduce(lambda x,y: x*y, factors)

print(r)

Buggy submission (verdict: Runtime Error):
from functools import reduce
from collections import Counter

N, X = map(int, input().split())
loc = list(map(int, input().split()))

def prime_factors(n):
    i = 2
    factors = []
    while i*i <= n:
        if n % i == 0:
            factors.append(i)
            n = n // i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors

def find_shared_factors(factors):
    counters = [Counter(factor) for factor in factors]
    shared = []
    keys = reduce(lambda x,y: x|y, [set(c.keys()) for c in counters])
    for key in keys:
        r = [counter[key] for counter in counters]
        if min(r) > 0:
            for _ in range(min(r)):
                shared.append(key)
    return shared

d1 = find_shared_factors([prime_factors(abs(l-X)) for l in loc])
d2 = find_shared_factors([prime_factors(abs(loc[i] - loc[j])) for i in range(N) for j in range(N) if i <= j])
d3 = find_shared_factors([d1, d2])
r = reduce(lambda x,y: x*y, d3) if len(d3) > 0 else reduce(lambda x,y: x*y, d1)
print(r)
Problem p03680 (python)

Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = [0 for _ in range(n)]
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem[v] == 0:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges[v]
    if mem.get(v) is None:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = [0 for _ in range(n)]
d = 0


def has_edge(edges, v, g, d):
    target = edges[v]
    if mem[v] == 0:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)
Problem p02641 (python)

Fixed submission:
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P) + 1):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))

print(solution(X, N, P))

Buggy submission (verdict: Runtime Error):
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P)):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))

print(solution(X, N, P))

Buggy submission (verdict: Runtime Error):
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P)):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P and left >= 1:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    else:
        nearest = nearest_l or nearest_r
    return nearest

X, N = map(int, input().split())
P = list(map(int, input().split()))
print(solution(X, N, P))
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_bkt = [-1 for _ in range(2 * 10 ** 5 + 1)]
count = 0
loop_len = -1
while True:
    visited_bkt[loc + 1] = count
    loc = a[loc]
    count += 1
    if visited_bkt[loc + 1] >= 0:
        loop_len = count - visited_bkt[loc + 1]
        break
start_len = count - loop_len
print(visited_bkt.index(start_len + (k - start_len) % loop_len) if k >= count else visited_bkt.index(k))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(t) - 1 for t in input().split()]

loc = 0
visited_bkt = [-1 for _ in range(2 * 10 ** 5 + 1)]
count = 0
loop_len = -1
while True:
    visited_bkt[loc + 1] = count
    loc = a[loc]
    if visited_bkt[loc + 1] > 0:
        loop_len = count - visited_bkt[loc + 1] + 1
        break
    count += 1
start_len = count - loop_len
# print(visited_bkt)
# print(start_len, loop_len)
# print(start_len + (k - start_len) % loop_len if k >= count else k)
print(visited_bkt.index(start_len + (k - start_len) % loop_len) if k >= count else visited_bkt.index(k))
Problem p02684 (python)

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

exist = [1]
#exist.append(a[0])
ex = {}
ex[1] = 0
#ex[a[0]] = 0
if k == 1:
    print(a[0])
    exit()

cnt = 0
while(True):
    if a[exist[-1]-1] in ex:        
        idx = exist.index(a[exist[-1]-1])
        exist.append(a[exist[-1]-1])
        break
    ex[a[exist[-1]-1]] = 0
    exist.append(a[exist[-1]-1])
    
    cnt += 1
    if cnt-1 >= k-1:
        print(exist[-1])
        exit()


#k = k-idx
d = (k-idx) % (cnt-idx+1)

print(exist[d+idx])

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

exist = [a[0]]
ex = {}

cnt = 1
while(True):
    if a[exist[-1]-1] in ex:
        idx = exist.index(a[exist[-1]-1])
        exist.append(a[exist[-1]-1])
        break
    exist.append(a[exist[-1]-1])
    ex[a[exist[-1]-1]] = 0
    
    cnt += 1
    if cnt >= k-1:
        print(exist[-1])
        exit()


#k = k-idx
#print(idx,exist,cnt)
d = (k-idx) % (cnt-idx)

print(exist[d+idx-1])
Problem p02786 (python)

Fixed submission:
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)

Buggy submission (verdict: Runtime Error):
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)
Problem p02803 (python)

Fixed submission:
from collections import deque
import pprint
import numpy as np

h, w = map(int, input().split())
maze = [['*']*(w+2) for j in range(h+2)]
for i in range(1,h+1):
    maze[i][1:] = map(str,list(input()))
    maze[i].append('*')

score = []
def bfs(maze):
    for i in range(1,h+1):
        for l in range(1,w+1):
            if maze[i][l] == '#':
                continue
            visited = [[-1]*(w+1) for j in range(h+1)]
            queue = deque()
            queue.append([i, l])
            visited[i][l] = 0
            while(queue):
                y, x = queue.popleft()
                for j,k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                    new_x, new_y = x+j, y+k
                    if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                        queue.append([new_y, new_x])
                        visited[new_y][new_x] = visited[y][x] + 1
            idx = np.unravel_index(np.argmax(np.array(visited)), np.array(visited).shape)
            score.append(np.array(visited)[idx])
    return (max(score))

print(bfs(maze))

Buggy submission (verdict: Runtime Error):
from collections import deque
import pprint
import numpy as np

h, w = map(int, input().split())
maze = [['*']*(w+2) for j in range(h+2)]
for i in range(1,h+1):
    maze[i][1:] = map(str,list(input()))
    maze[i].append('*')

score = []
def bfs(maze):
    for i in range(1,h+1):
        for l in range(1,w+1):
            if i == '#' or j == '#':
                continue
            visited = [[-1]*(w+1) for j in range(h+1)]
            queue = deque()
            queue.append([i, l])
            visited[i][l] = 0
            while(queue):
                y, x = queue.popleft()
                for j,k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                    new_x, new_y = x+j, y+k
                    if maze[new_y][new_x] == '.' and visited[new_y][new_x] == -1:
                        queue.append([new_y, new_x])
                        visited[new_y][new_x] = visited[y][x] + 1
            idx = np.unravel_index(np.argmax(np.array(visited)), np.array(visited).shape)
            score.append(np.array(visited)[idx])
    return (max(score))

print(bfs(maze))
Problem p02953 (python)

Fixed submission:

N = int(input())
H = list(map(int, input().split()))

for i in range(N-1):
    if (H[i] < H[i+1]):
        H[i+1] -= 1
    

for j in range(N-1):
    if (H[j] > H[j+1]):
        print('No')
        exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
H = list(map(int, input().split()))

for i in range(N-1):
    if (H[i] > H[i+1]):
        H[i] -= 1
    

for j in range(N):
    if (H[j] > H[i+1]):
        print('No')
        sys.exit()
        
print('Yes')
Problem p02995 (python)

Fixed submission:
import math
import fractions

A,B,C,D = map(int, input().strip().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

ans = 0
lcm = lcm_base(C,D)
c_num = B//C - (A-1)//C 
d_num = B//D - (A-1)//D
diff = B//lcm - (A-1)//lcm

print(B-A+1-(c_num+d_num-diff))

Buggy submission (verdict: Runtime Error):
import math

A,B,C,D = map(int, input().strip().split())

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

ans = 0
lcm = lcm_base(C,D)
c_num = B//C - (A-1)//C 
d_num = B//D - (A-1)//D
diff = B//lcm - (A-1)//lcm

print(B-A+1-(c_num+d_num-diff))
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)

for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

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

l = [0] * N
r = [0] * N

for i in range(Q):
    l[i], r[i] = map(int, input().split())

for j in range(Q):
    print(S[l[j]-1:r[j]].count('AC'))
Problem p03103 (python)

Fixed submission:
N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
ABs.sort()
 
ans = 0
for A, B in ABs:
    ans += A * min(M, B)
    M -= min(M, B)
print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(N):
    A[i],B[i] = map(int, input().split())  

C = dict(zip(A,B))

c_sorted = sorted(C.items(), key=lambda x:x[0])

ans = 0
cnt = 0

for k,v in dict(c_sorted).items():
    cnt += v
    if (cnt < M):
        ans += k*v
    else:
        ans += (M-cnt+v) * k
        break
print(ans)
Problem p03147 (python)

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

ans = 0
while(max(H)>=0):
    ans +=1
    for i in range(N):
        H[i] -= 1
        if (H[i] >= 0):
            if (i>=1):
                if (H[i-1] < 0 and max(H[:i])>=0):
                    ans += 1

print(ans-1)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

lst=sorted(set(A))

target = {}
for i in range(len(lst)):
    target[lst[i]] = i
    
for a in A:
    print(target[a])
Problem p03160 (python)

Fixed submission:
import math
N = int(input())
h = list(map(int, input().split())) 

dp = [0] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])
 
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import math
N,K=map(int, input().split())
h = list(map(int, input().split())) 

dp = [float('inf')] * N
dp[0] = 0

for i in range(N-K):
    for j in range(1,K+1):
        if (i+j < N):
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])
Problem p03435 (python)

Fixed submission:
import math
import numpy as np
from fractions import gcd
import collections

C = [list(map(int,input().split())) for l in range(3)]

C = np.array(C)

cross1 = C[0][0] + C[1][1] + C[2][2]
cross2 = C[0][2] + C[1][1] + C[2][0]
if(cross1 == cross2 and np.sum(C)/6 == cross1/2):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
C = [list(map(int,input().split())) for l in range(3)]

C = np.array(C)

cross1 = C[0][0] + C[1][1] + C[2][2]
cross2 = C[0][2] + C[1][1] + C[2][0]
if(cross1 == cross2 and np.sum(C)/6 == cross1/2):
    print('Yes')
else:
    print('No')
Problem p03612 (python)

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

ans = 0
for i in range(n):
    if p[i] == i+1:
        ans += 1
        if i != n-1:
            p[i+1] = 0


print(ans)

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

ans = 0
for i in range(n):
    if p[i] == i+1:
        ans += 1
        if i != n:
            p[i+1] = 0

print(ans)
Problem p03815 (python)

Fixed submission:
import math

N = int(input())

if (N%11 == 6):
    print(N//11*2+1)
else:
    print(math.ceil(N/11*2))

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

print(math.ceil(N/11*2))
Problem p03639 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=0
c=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%4==0:
      c+=1
    else:
      b+=1
if c==0:
  print("Yes") if n==b else print("No")
elif b==0:
  print("Yes") if n<=2*c+1 else print("No")
else:
  print("Yes") if n<=2*c+b else print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=0
c=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%4==0:
      c+=1
    else:
      b+=1
if b==0:
  print("Yes") if n<=3*c else print("No")
else:
  print("Yes") if n<=3c+b-1 else print("No")