Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
sum = 0
cnt = []
for i in range(N-1):
    if A[i] in cnt:
        sum += a
    else:
        for j in range(i+1, N):
            a = A[i] ^ A[j]
            sum += a
print(sum%1000000007)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# あるbit列に対するコストの計算
def count(zerone):
    one = 0
    cnt = 0
    for i in range(N):
        flag = True
        if zerone[i] == 1:
            one += 1
            for j in range(len(A[i])):
                if A[i][j][1] != zerone[A[i][j][0]-1]:
                    flag = False
                    break
        if flag:
            cnt += 1
    if cnt == N:
        return one
    else:
        return 0

# bit列の列挙
def dfs(bits):
    if len(bits) == N:
        return count(bits)
    res = 0
    for i in range(2):
        bits.append(i)
        res = max(res, dfs(bits))
        bits.pop()
    return res

# main
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        A[i].append([int(x) for x in input().split()])

ans = dfs([])
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)//(math.factorial(m) * math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))

Fixed submission:
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD

MOD = 10**9+7
x, y = map(int, input().split())
s, t = (-x+2*y)/3, (2*x-y)/3

if s < 0 or t < 0:
    ans = 0
elif not (s.is_integer() and t.is_integer()):
    ans = 0
else:
    s, t = int(s), int(t)
    COMinit()
    ans = COM((s+t), s)

print(ans)

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

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3

if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))

Fixed submission:
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD

MOD = 10**9+7
x, y = map(int, input().split())
s, t = (-x+2*y)/3, (2*x-y)/3

if s < 0 or t < 0:
    ans = 0
elif not (s.is_integer() and t.is_integer()):
    ans = 0
else:
    s, t = int(s), int(t)
    COMinit()
    ans = COM((s+t), s)

print(ans)

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

x, y = map(int, input().split())
m = (2*x-y)/3
n = (-x+2*y)/3
print(m,n)
if m.is_integer() == n.is_integer() == True:
    ans = math.factorial(m+n)/(math.factorial(m)*math.factorial(n))
else:
    ans = 0

print(int(ans%(10**9+7)))

Fixed submission:
MAX = 1000010
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD

MOD = 10**9+7
x, y = map(int, input().split())
s, t = (-x+2*y)/3, (2*x-y)/3

if s < 0 or t < 0:
    ans = 0
elif not (s.is_integer() and t.is_integer()):
    ans = 0
else:
    s, t = int(s), int(t)
    COMinit()
    ans = COM((s+t), s)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
zeroone = list(input())

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)

if zeroone[0] == "<":
    for j in range(0, cnt[1]):
            ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] == "<" and zeroone[i] == ">":
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1

        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

