Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a, b =map(int, input().spulit())

c = abs(a-b)
print('Yey!' if c<=2 else ':(')

Fixed submission:
a, b =map(int, input().split())
print('Yay!' if a<=8 and b <= 8 else ':(')
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import sys
import numpy as np

sys.setrecursionlimit(10**8)

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

@lru_cache(maxsize=None)
def dp(*x):
    xnum = np.array(x)
    x_seki = xnum.prod()
    result = 0
    while x_seki % 1 == 0:
        x_seki /= 2
        result += 1
    return result - 1
print(dp(*X))



Fixed submission:
N = input()
xs = map(int, input().split())
cnt = lambda n: bin(n)[::-1].find('1')
print(sum(cnt(x) for x in xs))
Buggy python submission (verdict: Runtime Error):
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

for i in range(1, N):
	if S[i] == '#' and S[i-1] == '#':
		print('No')
		sys.exit()

if C < D:
	print('Yes')
	sys.exit()

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

if S[B+1] == '.' and S[B+2] == '.':
	print('Yes')
	sys.exit()

if B == D - 1:
	print('Yes')
        sys.exit()

for i in range(B, D-1):
	if S[i] == '#':
		if S[i+1] == '.' and S[i+2] == '.' and S[i+3] == '.':
			print('Yes')
			sys.exit()

print('No')
sys.exit()

Fixed submission:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, A_, B_, C_, D_ = rrs()
A, B, C, D = [i-1 for i in [A_, B_, C_, D_]]
S = rr()

for i in range(A, max(C, D)):
	if S[i] == '#' and S[i+1] == '#':
		print('No')
		sys.exit()

if C < D:
	print('Yes')
	sys.exit()

if S[B-1] == '.' and S[B+1] == '.':
	print('Yes')
	sys.exit()

if S[B+1] == '.' and S[B+2] == '.':
	print('Yes')
	sys.exit()
	
for i in range(B, D-1):
	if S[i] == '#':
		if S[i+1] == '.' and S[i+2] == '.' and S[i+3] == '.':
			print('Yes')
			sys.exit()

print('No')
sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

N, M = rrs()
A = rrs()

for i in range(M):
    B, C = rrs()
    A.extend([C] * B)

A.sort(reverse=True)

print(sum(A[:N]))

Fixed submission:
import sys
rr = lambda: sys.stdin.readline().strip()
rri = lambda: int(rr())
rrs = lambda: [int(_) for _ in rr().split()]

from operator import itemgetter

N, M = rrs()
A = rrs()

data = [rrs() for _ in range(M)]

data.sort(key=itemgetter(1), reverse=True)

p = 0
for d in data:
    if p <= N:
        A.extend([d[1]] * d[0])
    p += d[0]

A.sort(reverse=True)

print(sum(A[:N]))
Buggy python submission (verdict: Runtime Error):
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

S = rr()

if not 1 <= int(S[:1]) <= 12:
    if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('YYMM')
elif not 1 <= int(S[2:]) <= 12:
	if not 1 <= int(S[1:]) <= 12:
        print('NA')
    else:
        print('MMYY')
else:
    print('AMBIGUOUS')

Fixed submission:
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

S = rr()

if not 1 <= int(S[:2]) <= 12:
    if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('YYMM')
elif not 1 <= int(S[2:]) <= 12:
	print('MMYY')
else:
    print('AMBIGUOUS')

Buggy python submission (verdict: Runtime Error):
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

S = rr()

if not 1 <= int(S[:1]) <= 12:
    if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('YYMM')
elif not 1 <= int(S[2:]) <= 12:
	if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('MMYY')
else:
    print('AMBIGUOUS')

Fixed submission:
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

S = rr()

if not 1 <= int(S[:2]) <= 12:
    if not 1 <= int(S[2:]) <= 12:
        print('NA')
    else:
        print('YYMM')
elif not 1 <= int(S[2:]) <= 12:
	print('MMYY')
else:
    print('AMBIGUOUS')
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        tmp = N - R * r - G * g
        if tmp >= 0 and tmp % B == 0:
            ans += 1
print(ans)

Fixed submission:
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

R, G, B, N = rs()

