Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from scipy.misc import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    if counter[a] < 3:
        print(0)
    else:
        print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))


Fixed submission:
from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * (c-1) // 2
for a in An:
    print(cnt - (counter[a] - 1))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from scipy.special import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    if counter[a] < 3:
        print(0)
    else:
        print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))


Fixed submission:
from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * (c-1) // 2
for a in An:
    print(cnt - (counter[a] - 1))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
from scipy.special import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))


Fixed submission:
from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * (c-1) // 2
for a in An:
    print(cnt - (counter[a] - 1))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
cnt = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    elif query[1] == '1':
        if cnt % 2 == 0:
            S = query[2] + S
        else:
            S += query[2]
    else:
        if cnt % 2 == 0:
            S += query[2]
        else:
            S = query[2] + S
if cnt % 2 != 0:
    S = S[::-1]
print(S)


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
cnt = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    elif query[1] == '1':
        if cnt % 2 == 0:
            S.appendleft(query[2])
        else:
            S.append(query[2])
    else:
        if cnt % 2 == 0:
            S.append(query[2])
        else:
            S.appendleft(query[2])
if cnt % 2 != 0:
    S.reverse()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        S = S[::-1]
    elif query[1] == '1':
        S = query[2] + S
    else:
        S += query[2]
print(S)


Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
cnt = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        cnt += 1
    elif query[1] == '1':
        if cnt % 2 == 0:
            S.appendleft(query[2])
        else:
            S.append(query[2])
    else:
        if cnt % 2 == 0:
            S.append(query[2])
        else:
            S.appendleft(query[2])
if cnt % 2 != 0:
    S.reverse()
print(''.join(S))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
possibility = [[], [], []]

for i in range(M):
    for j in range(N):
        if sc[i][0]==j+1:
            possibility[j].append(sc[i][1])
ans = ''
for i in range(N):
    if i == 0:
        if list(set(possibility[i]))[0] == 0:
            ans = -1
            break
        elif possibility[i] == []:
            ans += str(1)
            continue
    if len(possibility[i]) == 0:
        ans += str(0)
        continue
    if len(set(possibility[i])) != 1:
        ans = -1
        break
    ans += str(list(set(possibility[i]))[0])

print(ans)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
possibility = [[], [], []]

for i in range(M):
    for j in range(N):
        if sc[i][0]==j+1:
            possibility[j].append(sc[i][1])

ans = ''
if N > 1:
    for i in range(N):
        if i == 0:
            if (0 in list(set(possibility[i]))) or len(set(possibility[i])) > 1:
                ans = -1
                break
            elif len(possibility[i]) == 0:
                ans += str(1)
                continue
            else:
                ans += str(list(set(possibility[i]))[0])
        else:
            if len(possibility[i]) == 0:
                ans += str(0)
                continue
            elif len(set(possibility[i])) > 1:
                ans = -1
                break
            else:
                ans += str(list(set(possibility[i]))[0])
else:
    if len(set(possibility[0])) > 1:
        ans = -1
    elif len(possibility[0]) == 0:
        ans += str(0)
    else:
        ans += str(list(set(possibility[0]))[0])


print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

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


def cal(number):
    ans = 0
    for X in Xn:
        ans += (X - number)**2
    return ans

ans = sys.maxsize
for i in range(Xn[1], Xn[-1], 1):
    ans = min(ans, cal(i))

print(ans)


Fixed submission:
import sys

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


def cal(number):
    an = 0
    for X in Xn:
        an += (X - number)**2
    return an

ans = sys.maxsize
for i in range(min(Xn), max(Xn)+1, 1):
    ans = min(ans, cal(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
H, N = map(int, input().split())

dp = np.full(H+1, np.inf)
dp[0] = 0

for i in range(N):
    a, b = map(int, input().split())
    dp[1:a+1] = np.minimum(dp[1:a+1], b)
    dp[a+1:] = np.minimum(dp[a+1:], dp[:-a+1]+b)
print(int(dp[-1]))


Fixed submission:
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H, N = map(int, input().split())

dp = [float('inf')]*(H+1)
dp[0] = 0
for i in range(N):
    a, b = map(int, input().split())
    dp[1:a+1] = np.minimum(dp[1:a+1], b)
    for j in range(a+1, H+1):
        dp[j] = min(dp[j], dp[j-a]+b)
print(int(dp[-1]))


Fixed submission:
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])

