Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
data = list(map(int,input().split()))
dataSum = sum(data)
min = 100
for i in range(N):
    sumT = sum(data[0:i + 1])
    if abs(dataSum - sumT)  < min:
        min = abs(dataSum - sumT)
    else:
        print min
        break

Fixed submission:
N = int(input())
data = list(map(int,input().split()))
dataSum = sum(data)
min = 10000
for i in range(N):
    sumT = sum(data[0:i + 1])
    if abs(sumT * 2 - dataSum)  < min:
        min = abs(sumT * 2 - dataSum)
    else:
        print (min)
        break
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
up = [[0 for i in range(w)] for j in range(h)]
down = [[0 for i in range(w)] for j in range(h)]
right = [[0 for i in range(w)] for j in range(h)]
left = [[0 for i in range(w)] for j in range(h)]
for i in range(w):
    # init up
    if grid[0][i] == ".":
        up[0][i] = 1
    else:
        up[0][i] = 0
    #init down
    if grid[-1][i] == ".":
        down[-1][i] = 1
    else:
        down[-1][i] = 0
for i in range(h):
    #init right
    if grid[i][-1] == ".":
        right[i][-1] = 1
    else:
        right[i][-1] = 0
    
    #init left
    if grid[i][0] == ".":
        left[i][0] = 1
    else:
        left[i][0] = 0
for i in range(h):
    for j in range(1,w):
        if grid[i][j] == ".":
            left[i][j] = left[i][j-1] + 1
        else:
            left[i][j] = 0
for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == ".":
            right[i][j] = right[i][j+1] + 1
        else:
            right[i][j] = 0

for i in range(1,h):
    for j in range(w):
        if grid[i][j] == ".":
            up[i][j] = up[i-1][j] + 1
        else:
            up[i][j] = 0
for i in range(h-2,-1,-1):
    for j in range(w):
        if grid[i][j] == ".":
            down[i][j] = down[i+1][j] + 1
        else:
            down[i][j] = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3)
print(ans)

Fixed submission:
h, w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
L = [[0 for i in range(w)] for j in range(h)]
R = [[0 for i in range(w)] for j in range(h)]
U = [[0 for i in range(w)] for j in range(h)]
D = [[0 for i in range(w)] for j in range(h)]
#Uを決める
for i in range(w):
    if grid[0][i] == '#':
        U[0][i] = 0
    else:
        U[0][i] = 1
for i in range(1,h):
    for j in range(w):
        if grid[i][j] == '#':
            U[i][j] = 0
        else:
            U[i][j] = U[i-1][j] + 1
 #Dを決める
for i in range(w):
    if grid[-1][i] == '#':
        D[-1][i] = 0
    else:
        D[-1][i] = 1
for i in range(h-2, -1,-1):
    for j in range(w):
        if grid[i][j] == '#':
            D[i][j] = 0
        else:
            D[i][j] = D[i+1][j] + 1
# R を決める
for i in range(h):
    if grid[i][-1] == '#':
        R[i][-1] = 0
    else:
        R[i][-1] = 1
for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == '#':
            R[i][j] = 0
        else:
            R[i][j] = R[i][j+1] + 1
#Lを決める
for i in range(h):
    if grid[i][0] == '#':
        L[i][0] = 0
    else:
        L[i][0] = 1
for i in range(h):
    for j in range(1,w):
        if grid[i][j] == '#':
            L[i][j] = 0
        else:
            L[i][j] = L[i][j-1] + 1
ans = 0
for i in range(h):
    for j in range(w):
        #print("x:{} y:{} L:{} R:{} U:{} D:{}".format(j+1,i+1,L[i][j],R[i][j],U[i][j],D[i][j]))
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def Judge(a, b):
    k = 0
    while 2 ** k  - 1 <= a + b:
        if 2 ** k - 1 == a + b:
            return True
        k += 1
    return False

L = int(input(),2)
count = (L + 1) * 2 - 1
for i in range(1,L + 1):
    for j in range(1,L - i + 1):
        if Judge(i, j):
            count += 1

print(count % (10 ** 9 + 7))

