Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop

N, M = map(int,input().split())

# works[i] : M-i日に報酬が得られるリスト
works = [[] for _ in range(10**5)]

for _ in range(N):
    A, B = map(int,input().split())
    # 報酬が得られる日付に応じて格納
    works[A].append(B)

hq = []
ans = 0

for i in range(1,M+1):
    # M-i日から降順に仕事の候補リストを作る
    for w in works[i]:
        # 大きいものから選びたいのでマイナスをかける
        heappush(hq, -w)
    # M-i日の時点で報酬が最大の仕事を選ぶ
    if hq:
        ans += -heappop(hq)

print(ans)

Fixed submission:
from heapq import heappop, heappush
from bisect import bisect
from collections import deque
inf = 10**5


N, M = map(int,input().split())
info = [list(map(int,input().split())) for _ in range(N)]
info = deque(sorted(info))

ans = 0
hq = []

for i in range(M-1,-1,-1):
    index = bisect(info, [M-i,inf])
    for _ in range(index):
        A, B = info.popleft()
        heappush(hq, -B)
    if hq:
        B = -heappop(hq)
        ans += B

print(ans)

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop

N, M = map(int,input().split())

# works[i] : M-i日に報酬が得られるリスト
works = [[] for _ in range(10**4)]

for _ in range(N):
    A, B = map(int,input().split())
    A -= 1
    # 報酬が得られる日付に応じて格納
    works[A].append(B)

hq = []
ans = 0

for i in range(M):
    # M-i日から降順に仕事の候補リストを作る
    for w in works[i]:
        # 大きいものから選びたいのでマイナスをかける
        heappush(hq, -w)
    # M-i日の時点で報酬が最大の仕事を選ぶ
    if hq:
        ans += -heappop(hq)

print(ans)

Fixed submission:
from heapq import heappop, heappush
from bisect import bisect
from collections import deque
inf = 10**5


N, M = map(int,input().split())
info = [list(map(int,input().split())) for _ in range(N)]
info = deque(sorted(info))

ans = 0
hq = []

for i in range(M-1,-1,-1):
    index = bisect(info, [M-i,inf])
    for _ in range(index):
        A, B = info.popleft()
        heappush(hq, -B)
    if hq:
        B = -heappop(hq)
        ans += B

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

S = input()[::-1]
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (j + k * pow(10,i,13)) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (j + (int(s) * pow(10,i,13))) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)

Fixed submission:
mod = 10**9 + 7

S = input()
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (10*j + k) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (10*j + int(s)) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

S = input()[::-1]
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (j + k * pow(10,i,13)) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (j + (int(s) * pow(10,i,13))) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)

Fixed submission:
mod = 10**9 + 7

S = input()
N = len(S)

dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(13):
        if s == "?":
            for k in range(10):
                l = (10*j + k) % 13
                dp[i+1][l] += dp[i][j]
                dp[i+1][l] %= mod
        else:
            l = (10*j + int(s)) % 13
            dp[i+1][l] += dp[i][j]
            dp[i+1][l] %= mod

ans = dp[N][5]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
inf = float('inf')


N = int(input())
A = [int(input()) for _ in range(N)]

color = [A[0]]
for a in A[1:]:
    pos = bisect_left(color, a)
    if pos == 0:
        color.insert(0,a)
    else:
        color[pos-1] = a

ans = len(color)
print(ans)

Fixed submission:
from bisect import bisect_left

N = int(input())
A = [int(input()) for _ in range(N)]

color = [-1]*N

ans = 0
l = N

for i in range(N):
    pos = bisect_left(color, A[i])
    if pos == l:
        ans += 1
    color[pos-1] = A[i]