Buggy python submission (verdict: Runtime Error):
import numpy as np
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
np_ab = np.array(ab)
max_a = max(np_ab[:, 0])
dp = np.full(H+max_a, np.inf)
dp[:max_a] = 0
for i in range(max_a, H+max_a):
    for a, b in ab:
        dp[i] = min(dp[i], dp[i-a] + b)
print(int(dp[-1]))

Fixed submission:
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
np_ab = np.array(ab)
max_a = max(np_ab[:, 0])
dp = np.full(H+max_a, np.inf)
dp[:max_a] = 0
for i in range(max_a, H+max_a):
    for a, b in ab:
        dp[i] = min(dp[i], dp[i-a] + b)
print(int(dp[-1]))


Fixed submission:
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
max_a = max(a for a, b in ab)
dp = [0]*(H+max_a)
for i in range(1, H+max_a):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(dp[H])
Buggy python submission (verdict: Runtime Error):
N = int(input())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)


Fixed submission:
N = int(input())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, N+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

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

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)


Fixed submission:
N = int(input())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, N+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ps = [input().split() for i in range(M)]

ac = 0
wa = [0 for i in range(N)]
ansed = []
for psn in ps:
    if psn[1] == 'AC':
        if psn[0] not in ansed:
            ac += 1
            ansed.append(psn[0])
    else:
        if psn[0] not in ansed:
            wa[int(psn[0])-1] += 1
for i in range(N):
    if str(i+1) not in ansed:
        wa[i] = 0

print(ac, sum(wa))

Fixed submission:
N, M = map(int, input().split())
ps = [input().split() for i in range(M)]

ac = 0
wa = [0 for i in range(N)]
ansed = set()
for psn in ps:
    if psn[1] == 'AC':
        if psn[0] not in ansed:
            ac += 1
            ansed.add(psn[0])
    else:
        if psn[0] not in ansed:
            wa[int(psn[0])-1] += 1
for i in range(N):
    if str(i+1) not in ansed:
        wa[i] = 0

print(ac, sum(wa))

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

ac = 0
wa = []
ansed = []
for psn in ps:
    if psn[1] == 'AC':
        if psn[0] not in ansed:
            ac += 1
            ansed.append(psn[0])
    else:
        if psn[0] not in ansed:
            wa[int(psn[0])-1] += 1
for i in range(N):
    if str(i+1) not in ansed:
        wa[i] = 0

print(ac, sum(wa))

Fixed submission:
N, M = map(int, input().split())
ps = [input().split() for i in range(M)]

ac = 0
wa = [0 for i in range(N)]
ansed = set()
for psn in ps:
    if psn[1] == 'AC':
        if psn[0] not in ansed:
            ac += 1
            ansed.add(psn[0])
    else:
        if psn[0] not in ansed:
            wa[int(psn[0])-1] += 1
for i in range(N):
    if str(i+1) not in ansed:
        wa[i] = 0

print(ac, sum(wa))
Buggy python submission (verdict: Runtime Error):
while True:
    i = 2
    ok = True
    while i * i <= x:
        if x % i == 0:
            ok = False
            break
        i += 1
    if ok:
        print(x)
        break
    x += 1

Fixed submission:
import math
X = int(input())


def get_primenumber(number):
    prime_list = []
    # 2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2, number+1))
    while True:
    # search_listの先頭の値が√nの値を超えたら処理終了
        if search_list[0] > math.sqrt(number):
            # prime_listにsearch_listを結合
            prime_list.extend(search_list)
            break
        else:
            # search_listの先頭をprime_listに入れる
            head_num = search_list[0]
            prime_list.append(head_num)
            # search_listの先頭をpopする
            search_list.pop(0)
            # head_numの倍数を取り除く
            search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

prime_list = get_primenumber(100000)

left = 0
right = len(prime_list)-1

if X == 2:
    print(int(2))
elif X > 99991:
    print(int(100003))