cnt = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        if (N - (r*R + g*G))%B == 0 and (N - (r*R + g*G)) >= 0:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
import sys
from math import gcd

def input():
	return sys.stdin.readline()

N = int(input())
A = [int(_) for _ in input().split()]
p1 = [0] * N
p2 = [0] * N

p1[0] = A[0]
p2[-1] = A[-1]

for i in range(1, N):
	p1[i] = gcd(p1[i-1], A[i])
	p2[-(i+1)] = gcd(p2[-i], A[-(i+1)])

m = max(p1[-2], p2[1])

if N > 2:
	for i in range(1, N-1):
		m = max(m, gcd(p1[i-1], p2[i+1]))

print(m)

Fixed submission:
import sys
from fractions import gcd

def input():
	return sys.stdin.readline()

N = int(input())
A = [int(_) for _ in input().split()]
p1 = [0] * N
p2 = [0] * N

p1[0] = A[0]
p2[-1] = A[-1]

for i in range(1, N):
	p1[i] = gcd(p1[i-1], A[i])
	p2[-(i+1)] = gcd(p2[-i], A[-(i+1)])

m = max(p1[-2], p2[1])

if N > 2:
	for i in range(1, N-1):
		m = max(m, gcd(p1[i-1], p2[i+1]))

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import fractions
from functools import reduce

def input():
	return sys.stdin.readline()

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

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

ans = 0
for i in range(N):
	if i == 0:
		A_ = A[1:]
	elif i == N-1:
		A_ = A[:-1]
	else:
		A_ = A[:i]+A[i+1:]
	ans = max(ans, gcd(A_))

print(ans)


Fixed submission:
import sys
from fractions import gcd

def input():
	return sys.stdin.readline()

N = int(input())
A = [int(_) for _ in input().split()]
p1 = [0] * N
p2 = [0] * N

p1[0] = A[0]
p2[-1] = A[-1]

for i in range(1, N):
	p1[i] = gcd(p1[i-1], A[i])
	p2[-(i+1)] = gcd(p2[-i], A[-(i+1)])

m = max(p1[-2], p2[1])

if N > 2:
	for i in range(1, N-1):
		m = max(m, gcd(p1[i-1], p2[i+1]))

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import fractions
from functools import reduce

def input():
	return sys.stdin.readline()

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

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

ans = 0
for i in range(N):
	if i == 0:
		A_ = A[1:]
	elif i == N-1:
		A_ = A[:-1]
	else:
		A_ = A[:i]+A[i+1:]
	ans = max(ans, gcd(A_))

print(ans)

Fixed submission:
import sys
from fractions import gcd

def input():
	return sys.stdin.readline()

N = int(input())
A = [int(_) for _ in input().split()]
p1 = [0] * N
p2 = [0] * N

p1[0] = A[0]
p2[-1] = A[-1]

for i in range(1, N):
	p1[i] = gcd(p1[i-1], A[i])
	p2[-(i+1)] = gcd(p2[-i], A[-(i+1)])

m = max(p1[-2], p2[1])

if N > 2:
	for i in range(1, N-1):
		m = max(m, gcd(p1[i-1], p2[i+1]))

print(m)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

def changeS(S):
	S_ = ['_'] * N
	for i in range(N-1):
		if S[i] == 'A' and S[i+1] == 'C':
			S_[i] = 'A'
	return S_

def cntdivS(S_, pi):
	return S_[pi[0]:pi[1]].count('A')

S_ = changeS(S)

for pi in p:
	print(cntdivS(S_, pi))

Fixed submission:
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(i) for i in input().split()]
S = input()
l, r = [[None] * Q for _ in range(2)]
for i in range(Q):
  l[i], r[i] = [int(i) for i in input().split()]

for i in range(Q):
  s = S[l[i]-1:r[i]]
  f = False
  count = 0
  for n in s:
    if n == 'A':
      if not f:
        f = True
    elif n == 'C':
      if f:
        count += 1
        f = False
    else:
      f = False
  print(count)


Fixed submission:
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(i) for i in input().split()]
S = input()
l, r = [[None] * Q for _ in range(2)]
for i in range(Q):
  l[i], r[i] = [int(i) for i in input().split()]
  