if zeroone[-1] == ">":
    for k in range(cnt[-2], cnt[-1])[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Fixed submission:
# coding: utf-8

S = list(input())
S.append("end")

def count(r, l):
    part_sum = ((r-1)*r + (l-1)*l)/2 #"<<<>>>"頂点の値以外
    part_max = max(r, l) #"<<<>>>"頂点の値
    return(part_sum + part_max)

ans = 0
r = l = 0
for i in range(len(S)-1):
    if S[i+1] != S[i] and S[i] == ">": #"<<<>>>"をセットとして足す
        r += 1
        ans += count(r, l)
        r = l = 0
    elif S[i] == "<":
        l += 1
    elif S[i] == ">":
        r += 1
ans += count(r, l) #"<"終わりの時は、その分がカウントされないので足す(ただしl = 0)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

ans = [0] * (len(zeroone)+1)

if zeroone[0] == 1:
    for j in range(0, cnt[1]):
            ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1
        
        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

if zeroone[-1] == -1:
    for k in range(cnt[-2], cnt[-1])[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Fixed submission:
# coding: utf-8

S = list(input())
S.append("end")

def count(r, l):
    part_sum = ((r-1)*r + (l-1)*l)/2 #"<<<>>>"頂点の値以外
    part_max = max(r, l) #"<<<>>>"頂点の値
    return(part_sum + part_max)

ans = 0
r = l = 0
for i in range(len(S)-1):
    if S[i+1] != S[i] and S[i] == ">": #"<<<>>>"をセットとして足す
        r += 1
        ans += count(r, l)
        r = l = 0
    elif S[i] == "<":
        l += 1
    elif S[i] == ">":
        r += 1
ans += count(r, l) #"<"終わりの時は、その分がカウントされないので足す(ただしl = 0)
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
n = int(math.sqrt(N))

while n < N:
    if (N/n).is_integer() == True:
        print(int(N/n + n - 2))
        break
    else:
        n += 1

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

import math
import bisect
N = int(input())
N_list = sorted(make_divisors(N))
p = bisect.bisect_left(N_list, math.sqrt(N))
n = N_list[p]
print(int(N/n + n - 2))
Buggy python submission (verdict: Runtime Error):
import math
 
a, b, x = map(int, input().split())
if x <= a*a*b/2:
    p = math.degrees(math.atan(b/(2*x/(a*b))))
else:
    p = 90-math.degrees(math.atan(a/2/(b - x/(a*a))))

print(p)

Fixed submission:
import math
 
a, b, x = map(int, input().split())
if x == a*a*b:
    p = 0
elif x <= a*a*b/2:
    p = math.degrees(math.atan(b/(2*x/(a*b))))
else:
    p = 90-math.degrees(math.atan(a/2/(b - x/(a*a))))

print(p)

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

a, b, x = map(int, input().split())
if x <= a*a*b/2:
    y = 2*x/(a*b)
    X = math.degrees(math.atan(b/y))
else:
    y = b - x/(a*a)
    X = 90-math.degrees(math.atan(a/2/y))

print(round(X, 10))

Fixed submission:
import math
 
a, b, x = map(int, input().split())
if x == a*a*b:
    p = 0
elif x <= a*a*b/2:
    p = math.degrees(math.atan(b/(2*x/(a*b))))
else:
    p = 90-math.degrees(math.atan(a/2/(b - x/(a*a))))

print(p)

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

a, b, x = map(int, input().split())
if x <= a*a*b/2:
    y = 2*x/(a*b)
    X = math.degrees(math.atan(b/y))
else:
    y = b - x/(a*a)
    X = 90-math.degrees(math.atan(a/2/y))

print(X)

Fixed submission:
import math
 
a, b, x = map(int, input().split())
if x == a*a*b:
    p = 0
elif x <= a*a*b/2:
    p = math.degrees(math.atan(b/(2*x/(a*b))))
else:
    p = 90-math.degrees(math.atan(a/2/(b - x/(a*a))))

print(p)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

if sum(A) < K:
    K = sum(A)

A.sort()
F.sort()
F = F[::-1]

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    sum = 0
    G = A - (mid // F)
    for i in range(N):
        sum += max(0, G[i])
    if sum <= K:
        right = mid
    else:
        left = mid + 1

print(right)

Fixed submission:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

if sum(A) < K:
    K = sum(A)

A.sort()
F.sort()
F = F[::-1]

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    sum = 0
    G = A - (mid // F)
#    for i in range(N):
#        sum += max(0, G[i])
    if G[G>0].sum() <= K:
        right = mid
    else:
        left = mid + 1

print(right)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

if sum(A) < K:
    K = sum(A)

A.sort()
F.sort(reverse = True)
G = [A[i]*F[i] for i in range(N)]

for i in range(K):
    g = G.index(max(G))
    A[g] -= 1
    G[g] = A[g] * F[g]

print(max(G))

Fixed submission:
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

if sum(A) < K:
    K = sum(A)

A.sort()
F.sort()
F = F[::-1]

left = 0
right = 10 ** 12
while left < right:
    mid = (left + right) // 2
    sum = 0
    G = A - (mid // F)
#    for i in range(N):
#        sum += max(0, G[i])
    if G[G>0].sum() <= K:
        right = mid
    else:
        left = mid + 1

print(right)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        res = L[i] + L[j]
        num = bisect.bisect_left(L[j+1:], res)
        ans += num
print(ans)

Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[k] >= L[i]+L[j]:
                break
            else:
                cnt += 1
print(cnt)

Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                ans.append(0)
print(len(ans))

Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] < L[j]+L[k] and L[j] < L[k]+L[i] and L[k] < L[i]+L[j]:
                ans.append(0)
print(len(ans))

Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1)

print(cnt)
Buggy python submission (verdict: Runtime Error):
S = list(input())

Odd = S[0::2]
Even = S[1::2]

for i in range(len(Odd)):
    if 'L' == Odd[i]:
        l = 0
        break
    else:
        l = 1

for j in range(len(Even)):
    if 'R' == Even[j]:
        r = 0
        break
    else:
        r = 1

if l+r == 2:
    print('Yes')
else:
    print('No')

Fixed submission:
S = list(input())

Odd = S[0::2]
Even = S[1::2]

for i in range(len(Odd)):
    if 'L' == Odd[i]:
        l = 0
        break
    else:
        l = 1

r = 1
for j in range(len(Even)):
    if 'R' == Even[j]:
        r = 0
        break
    else:
        r = 1

if l+r == 2:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
S = list(input())

Odd = S[0::2]
Even = S[1::2]

for i in range(len(Odd)):
    if 'L' == Odd[i]:
        c = 0
    else:
        for j in range(len(Even)):
            if 'R' == Even[j]:
                c = 0
            else:
                c = 1

if c == 1:
    print('Yes')
else:
    print('No')

Fixed submission:
S = list(input())

Odd = S[0::2]
Even = S[1::2]

for i in range(len(Odd)):
    if 'L' == Odd[i]:
        l = 0
        break
    else:
        l = 1

r = 1
for j in range(len(Even)):
    if 'R' == Even[j]:
        r = 0
        break
    else:
        r = 1

if l+r == 2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
A = []
for _ in range(Q):
    A.append(int(input()))

point = [K] * N

def mainasu(n):
    return n-1

for i in range(Q):
    point = list(map(mainasu, point))
    point[A[i] - 1] += 1

for j in range(N):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')

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

point = [K-Q] * N

for i in range(Q):
    point[A[i] - 1] += 1

for j in range(N):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Runtime Error):
N, K, Q = map(int, input().split())
A = []
for _ in range(Q):
    A.append(int(input()))

point = [K] * N

for i in range(Q):
    if A[i] == i:
        break
    else:
        point[i] -= 1

for j in range(N):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')

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

point = [K-Q] * N

for i in range(Q):
    point[A[i] - 1] += 1

for j in range(N):
    if point[j] > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

MAX_1 = max(A)
MAX_2 = sorted(set(A))[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if i == A.index(MAX_1):
        print(MAX_2)
    else:
        print(MAX_1)

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    kari = A[i]
    A[i] = 0
    print(max(A))
    A[i] = kari

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []

S = [0] * (N+1)
for i in range(N):
    A.append(int(input()))
    S[i+1] = S[i] + A[i]

for i in range(N):
    MAX = -float('inf')
    for j in range(N):
        if j == i:
            continue
        else:
            MAX = max(MAX, S[j+1] - S[j])
    print(MAX)

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

for i in range(N):
    kari = A[i]
    A[i] = 0
    print(max(A))
    A[i] = kari

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

MAX_1 = max(A)
MAX_2 = sorted(A)[-2]

for i in range(N):
    if A[i] == MAX_1:
        print(MAX_2)
    else:
        print(MAX_1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

d = dict()
for i in range(N):
    d[A[i]] = d.get(A[i], 0) + 1

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and (k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1]):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')


Fixed submission:
from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]

d = Counter(A)

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and ((k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1])):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

d = dict()
for i in range(N):
    d[A[i]] = d.get(A[i], 0) + 1

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and (k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1]):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')