else:
    while left <= right:
        mid = (left+right) // 2
        if prime_list[mid] == X:
            ans = prime_list[mid]
            break
        elif prime_list[mid] > X:
            if prime_list[mid-1] < X:
                ans = prime_list[mid]
                break
            else:
                right = mid - 1
        else:
            if prime_list[mid+1] > X:
                ans = prime_list[mid+1]
                break
            else:
                left = mid + 1

    print(int(ans))
Buggy python submission (verdict: Runtime Error):

def resolve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    score = {'r':  P, 's': R, 'p': S}

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ' '
            continue
        ans += score[T[i]]

    print(s)

if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    score = {'r':  P, 's': R, 'p': S}

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ' '
            continue
        ans += score[T[i]]

    print(ans)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    N, K = map(int, input().rstrip().split())
    R, S, P = map(int, input().rstrip().split())
    T = list(input().rstrip())

    score = {"r":  P, "s": R, "p": S}

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ""
            continue
        ans += score[T[i]]

    print(s)

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = list(input())

    score = {'r':  P, 's': R, 'p': S}

    ans = 0
    for i in range(K):
        ans += score[T[i]]

    for i in range(K, N):
        if T[i-K] == T[i]:
            T[i] = ' '
            continue
        ans += score[T[i]]

    print(ans)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

if (b-a) % 2 == 0:
    ans = (b-a)/2
else:
    if (a-1) < (n-b):
        ans = a+((b-a-1)/2)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)/2)

print(int(ans))


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

if (b-a) % 2 == 0:
    ans = (b-a)//2
else:
    if (a-1) < (n-b):
        ans = a+((b-a-1)//2)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)//2)

print(int(ans))

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

if (b-a) % 2 == 0:
    ans = (b-a)/2
else:
    if a-1 = n-b:
        ans = a+((b-a-1)/2)
    elif a-1 == n-b:
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)/2)

print(int(ans))

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

if (b-a) % 2 == 0:
    ans = (b-a)//2