for i in range(Q):
  s = S[l[i]-1:r[i]]
  
  count = 0
  i = s.find('AC')
  while i >= 0:
    count += 1
    i = s.find('AC', i+2)
  
  print(count)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(i) for i in input().split()]
S = input()
l, r = [[None] * Q for _ in range(2)]
for i in range(Q):
  l[i], r[i] = [int(i) for i in input().split()]

for i in range(Q):
  s = S[l[i]-1:r[i]]
  f = False
  count = 0
  for n in s:
    if n == 'A':
      if not f:
        f = True
    elif n == 'C':
      if f:
        count += 1
        f = False
    else:
      f = False
  print(count)

Fixed submission:
import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])
Buggy python submission (verdict: Runtime Error):
import sys
from bisect import bisect_right
input = sys.stdin.readline().strip()
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Fixed submission:
import sys
from bisect import bisect_right
input = sys.stdin.readline
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(N, A):
	a = min(A)
	flag = False
	while not flag:
		flag = True
		for i in A:
			if i % a == 0:
				i = a
			else:
				i = i % a
				flag = False
		a = min(A)
	return a
	
N = int(input())
A = [int(i) for i in input().split()]
#N = 4
#A = [2, 10, 8, 40]
print(slv(N, A))

Fixed submission:
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(N, A):
	flag = True
	while len(A) > 1:
		m = min(A)
		A = [a % m for a in A if a % m != 0]
		A.append(m)
		print(A, file=sys.stderr)
	return m


N = int(input())
A = [int(i) for i in input().split()]
'''
N = 5
A = [13, 5, 18, 100000000]
'''
print(slv(N, A))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(N, A):
	a = min(A)
	flag = False
	while not flag:
		flag = True
		for i in A:
			if i % a == 0:
				i = a
			else:
				i = i % a
				flag = False
		a = min(A)
	return a
	
N = int(input().split())
A = [int(i) for i in input().split())]
#N = 4
#A = [2, 10, 8, 40]
print(slv(N, A))

Fixed submission:
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(N, A):
	flag = True
	while len(A) > 1:
		m = min(A)
		A = [a % m for a in A if a % m != 0]
		A.append(m)
		print(A, file=sys.stderr)
	return m


N = int(input())
A = [int(i) for i in input().split()]
'''
N = 5
A = [13, 5, 18, 100000000]
'''
print(slv(N, A))
Buggy python submission (verdict: Runtime Error):
# import bisect
# import heapq
# import math
# import random
# from collections import Counter, defaultdict, deque
# from decimal import Decimal
# from functools import lru_cache, reduce
# from itertools import combinations, combinations_with_replacement, product, permutations
# from operator import add, mul, sub, itemgetter
# import numpy as np

import sys
sys.setrecursionlimit(10000)

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def read_int(input):
	if input == None:
		input = sys.stdin.readline().strip()
	ret = [int(x) for x in input.split()]
	if len(ret) == 1:
		ret = ret[0]
	return ret

def read_float(input):
	if input == None:
		input = sys.stdin.readline().strip()
	ret = [float(x) for x in input.split()]
	if len(ret) == 1:
		ret = ret[0]
	return ret
	
def read_str(input):
	if input == None:
		input = sys.stdin.readline().strip()
	ret = [x for x in input.split()]
	if len(ret) == 1:
		ret = ret[0]
	return ret
		
@mt
def slv(*args): 
	# 処理
	# ここから
	
	if max(L) < sum(L) - max(L):
		ans = 'Yes'
	else:
		ans = 'No'
	
	# ここまで
	return ans

if __name__ == '__main__':
	
	# テスト用入力
	t = '''4
3 8 5 1'''.splitlines()
	
	# 入力 (変数= read_xxx(test[行数]))
	# ここから
	
	N = read_int()
	L = read_int()
	
	# ここまで
		
	# 出力
	# ここから
	
	print(slv(N, L))
	
	# ここまで

Fixed submission:
N = int(input())
L = [int(x) for x in input().split()]

res = 'Yes'
for i in range(N):
	if L[i] >= sum(L[:i]) + sum(L[i + 1:]):
		res = 'No'

print(res)

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

res = 'Yes'
for i in range(N):
	if L[i] >= sum(L[:i]) + sum(L[i + 1:]):
		res = 'No'