ans = len([c for c in color if c != -1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    if not n >= r:
        return 0
    r = min(r,n-r)
    res = 1
    for i in range(n-r+1,n+1):
        res *= i
    for i in range(1,r+1):
        res //= i
    return res

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

Fixed submission:
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    if not n >= r:
        return 0
    return factorial(n) // (factorial(n-r)*factorial(r))

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    r = min(r,n-r)
    return factorial(n) // (factorial(n-r)*factorial(r))

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

Fixed submission:
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    if not n >= r:
        return 0
    return factorial(n) // (factorial(n-r)*factorial(r))

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    return factorial(n) // (factorial(n-r)*factorial(r))

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

Fixed submission:
from math import factorial

mod = 10**9 + 7

# 組み合わせ　n_C_r
def comb(n,r):
    if not n >= r:
        return 0
    return factorial(n) // (factorial(n-r)*factorial(r))

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

for i in range(1,K+1):
    ans = cal(i)
    print(ans)
Buggy python submission (verdict: Runtime Error):
mod = 10**9 + 7

N,M = map(int,input().split())
S = "".join(input().split())
T = "".join(input().split())

dp = [[0]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = 1
for j in range(1,M+1):
    dp[0][j] = 1
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] += dp[i][j-1] + dp[i-1][j]
        else:
            dp[i][j] += dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
        dp[i][j] %= mod

ans = dp[N][M]
print(ans)

Fixed submission:
X,A = map(int,input().split())
if X < A:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7

N,M = map(int,input().split())
S = input().split()
T = input().split()

dp = [[-1]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = 1
for j in range(1,M+1):
    dp[0][j] = 1

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = dp[i][j-1] + dp[i-1][j]
        else:
            dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
        dp[i][j] %= mod

ans = dp[N][M]
print(ans)

Fixed submission:
mod = 10**9 + 7

N,M = map(int,input().split())
S = input().split()
T = input().split()

dp = [[-1]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = 1
for j in range(1,M+1):
    dp[0][j] = 1

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = dp[i][j-1] + dp[i-1][j]
        else:
            dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
        dp[i][j] %= mod

ans = dp[N][M]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

mod = 10**9 + 7

N,M = map(int,input().split())
S = input().split()
T = input().split()

dp = [[-1]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = 1
for j in range(1,M+1):
    dp[0][j] = 1

def rec(i,j):
    if dp[i][j] != -1:
        return dp[i][j]
    res = 0
    if S[i-1] == T[j-1]:
        res = rec(i,j-1) + rec(i-1,j)
    else:
        res = rec(i,j-1) + rec(i-1,j) - rec(i-1,j-1)
    res %= mod
    dp[i][j] = res
    return res

ans = rec(N,M)
print(ans)

Fixed submission:
mod = 10**9 + 7

N,M = map(int,input().split())
S = input().split()
T = input().split()

dp = [[-1]*(M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    dp[i][0] = 1
for j in range(1,M+1):
    dp[0][j] = 1

for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = dp[i][j-1] + dp[i-1][j]
        else:
            dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
        dp[i][j] %= mod

ans = dp[N][M]
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

if N == 1:
    print(1)

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

if N == 1:
    print(1)
    exit()

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)

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

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

if N == 1:
    print(1)
    exit()

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():

    import sys
    input = sys.stdin.readline
    from collections import deque


    N = int(input())
    edges = []
    ad = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        a -= 1; b -= 1
        ad[a].append(b)
        ad[b].append(a)
        edges.append((a,b))

    C = deque(map(int,input().split()))

    nodes = [-1]*N

    def dfs(v=0,pv=-1):
        for nv in ad[v]:
            if nv == pv:
                continue
            dfs(nv,v)
        nodes[v] = C.pop()

    dfs()
    ans = 0

    for a,b in edges:
        ans += min(nodes[a],nodes[b])

    print(ans)
    print(*nodes)


if __name__ == "__main__":
    main()

Fixed submission:
def main():

    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**5)
    from collections import deque


    N = int(input())
    edges = []
    ad = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        a -= 1; b -= 1
        ad[a].append(b)
        ad[b].append(a)
        edges.append((a,b))

    C = deque(sorted(map(int,input().split()), reverse=True))

    nodes = [-1]*N

    def dfs(v=0,pv=-1):
        for nv in ad[v]:
            if nv == pv:
                continue
            dfs(nv,v)
        nodes[v] = C.pop()

    dfs()
    ans = 0

    for a,b in edges:
        ans += min(nodes[a],nodes[b])

    print(ans)
    print(*nodes)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from itertools import accumulate


N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
info = [list(map(int,input().split())) for _ in range(M)]

info = sorted(info, key=lambda x:-x[1])

def calc(num):
    res = 0
    for i in range(M):
        B,C = info[i]
        if B <= num:
            res += B*C
            num -= B
        else:
            res += C*num
            num = 0
    return res

cs = [0] + list(accumulate(A))
ans = 0
# i:いくつ変換するか
for i in range(N+1):
    res = cs[N] - cs[i] + calc(i)
    ans = max(ans,res)

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
from itertools import accumulate


N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
info = [list(map(int,input().split())) for _ in range(M)]

info = sorted(info, key=lambda x:-x[1])

calc = [0]
for B, C in info:
    if len(calc) + B <= N+1:
        calc +=[C]*B
    else:
        calc += [C]*(N+1-len(calc))

calc += [0]*(N+1-len(calc))
calc = list(accumulate(calc))

cs = [0] + list(accumulate(A))
ans = 0
# i:いくつ変換するか
for i in range(N+1):
    res = cs[N] - cs[i] + calc[i]
    ans = max(ans,res)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(3001):
    for g in range(3001):
        remain = N - r*R - g*G
        if remain >= 0 and remain % B == 0:
            ans += 1
print(ans)

Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(3001):
    for g in range(3001):
        remain = N - r*R - g*G
        if remain >= 0 and remain % B == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import floor

def divisor(n):
    left = []
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            left.append(p)
            right.append(n//p)
    res = left + right[::-1]
    return res
        
N = int(input())

div = divisor(N)
ans = 0

for d in div:
    if N // (d-1) == N % (d-1):
        ans += (d-1)

print(ans)

Fixed submission:
from math import floor

N = int(input())
ans = 0
sup = floor(pow(N,1/2))
for r in range(1,sup+1):
    if N % r == 0:
        m = N // r - 1
        if 0 <= r <= m-1:
            ans += m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd,numbers)

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

def func(i):
    res = []
    for j,a in enumerate(A):
        if i == j:
            continue
        res.append(a)
    return res

ans = 0

for i in range(N):
    res = gcd_list(func(i))
    if res > ans:
        ans = res

print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd,numbers)

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

res1 = [gcd(A[-1],a) for a in A]

min_res = min(res1)
index = res1.index(min_res)

res1 = [A[i] for i in range(N) if i != index]
res2 = A[:N-1]

res1 = gcd_list(res1)
res2 = gcd_list(res2)

print(max(res1,res2))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353

N = int(input())
A = [int(input()) for _ in range(N)]

S = sum(A)

dp1 = [[0] * (S+1) for _ in range(N+1)]
dp1[0][0] = 1
for i in range(N):
    for r in range(S+1):
        if r + A[i] < S+1:
            dp1[i+1][r+A[i]] += dp1[i][r]
            dp1[i+1][r+A[i]] %= mod
        dp1[i+1][r] += 2 * dp1[i][r]
        dp1[i+1][r] %= mod

dp2 = [[0] * (S+1) for _ in range(N+1)]
dp2[0][0] = 1
for i in range(N):
    for r in range(S+1):
        if r + A[i] < S+1:
            dp2[i+1][r+A[i]] += dp2[i][r]
            dp2[i+1][r+A[i]] %= mod
        dp2[i+1][r] += dp2[i][r]
        dp2[i+1][r] %= mod

res1 = sum(dp1[N][r] for r in range(-(-S//2), S+1))
res2 = dp2[N][S//2] if S % 2 == 0 else 0

ans = pow(3, N, mod) - (3*res1 - 3*res2)
ans %= mod
print(ans)

Fixed submission:
mod = 998244353

N = int(input())
A = [int(input()) for _ in range(N)]

S = sum(A)

dp1 = [[0] * (S+1) for _ in range(N+1)]
dp1[0][0] = 1
for i in range(N):
    for r in range(S+1):
        if r + A[i] < S+1:
            dp1[i+1][r+A[i]] += dp1[i][r]
            dp1[i+1][r+A[i]] %= mod
        dp1[i+1][r] += 2 * dp1[i][r]
        dp1[i+1][r] %= mod

dp2 = [[0] * (S+1) for _ in range(N+1)]
dp2[0][0] = 1
for i in range(N):
    for r in range(S+1):
        if r + A[i] < S+1:
            dp2[i+1][r+A[i]] += dp2[i][r]
            dp2[i+1][r+A[i]] %= mod
        dp2[i+1][r] += dp2[i][r]
        dp2[i+1][r] %= mod

res1 = sum(dp1[N][r] for r in range(-(-S//2), S+1))
res2 = dp2[N][S//2] if S % 2 == 0 else 0

ans = pow(3, N, mod) - (3*res1 - 3*res2)
ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)

res = []

for a in A:
    for b in B:
        res.append(a+b)

res.sort(reverse=True)

res = res[:K]
ans = []

for ab in res:
    for c in C:
        ans.append(ab+c)
    
ans.sort(reverse=True)
ans = ans[:K]

for a in ans:
    print(a)

Fixed submission:
import sys
input = sys.stdin.readline

X,Y,Z,K = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
B = sorted(list(map(int,input().split())),reverse=True)
C = sorted(list(map(int,input().split())),reverse=True)

res = []

for a in A:
    for b in B:
        res.append(a+b)

res.sort(reverse=True)

res = res[:K]
ans = []

for ab in res:
    for c in C:
        ans.append(ab+c)
    
ans.sort(reverse=True)
ans = ans[:K]

for a in ans:
    print(a)
Buggy python submission (verdict: Runtime Error):
N,Q = map(int,input().split())
s = input()
info = [input().split() for _ in range(Q)]

def biserch(ok,ng,judge):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

def left_out(i):
    now = i
    for t, d in info:
        if s[now] == t:
            if d == "L":
                now -= 1
            elif d == "R":
                now += 1
        if now < 0:
            return True
    return False

def right_out(i):
    now = i
    for t, d in info:
        if s[now] == t:
            if d == "L":
                now -= 1
            elif d == "R":
                now += 1
        if now > N-1:
            return True
    return False

left = biserch(ok=-1,ng=N,judge=left_out)
right = biserch(ok=N,ng=-1,judge=right_out)
ans = right - (left + 1)
print(ans)

Fixed submission:
N,Q = map(int,input().split())
s = input()
info = [input().split() for _ in range(Q)]

def left_out():
    left = -1; right = N
    while right - left > 1:
        mid = (left+right) // 2
        if judge(mid) == -1:
            left = mid
        else:
            right = mid
    return left

def right_out():
    left = -1; right = N
    while right - left > 1:
        mid = (left+right) // 2
        if judge(mid) == 1:
            right = mid
        else:
            left = mid
    return right

def judge(i):
    now = i
    for t, d in info:
        if s[now] == t:
            if d == "L":
                now -= 1
            elif d == "R":
                now += 1
        if now < 0:
            return -1
        elif N <= now:
            return 1
    return 0
    
left = left_out()
right = right_out()
ans = right - left - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
def xor(data):
    res = data[0]
    for i in range(1,len(data)):
        res ^= data[i]
    return res

A,B = map(int,input().split())
num = B-A+1
data = []
cut = 0
if A % 2 == 0:
    cut = (num) // 2
    if cut == 1:
        data.append(1)
    if num % 2 == 1:
        data.append(B)
else:
    data.append(A)
    cut = (num-1) // 2
    if cut == 1:
        data.append(1)
    if (num-1) % 2 == 1:
        data.append(B)
ans = xor(data)
print(ans)

Fixed submission:
def xor(data):
    if not data:
        return 0
    res = data[0]
    for i in range(1,len(data)):
        res ^= data[i]
    return res

A,B = map(int,input().split())
if A == B:
    print(A)
    exit()
num = B-A+1
data = []
cut = 0
if A % 2 == 0:
    cut = (num) // 2
    if cut % 2 == 1:
        data.append(1)
    if num % 2 == 1:
        data.append(B)
else:
    data.append(A)
    cut = (num-1) // 2
    if cut % 2 == 1:
        data.append(1)
    if (num-1) % 2 == 1:
        data.append(B)
ans = xor(data)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
# dp[i] 足場iに辿り着くまでに支払うコストの総和の最小値
# dp[0] = 0, dp[1] = 0, dp[2] = abs(h[1] - h[0])
dp = [float("inf") for i in range(N+1)]
dp[0] = 0; dp[1] = 0
dp[2] = abs(h[1] - h[0])
for i in range(3,N+1):
    for j in range(1,min(i,K+1)):
        if dp[i-j] + abs(h[i-1] - h[i-j-1]) < dp[i]:
            dp[i] = dp[i-j] + abs(h[i-1] - h[i-j-1])
print(dp[N])

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
# dp[i] 足場iに辿り着くまでに支払うコストの総和の最小値
# dp[0] = 0, dp[1] = 0, dp[2] = abs(h[1] - h[0])
dp = [float("inf") for i in range(N+1)]
dp[0] = 0; dp[1] = 0
dp[2] = abs(h[1] - h[0])
for i in range(3,N+1):
    for j in range(1,min(i,K+1)):
        if dp[i-j] + abs(h[i-1] - h[i-j-1]) < dp[i]:
            dp[i] = dp[i-j] + abs(h[i-1] - h[i-j-1])
print(dp[N])