Fixed submission:
L = input()
#dp1[k] := k桁目までを確定させ、その時点でA+BがL以下が確定
#dp2[k] := k桁目までを確定させ、その時点でA+BがL以下が確定していない
dp1 = [0 for i in range(len(L))]
dp2 = [0 for i in range(len(L))]
mod = 10**9 + 7
dp1[0] = 1 # A,Bの最上位bitが(0,0)
dp2[0] = 2 # A,Bの最上位bitが(0,1), (1,0)の二通り
#最上位bitを(1,1)にしてしまうと、Lを超えてしまうのでない
for i in range(1,len(L)):
    #dp1の更新から行う
    if L[i] == '1':
        dp1[i] = dp1[i-1] * 3 + dp2[i-1]
        dp2[i] = dp2[i-1] * 2
    else:
        dp1[i] = dp1[i-1] * 3
        dp2[i] = dp2[i-1]
    dp1[i] %= mod
    dp2[i] %= mod
print((dp1[-1] + dp2[-1]) % mod)

Buggy python submission (verdict: Runtime Error):
def judge(a, b):
    k = 0
    while 2 ** k  - 1 <= a + b:
        if 2 ** k - 1 == a + b:
            return True
        k += 1
    return False

L = int(input(),2)
count = (L + 1) * 2 - 1
for i in range(1,L + 1):
    for j in range(1,L - i + 1):
        if Judge(i, j):
            count += 1


print(count % (10 ** 9 + 7))

Fixed submission:
L = input()
#dp1[k] := k桁目までを確定させ、その時点でA+BがL以下が確定
#dp2[k] := k桁目までを確定させ、その時点でA+BがL以下が確定していない
dp1 = [0 for i in range(len(L))]
dp2 = [0 for i in range(len(L))]
mod = 10**9 + 7
dp1[0] = 1 # A,Bの最上位bitが(0,0)
dp2[0] = 2 # A,Bの最上位bitが(0,1), (1,0)の二通り
#最上位bitを(1,1)にしてしまうと、Lを超えてしまうのでない
for i in range(1,len(L)):
    #dp1の更新から行う
    if L[i] == '1':
        dp1[i] = dp1[i-1] * 3 + dp2[i-1]
        dp2[i] = dp2[i-1] * 2
    else:
        dp1[i] = dp1[i-1] * 3
        dp2[i] = dp2[i-1]
    dp1[i] %= mod
    dp2[i] %= mod