print(res

Fixed submission:
N = int(input())
L = [int(x) for x in input().split()]

res = 'Yes'
for i in range(N):
	if L[i] >= sum(L[:i]) + sum(L[i + 1:]):
		res = 'No'

print(res)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
L = [[0] * 3 for _ in range(N)]

for i in range(N):
    L[i][0], L[i][1] = [int(i) for i in input().split()]
    L[i][2] = L[i][0] + L[i][1]

L.sort(key=lambda x:x[2], reverse=True)

print(sum(L[::2][0]) - sum(L[1::2][1]))

Fixed submission:
N = int(input())
A = [0] * N
B = [0] * N
Sum = [[0] * 2 for i in range(N)]

for i in range(N):
    A[i], B[i] = map(int, input().split())
    Sum[i][0] = i
    Sum[i][1] = A[i] + B[i]
    
a = 0
b = 0
turn = 0

Sum.sort(key=lambda x:x[1], reverse=True)
    
for i in range(N):
    if turn == 0:
        a += A[Sum[i][0]]
        turn = 1
    else:
        b += B[Sum[i][0]]
        turn = 0

print(a - b)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
h = np.ndarray(input().split(), dtype='int32')
dp = np.zeros(N, dtype='int32')

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

print(dp[-1])

Fixed submission:
N = int(input())
h = [int(i) for i in input().split()]

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

for i in range(2, N):
    dp_1 = dp[i-2] + abs(h[i]-h[i-2])
    dp_2 = dp[i-1] + abs(h[i]-h[i-1])
    dp[i] = min(dp_1, dp_2)
    
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

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

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, K+1):
        if i - k >= 0:
            dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])

Fixed submission:
import sys
def input():
    return sys.stdin.readline()
    
N, K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for k in range(1, min(K+1, i+1)):
        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = [int(i) for i in input().split()]
weight, value = [0] * N, [0] * N
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

dp = [[0] * (W+1) for _ in range(N)]
dp[0][weight[0]] = value[0]
for i in range(1, N):
    for w in range(W+1):
        if w-weight[i] >= 0:
            dp[i][w] = max(dp[i-1][w-weight[i]]+value[i], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(max(dp[N-1]))

Fixed submission:
N, W = [int(i) for i in input().split()]
weight, value = [0] * N, [0] * N
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

dp = [[0] * (W+1) for _ in range(N)]
dp[0][weight[0]] = value[0]
for i in range(1, N):
    for w in range(W+1):
        if w-weight[i] >= 0:
            dp[i][w] = max(dp[i-1][w-weight[i]]+value[i], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(max(dp[N-1]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

N, W = rs()
d = [rs() for _ in range(N)]

dp = [[0 for _ in range(W+1)] for __ in range(N)]

for i in range(N):
    for w in range(W+1):
        if w >= d[i][0]:
            dp[i][w] = max(dp[i-1][w-d[i][0]] + d[i][1], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]

print(max(dp[-1]))

Fixed submission:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N, W = ri_()
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = ri_()
dp = [[INF] * (N * (10 ** 3) + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(N * (10 ** 3) + 1):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
        else:
            dp[i + 1][j] = dp[i][j]
ans = 0
for j in range(N * (10 ** 3) + 1):
    if dp[N][j] <= W:
        ans = max(ans, j)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [0] * N
max_value = 0

for i in range(N):
    p[i] = int(input())
    max_value = max(max_value, p[i])

price = sum(p) - max_value / 2
print(int(price)

Fixed submission:
N = int(input())
p = [0] * N
max_value = 0

for i in range(N):
    p[i] = int(input())
    max_value = max(max_value, p[i])

price = sum(p) - max_value / 2
print(int(price))
Buggy python submission (verdict: Runtime Error):
n = input()
ans = []
for ni in n:
    if ni == '1':
        ans.append('9')
    elif ni == '9':
        ans.append('1')
    else:
        ans.append(ni)
print(ans[0]+ans[1]+ans[2])

Fixed submission:
n = input()
ans = []
for ni in n:
    if ni == '1':
        ans.append('9')
    elif ni == '9':
        ans.append('1')
    else:
        ans.append(ni)
print(ans[0]+ans[1]+ans[2])