else:
    if (a-1) < (n-b):
        ans = a+((b-a-1)//2)
    elif (a-1) == (n-b):
        ans = n/2
    else:
        ans = n-b+1+((b-a-1)//2)

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
X = int(input())
num = X//100
r = X % 100
li = [0, 1, 2, 3, 4, 5]
flag = False
for i in itertools.product(li, repeat=num):
    if sum(i) == r:
        flag = True
        break
print('1' if flag else '0')

Fixed submission:
X = int(input())
flag = False
for i in range(1, X+1):
    if 100*i <= X <= 105*i:
        flag = True
        break
print('1' if flag else '0')
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
point = [K-Q for _ in range(N)]
for i in range(1, N+1):
    point[i-1] = point[i-1] + A.count(i)
    print('Yes' if point[i-1]>0 else 'No')

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
point = [K-Q]*N
for i in A:
    point[i-1] += 1
for p in point:
    print('Yes' if p > 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())
R = min(R, L+4038)
ans = 10e+10
for i in range(L, R):
    for j in range(i+1, R+1):
        ans = min((i*j)%2019, ans)
print(ans)


Fixed submission:
L, R = map(int, input().split())
R = min(R, L+4038)
ans = 2018
for i in range(L, R):
    for j in range(i+1, R+1):
        ans = min((i*j)%2019, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
lcm = (c*d)//math.gcd(c, d)
a -= 1
ans1 = b - b//c - b//d + b//lcm
ans2 = a - a//c - a//d + a//lcm
print(ans1 - ans2)


Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
lcm = (c*d)//fractions.gcd(c, d)
a -= 1
ans1 = b - b//c - b//d + b//lcm
ans2 = a - a//c - a//d + a//lcm
print(ans1 - ans2)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
x = 0
i = 0
while x <= X:
    x += L[i]
    i += 1
print(i)


Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
x = 0
ans = 1
for i in range(N):
    x += L[i]
    if x > X:
        break
    else:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
am = [int(input()) for _ in range(m)]
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
    if i-1 not in am:
        dp[i] += dp[i-1]
    if i-2 not in am:
        dp[i] += dp[i-2]
    dp[i] %= mod
print(dp[n])


Fixed submission:
n, m = map(int, input().split())
am = set([int(input()) for _ in range(m)])
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
for i in range(1, n+1):
    if i in am:
        continue
    dp[i] = dp[i-2] + dp[i-1] 
    dp[i] %= mod
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
am = [int(input()) for _ in range(m)]
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
    if i-1 not in am:
        dp[i] += dp[i-1]
    if i-2 not in am:
        dp[i] += dp[i-2]
    dp[i] %= mod
print(dp[n])


Fixed submission:
n, m = map(int, input().split())
am = set([int(input()) for _ in range(m)])
mod = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
for i in range(1, n+1):
    if i in am:
        continue
    dp[i] = dp[i-2] + dp[i-1] 
    dp[i] %= mod
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
ans = 0
for i in range(0, n+1):
    for j in range(0, n-i+1):
        check = (n-(i*r + j*g))/b
        if check % 1 == 0 and check >= 0:
            ans += 1
print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())
ans = 0
for i in range(0, n+1):
    for j in range(0, n-i+1):
        check = (n-(i*r + j*g))/b
        if check % 1 == 0 and check >= 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
n = int(input())
an = list(map(int, input().split()))


def gcd(numbers):
    return reduce(fractions.gcd, numbers)


left = [gcd(an[:i]) for i in range(1, n)]
right = [gcd(an[i:]) for i in range(1, n)]

ans = 0
ans = max(ans, right[0], left[-1])
for i in range(1, n-1):
    ans = max(ans, fractions.gcd(left[i-1], right[i]))

print(ans)


Fixed submission:
from fractions import gcd
n = int(input())
an = list(map(int, input().split()))

left = [an[0]]
right = [an[-1]]
for i in range(1, n-1):
    left.append(gcd(left[-1], an[i]))
    right.append(gcd(right[-1], an[-(i+1)]))

ans = max(right[-1], left[-1])
for i in range(n-2):
    ans = max(ans, gcd(left[i], right[-(i+2)]))

print(ans)
Buggy python submission (verdict: Runtime Error):
menu = [int(input()) for _ in range(5)]
ans = 0
mod = []
for time in menu:
    if time % 10 == 0:
        ans += time
    else:
        ans += time
        mod.append(10 - time % 10)
mod.remove(max(mod))
ans += sum(mod)
print(ans)


Fixed submission:
menu = [int(input()) for _ in range(5)]
ans = 0
mod = []
for time in menu:
    if time % 10 == 0:
        ans += time
    else:
        ans += time
        mod.append(10 - time % 10)
try:
    mod.remove(max(mod))
    ans += sum(mod)
except:
    pass
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
memo = defaultdict(int)
for i in range(1, N+1):
    memo[i] = S[:i].count('AC')
for l, r in lr:
    print(memo[r] - memo[l])


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

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
for l, r in lr:
    print(S[l-1:r].count('AC'))


Fixed submission:
N, Q = map(int, input().split())
S = input()
cnt = [0]*(N+1)
for i in range(N):
    cnt[i+1] = cnt[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(cnt[r-1] - cnt[l-1])
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce
N = int(input())
An = list(map(int, input().split()))


def gcd(list):
    return reduce(math.gcd, list)


print(gcd(An))


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


def gcd(list):
    return reduce(fractions.gcd, list)


print(gcd(An))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
Xm = list(map(int, input().split()))
if n >= m:
    print(0)
else:
    Xm.sort()
    check = [Xm[i+1] - Xm[i] for i in range(m-1)]
    check.sort(reverse=True)
    print(sum(check) - check[:n-1])


Fixed submission:
n, m = map(int, input().split())
Xm = list(map(int, input().split()))
Xm.sort()
check = [Xm[i+1] - Xm[i] for i in range(m-1)]
check.sort()
print(sum(check[:max(m-n, 0)]))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
hn = list(map(int, input().split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(0, n):
    for j in range(1, min(k+1, n-i)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hn[i+j]-hn[i]))
print(dp[-1])


Fixed submission:
n, k = map(int, input().split())
hn = list(map(int, input().split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
for i in range(0, n):
    for j in range(1, min(k+1, n-i)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hn[i+j]-hn[i]))
print(dp[-1])