Fixed submission:
from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]

d = Counter(A)

if len(d) > 3:
    print('No')

else:
    k = list(d.keys())
    v = list(d.values())
    
    # a1 ^ a2 ^ a3 = 0 and an: N/3
    if len(d) == 3 and k[0]^k[1]^k[2] == 0 and v[0]==v[1]==v[2]:
        print('Yes')
    
    # a1: 2N/3, 0: N/3
    elif len(d) == 2 and ((k[0] == 0 and v[1] == 2*v[0]) or (k[1] == 0 and v[0] == 2*v[1])):
        print('Yes')
    
    # 0: N
    elif len(d) == 1 and k[0] == 0:
        print('Yes')
    
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
l = ('A', 'T', 'C', 'G')
S = input()

ans = [0]
for i in range(len(S)):
    if S[i] in l:
        res += 1
    elif res != 0:
        ans.append(res)
        res = 0

print(max(ans))

Fixed submission:
l = ('A', 'T', 'C', 'G')
S = input()

ans, res = 0, 0
for i in range(len(S)):
    if S[i] in l:
        res += 1
    else:
        ans = max(ans, res)
        res = 0
ans = max(ans, res)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

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

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

print(dp[-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

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

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

import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype=np.int64)
h = np.append(h, [0]*K)

dp = np.full(N+K, np.inf)
dp[0] = 0

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

print(int(dp[N-1]))

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

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

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

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

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [INF] * (N+K)
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
a = [0] * (N+1)
for i in range(N):
    a[i] = list(map(int, input().split()))
dp = np.zeros((N+1, 3), dtype=np.int64)

for n in range(N):
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            dp[n+1][i] = max(dp[n+1][i], dp[n][j] + a[n][i])
ans = max(dp[N])

print(ans)

Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

A, B, C = 0, 0, 0 #最後に各活動を行った幸福度の和
for _ in range(N):
    a, b, c = map(int, input().split())
    A, B, C = max(B, C) + a, max(C, A) + b, max(A, B) + c
ans = max(A, B, C)

print(ans)

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

import numpy as np

N = int(input())
a = [0] * (N+1)
for i in range(N):
    a[i] = list(map(int, input().split()))
dp = np.zeros((N+1, 3), dtype=np.int64)

for n in range(N):
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            dp[n+1][i] = max(dp[n+1][i], dp[n][j] + a[n][i])
ans = max(dp[N])

print(ans)

Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

A, B, C = 0, 0, 0 #最後に各活動を行った幸福度の和
for _ in range(N):
    a, b, c = map(int, input().split())
    A, B, C = max(B, C) + a, max(C, A) + b, max(A, B) + c
ans = max(A, B, C)

print(ans)