print((dp1[-1] + dp2[-1]) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def calc(a, b):
    k = 0
    if a == 0 or b == 0:
        return True
    while 2 ** k  - 1 <= a + b:
        if 2 ** k - 1 == a + b:
            return True
        k += 1
    return False

L = int(input(),2)
count = 0
for i in range(L + 1):
    for j in range(L - i + 1):
        if calc(i, j):
            count += 1

print(count % (10 ** 9 + 7))

Fixed submission:
L = input()
#dp1[k] := k桁目までを確定させ、その時点でA+BがL以下が確定
#dp2[k] := k桁目までを確定させ、その時点でA+BがL以下が確定していない
dp1 = [0 for i in range(len(L))]
dp2 = [0 for i in range(len(L))]
mod = 10**9 + 7
dp1[0] = 1 # A,Bの最上位bitが(0,0)
dp2[0] = 2 # A,Bの最上位bitが(0,1), (1,0)の二通り
#最上位bitを(1,1)にしてしまうと、Lを超えてしまうのでない
for i in range(1,len(L)):
    #dp1の更新から行う
    if L[i] == '1':
        dp1[i] = dp1[i-1] * 3 + dp2[i-1]
        dp2[i] = dp2[i-1] * 2
    else:
        dp1[i] = dp1[i-1] * 3
        dp2[i] = dp2[i-1]
    dp1[i] %= mod
    dp2[i] %= mod
print((dp1[-1] + dp2[-1]) % mod)
Buggy python submission (verdict: Runtime Error):
n, a, b, c, d = input().split()
s = input()
flag = False
for i in range(n-1):
    if s[i] == s[i+1] == '#':
        print("No")
        exit()
if c < d:
    print("Yes")
else:
    for i in range(b+1, d):
        if s[i-1] == s[i+1] == s[i]:
            print("Yes")
            exit()
    print("No")



Fixed submission:
n, a, b, c, d = map(int, input().split())
a -= 1
b -= 1
c -= 1
d -= 1
s = input()
flag = False
for i in range(a,c):
    if s[i] == s[i+1] == '#':
        print("No")
        exit()
for i in range(b,d):
    if s[i] == s[i+1] == '#':
        print("No")
        exit()
if c < d:
    print("Yes")
else:
    for i in range(b, d+1):
        if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
            print("Yes")
            exit()
    print("No")
Buggy python submission (verdict: Runtime Error):
a, p = input().split()
print((3 * a + p) / 2)

Fixed submission:
a, p = list(map(int,input().split()))
print(int(((3 * a + p) / 2)))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
data = []
for i in range(m):
    data.append(list(map(int, input().split())))
num = 1
count = 0
while num <= n:
    flag = True
    for i in range(m):
        if data[i][0] > num or data[i][1] < num:
            flag = False
    num += 1
    if flag:
        count += 1
print(count)

Fixed submission:
n, m = list(map(int, input().split()))
data = []
data1 = []
data2 = []
for i in range(m):
    data.append(list(map(int, input().split())))
for i in range(m):
    data1.append(data[i][0])
    data2.append(data[i][1])
if min(data2) - max(data1)  + 1 > 0:
    print(min(data2) - max(data1) + 1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
s = input()
s[k - 1] = (s[k - 1]).lower()
print(s)

Fixed submission:
n, k = list(map(int, input().split()))
s = list(input())
s[k - 1] = s[k - 1].lower()
print(*s, sep = "")

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
s = input()
s[k - 1] =　lower(s[k - 1])
print(s)

Fixed submission:
n, k = list(map(int, input().split()))
s = list(input())
s[k - 1] = s[k - 1].lower()
print(*s, sep = "")
Buggy python submission (verdict: Runtime Error):
data = int(input())
up = data/100
down = data % 100
if(1 <= up and up <= 12):
    if(1 <= down and down <= 12):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if(1 <= down and down <= 12):
        print("YYMM")
    else:
        print(NA)

Fixed submission:
data = int(input())
up = data/100
down = data % 100
if(1 <= up and up <= 12):
    if(1 <= down and down <= 12):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if(1 <= down and down <= 12):
        print("YYMM")
    else:
        print("NA")
Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [[] for i in range(n + 1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])
finished = set()
ans = [-1 for i in range(n + 1)]
def dfs(node, weight):
    finished.add(node)
    if weight % 2 == 0:
        ans[node] = 0
    else:
        ans[node] = 1
    for i in tree[node]:
        next, w = i
        if next not in finished:
            dfs(next, w + weight)
dfs(1,0)
for i in range(1, len(ans)):
    print(ans[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n = int(input())
tree = [[] for i in range(n + 1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])
finished = set()
ans = [-1 for i in range(n + 1)]
def dfs(node, weight):
    finished.add(node)
    if weight % 2 == 0:
        ans[node] = 0
    else:
        ans[node] = 1
    for i in tree[node]:
        next, w = i
        if next not in finished:
            dfs(next, w + weight)
dfs(1,0)
for i in range(1, len(ans)):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
count = 0
for i in range(n):
    if max(h[0:i]) =< h[i]:
        count += 1
print(count)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
count = 0
for i in range(n):
    if max(h[0:i + 1]) <= h[i]:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):

x, y, z, k = map(int,input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
mul_x_y = []
for i in X:
    for j in Y:
        mul_x_y.append(i+j)
mul_x_y.sort()
mul_x_y.reverse()
Z.sort()
Z.reverse()
mul_x_y = mul_x_y[:k]
Z = Z[:k]
ans = []
for i in mul_x_y:
    for j in Z:
        ans.append(i + j)
ans.sort()
ans.reverse()
for i in range(k):
    print(ans[i])

Fixed submission:

x, y, z, k = map(int,input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(map(int, input().split()))
mul_x_y = []
for i in X:
    for j in Y:
        mul_x_y.append(i+j)
mul_x_y.sort()
mul_x_y.reverse()
Z.sort()
Z.reverse()
mul_x_y = mul_x_y[:k]
Z = Z[:k]
ans = []
for i in mul_x_y:
    for j in Z:
        ans.append(i + j)
ans.sort()
ans.reverse()
for i in range(k):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
n, m, c = list(map(int ,input().split()))
b = list(map(int ,input().split()))
A = []
for i in range(n):
    A.appened(list(map(int ,input().split())))
count = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += (b[m] * A[n][m])
    if sum + c > 0:
        count += 1
print(count)

Fixed submission:
n, m, c = list(map(int ,input().split()))
b = list(map(int ,input().split()))
A = []
for i in range(n):
    A.append(list(map(int ,input().split())))
count = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += (b[j] * A[i][j])
    if sum + c > 0:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    k, l = list(map(int, input().split()))
    a.append(k)
    b.append(l)
sum = 0
money = 0
index = a.index(min(a))
while sum + b[index]< m:
    sum += b[index]
    money += a[index] * b[index]
    del a[index]
    del b[index]
    index = a.index(min(a))
money += (m - sum) * a[index]
print(money)


Fixed submission:
n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    k, l = list(map(int, input().split()))
    a.append(k)
    b.append(l)
sum = 0
money = 0
index = a.index(min(a))
while sum < m:
    if b[index] > 0:
        b[index] -= 1
        sum += 1
        money += a[index]
    else:
        del a[index]
        del b[index]
        index = a.index(min(a))
print(money)

Fixed submission:
n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)
Buggy python submission (verdict: Time Limit Exceeded):
a, b = list(map(int, input().split()))
ansL = 0
ansR = 0
for i in range(a, int((b + a + 1) / 2)):
    ansL = ansL ^ i
    ansR = ansR ^ b + a - i
if (a + b) % 2 == 0 :
    ansL = ansL ^ int((a + b) / 2)
print(ansL ^ ansR)

Fixed submission:
a, b = list(map(int, input().split()))
def division2(n):
    if(n % 2 == 0):
        return True
    else:
        return False
k = b - a + 1
if division2(k):##戸数が偶数
    if division2(a):
        if division2(k / 2):##個数の半分が偶数
            print(0)
        else:
            print(1)
    else:
        if division2((k - 2)/2):
            print(a ^ b)
        else:
            print(1 ^ a ^ b)
else:
    if division2(a):##最初がguu数
        if division2((k - 1) / 2):
            print(b)
        else:
            print(b ^ 1)
    else:
        if division2((k - 1) / 2):
            print(a)
        else:
            print(a ^ 1)

Buggy python submission (verdict: Time Limit Exceeded):
a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
    ans = ans ^ i
print(ans)

Fixed submission:
a, b = list(map(int, input().split()))
def division2(n):
    if(n % 2 == 0):
        return True
    else:
        return False
k = b - a + 1
if division2(k):##戸数が偶数
    if division2(a):
        if division2(k / 2):##個数の半分が偶数
            print(0)
        else:
            print(1)
    else:
        if division2((k - 2)/2):
            print(a ^ b)
        else:
            print(1 ^ a ^ b)
else:
    if division2(a):##最初がguu数
        if division2((k - 1) / 2):
            print(b)
        else:
            print(b ^ 1)
    else:
        if division2((k - 1) / 2):
            print(a)
        else:
            print(a ^ 1)
Buggy python submission (verdict: Runtime Error):
s = input()
data = []
for i in s:
    data.append(int(i))
one = 0
zero = 0
for i in range(len(data))
    if i == 0:
        zero += 1
    else:
        one += 1
print(min(zero, one))

Fixed submission:
s = input()
data = []
for i in s:
    data.append(int(i))
one = 0
zero = 0
for i in range(len(data)):
    if data[i] == 0:
        zero += 1
    else:
        one += 1

print(min(zero, one) * 2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int, input().split()))
L.sort().reverse()
if L[0] < sum(L[1:n]):
  print("Yes")
else:
  print("No")

Fixed submission:
n = int(input())
L = list(map(int, input().split()))
L.sort()
L.reverse()
if L[0] < sum(L[1:n]):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = list(str(format(k, 'b')))
L = len(ans)
zero = 0
one = 0
for i in range(n):
    a[i] = str(format(a[i], 'b'))
    if len(a[i]) < L:
        a[i] = '0' * (L - len(a[i])) + a[i]
for i in range(L + 1):
    one = 0
    zero = 0
    for j in range(n):
        if a[j][i] == '0':
            zero += 1
        else:
            one += 1
    if zero > one:
        ans[i] = '1'
    else:
        ans[i] = '0'
ans = "".join(ans)
sum = 0
for i in range(n):
    a[i] = int(a[i], 2)
    sum += a[i] ^ int(ans, 2)
print(sum)


Fixed submission:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
bit_len = len(format(k, 'b'))
for i in range(n):
    bit_len = max(bit_len, len(format(a[i],'b')))
bit_count = [0 for i in range(bit_len)]
for i in range(n):
    bit = format(a[i], 'b').zfill(bit_len)
    for j in range(bit_len):
        if bit[j] == '1':
            bit_count[j] += 1
ans = 0
now_num = 0
for i in range(bit_len):
    if bit_count[i] < n - bit_count[i]:
        if now_num + 2 ** (bit_len - i - 1) <= k:
            now_num += 2 ** (bit_len - i - 1)
            ans += (n - bit_count[i]) * (2 ** (bit_len - i - 1))
            continue
    ans += bit_count[i] * (2 ** (bit_len - i - 1))
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
alpha = ''
b = []
one = 0
zero = 0
for i in range(n):
    b.append(format(a[i], '041b'))
if k == 0:
    print(sum(a))
    exit()
else:
    k = len(format(k,'b'))

for i in range(k):
    one = 0
    zero = 0
    for j in range(n):
        if b[-j][-i] == '1':
            one += 1
        else:
            zero += 1
    if one >= zero:
        alpha += '0'
    else:
        alpha += '1'
beta = int(alpha, 2)
sumA = 0
for i in range(n):
    sum += a[i] ^ beta
print(sum)


Fixed submission:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
bit_len = len(format(k, 'b'))
for i in range(n):
    bit_len = max(bit_len, len(format(a[i],'b')))
bit_count = [0 for i in range(bit_len)]
for i in range(n):
    bit = format(a[i], 'b').zfill(bit_len)
    for j in range(bit_len):
        if bit[j] == '1':
            bit_count[j] += 1
ans = 0
now_num = 0
for i in range(bit_len):
    if bit_count[i] < n - bit_count[i]:
        if now_num + 2 ** (bit_len - i - 1) <= k:
            now_num += 2 ** (bit_len - i - 1)
            ans += (n - bit_count[i]) * (2 ** (bit_len - i - 1))
            continue
    ans += bit_count[i] * (2 ** (bit_len - i - 1))
print(ans)
Buggy python submission (verdict: Runtime Error):

n, k = list(map(int, input().split()))
sushi = []
for i in range(n):
    sushi.append(list(map(int, input().split())))
point = 0
sushi_kind = set()
duplication = []
sushi.sort(key=lambda x: x[1],reverse = True)
for i in range(k):
    point += sushi[i][1]
    if sushi[i][0] in sushi_kind:
        duplication.append(sushi[i])
    else:
        sushi_kind.add(sushi[i][0])
ans = point + pow(len(sushi_kind),2)
dup_index = len(duplication) - 1
for i in range(k,n):
    if sushi[i][0] in sushi_kind:
        continue
    else:
        point += sushi[i][1]
        sushi_kind.add(sushi[i][0])
        point -= duplication[dup_index][1]
    ans = max(ans, point + pow(len(sushi_kind),2))
print(ans)



Fixed submission:

n, k = list(map(int, input().split()))
sushi = []
for i in range(n):
    sushi.append(list(map(int, input().split())))
point = 0
sushi_kind = set()
duplication = []
sushi.sort(key=lambda x: x[1],reverse = True)
for i in range(k):
    point += sushi[i][1]
    if sushi[i][0] in sushi_kind:
        duplication.append(sushi[i])
    else:
        sushi_kind.add(sushi[i][0])
ans = point + pow(len(sushi_kind),2)
dup_index = len(duplication) - 1
for i in range(k,n):
    if sushi[i][0] in sushi_kind:
        continue
    else:
        if dup_index >= 0:
            point -= duplication[dup_index][1]
            dup_index -= 1
            point += sushi[i][1]
            sushi_kind.add(sushi[i][0])
    ans = max(ans, point + pow(len(sushi_kind),2))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0

for i in range(n - 2):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
dp[n - 1] = min(dp[n - 1], dp[n - 2] + abs(h[n - 2] - h[i + 1]))
print(dp[n - 1])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
inf = 10 ** 8 + 1
dp = [inf] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
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 python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    dp[i] = min([dp[j] + abs(h[j] - h[i]) for j in range(max(0, i - k), i)])
print(dp[-1])


Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4+1
dp = [inf] * n
dp[0] = 0
for i in range(n):
    dp[i] = min([dp[i - j]  + abs(h[i - j] - h[i]) for j in range(max(0,i-k),i)])
print(dp[-1])


Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4+1
dp = [inf] * n
dp[0] = 0
for i in range(n):
    dp[i] = min([dp[i - j]  + abs(h[i - j] - h[i]) for j in range(max(0,i-k),i))])
print(dp[-1])


Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 8 + 1
dp = [inf] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    for j in range(1, k):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[n - 1])

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(n):
    ans += int(input())
if ans % 2 == 0:
    print("second")
else:
    print("first")

Fixed submission:
n = int(input())
ans = 0
for i in range(n):
    if int(input()) % 2 != 0:
        print("first")
        exit()
print("second")
Buggy python submission (verdict: Runtime Error):
n , k = list(map(input().split()))
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min = h[-1]
for i in range(n - k):
    if min > h[i + k] - h[i]:
        min = h[i + k] - h[i]
print(min)

Fixed submission:
n , k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min = h[-1]
for i in range(n - k + 1):
    if min > h[i + k - 1] - h[i]:
        min = h[i + k - 1] - h[i]
print(min)