Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
'''input
2 2
3
2 1 1
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
if li == 1:
	print li[-1]**2
else:
	if c[li[-1]] >= 4:
		print li[-1]**2
	else:
		print li[-1]*li[-2]

Fixed submission:
'''input
4
1 2 3 4
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
if len(li) == 0:
	print "0"
elif len(li) == 1:
	print li[-1]**2
else:
	if c[li[-1]] >= 4:
		print li[-1]**2
	else:
		print li[-1]*li[-2]

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
print li[-1]*li[-2]


Fixed submission:
'''input
4
1 2 3 4
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
if len(li) == 0:
	print "0"
elif len(li) == 1:
	print li[-1]**2
else:
	if c[li[-1]] >= 4:
		print li[-1]**2
	else:
		print li[-1]*li[-2]
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ((h[i]-val*b-1)/(a-b))+1
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**9
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Fixed submission:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ((h[i]-val*b-1)/(a-b))+1
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**9
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ceil((h[i]-val*b)/float(a-b))
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,max(h)+10
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Fixed submission:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ((h[i]-val*b-1)/(a-b))+1
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**9
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ceil((h[i]-val*b)/float(a-b))
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**12
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Fixed submission:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ((h[i]-val*b-1)/(a-b))+1
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**9
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo
Buggy python submission (verdict: Time Limit Exceeded):
import math

print (int(math.factorial(input())))%(10**9+7)

Fixed submission:
def factorialMod(n, modulus):
    ans=1
    if n <= modulus//2:
        #calculate the factorial normally (right argument of range() is exclusive)
        for i in range(1,n+1):
            ans = (ans * i) % modulus
    else:
        #Fancypants method for large n
        for i in range(n+1,modulus):
            ans = (ans * i) % modulus
        ans = modinv(ans, modulus)
        ans = -1*ans + modulus
    return ans % modulus


print factorialMod(input(),10**9+7)
Buggy python submission (verdict: Runtime Error):
a = ['2','3','4','5','6','7','8','9','10','11','12','13']
al,bo = map(str,raw_input().split())
if a.index(al) > a.index(bo):
    print 'Alice'
elif a.index(al) < a.index(bo):
    print 'Bob'
else:
    print 'Draw'


Fixed submission:
a = ['2','3','4','5','6','7','8','9','10','11','12','13','1']
al,bo = map(str,raw_input().split())
if a.index(al) > a.index(bo):
    print 'Alice'
elif a.index(al) < a.index(bo):
    print 'Bob'
else:
    print 'Draw'
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = input()
a = [int(x) for x in raw_input().split()]
a.sort()
c = 0
if n&1:
    if a[0] == 0:
        del a[0]
        d = Counter(a)
        for i in d.keys():
            if i == 0:
                print 0
                exit(1)
            if i&1:
                print 0
                exit(1)
            if not(i&1):
                if d[i] == 2:
                    c += 1
                if d[i] != 2:
                    print 0
                    exit(1)
    if c == (n-1)//2:
        print (1 << c)%(10**9+7)
if not(n&1):
    d = Counter(a)
    for i in d.keys():
        if i&1:
            if d[i] == 2:
                c +=1
            if d[i] != 2:
                print 0
                exit(1)
        if not(i&1):
            print 0
            exit(1)
    if c == n//2:
        print (1 << c)%(10**9+7)



Fixed submission:
import sys
from collections import Counter
n = input()
a = [int(x) for x in raw_input().split()]
a.sort()
if n == 1:
    if a[0] == 0:
        print 1
        sys.exit()
c = 0
if n&1:
    if a[0] == 0:
        del a[0]
        d = Counter(a)
        for i in d.keys():
            if i == 0:
                print 0
                sys.exit()
            if i&1:
                print 0
                sys.exit()
            if not(i&1):
                if d[i] == 2:
                    c += 1
                if d[i] != 2:
                    print 0
                    sys.exit()
    if c == (n-1)//2:
        print (1 << c)%(10**9+7)
if not(n&1):
    d = Counter(a)
    for i in d.keys():
        if i&1:
            if d[i] == 2:
                c +=1
            if d[i] != 2:
                print 0
                sys.exit()
        if not(i&1):
            print 0
            sys.exit()
    if c == n//2:
        print (1 << c)%(10**9+7)
Buggy python submission (verdict: Time Limit Exceeded):
n,x = map(int,input().split())
a = [int(x) for x in input().split()]
c =0
for i in range(n-1):
    if a[i]+a[i+1] <= x:
        continue
    else:
        while(a[i+1] != 0 and x!= a[i]+a[i+1]):
            a[i+1] = a[i+1]-1
            c += 1
    if a[i]+a[i+1] > x:
        while (a[i] != 0 and x != a[i] + a[i + 1]):
            a[i] = a[i] - 1
            c += 1
print(c)

Fixed submission:
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
su = arr[0]
ans = 0
for i in range(1,n):
    su += arr[i]
    if su > x:
        diff = min(arr[i],su-x)
        arr[i] -= diff
        su = arr[i-1]+arr[i]
        if su > x:
            diff1 = min(arr[i-1],su-x)
            arr[i-1] -= diff1
            su = arr[i-1]+arr[i]
            ans += diff1
        ans += diff
    su = arr[i]
print ans
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())

if k%2 ==1:
  print(int(n//k)**3)
else:
  print(int((n//k)**3 + ((n+(k/2))//k)**3))


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

if k%2 ==1:
  print(int(n//k)**3)
else:
  print(int((n//k)**3 + ((n+(k/2))//k)**3))
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = []
seen = [[False for y in range(w)] for x in range(h)]

for x in range(h):
    grid.append(input())



blackSeen = 0
whiteSeen = 0
def countFrom(a, b, lastColor):
    global blackSeen, whiteSeen
    if not (0 <= a < h and 0 <= b < w):
        return
    if seen[a][b]:
        return
    #print(a, b)
    

    thisColor = (1 if grid[a][b] == "." else -1)

    if grid[a][b] == "#" and lastColor != -1:
        blackSeen += 1
    elif grid[a][b] == "." and lastColor != 1:
        whiteSeen += 1
    else:
        return
    seen[a][b] = True

    countFrom(a+1, b, thisColor)
    countFrom(a-1, b, thisColor)
    countFrom(a, b+1, thisColor)
    countFrom(a, b-1, thisColor)

tot = 0
for x in range(h):
    for y in range(w):
        blackSeen = 0
        whiteSeen = 0
        countFrom(x, y, 0)
        #print(x, y, blackSeen, whiteSeen)
        tot += blackSeen * whiteSeen

print(tot)

    

Fixed submission:
import sys
sys.setrecursionlimit(500*500)

h, w = map(int, input().split())
grid = []
seen = [[False for y in range(w)] for x in range(h)]

for x in range(h):
    grid.append(input())



blackSeen = 0
whiteSeen = 0
def countFrom(a, b, lastColor):
    global blackSeen, whiteSeen
    if not (0 <= a < h and 0 <= b < w):
        return
    if seen[a][b]:
        return
    #print(a, b)
    

    thisColor = (1 if grid[a][b] == "." else -1)

    if grid[a][b] == "#" and lastColor != -1:
        blackSeen += 1
    elif grid[a][b] == "." and lastColor != 1:
        whiteSeen += 1
    else:
        return
    seen[a][b] = True

    countFrom(a+1, b, thisColor)
    countFrom(a-1, b, thisColor)
    countFrom(a, b+1, thisColor)
    countFrom(a, b-1, thisColor)

tot = 0
for x in range(h):
    for y in range(w):
        blackSeen = 0
        whiteSeen = 0
        countFrom(x, y, 0)
        #print(x, y, blackSeen, whiteSeen)
        tot += blackSeen * whiteSeen

print(tot)
Buggy python submission (verdict: Runtime Error):
import sympy
def piyo():
    n = int(input())
    if (n-7)%4==0 or (n-14)%4==0 or (n-21)%4==0 or n%4==0:
        print("Yes")
        return
    print("No")
        
if __name__ == '__main__':
    piyo()

Fixed submission:
def piyo():
    n = int(input())
    if n>=24:
        if ((n-7)%4==0 or (n-14)%4==0 or (n-21)%4==0 or n%4==0
        or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or (n-24)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=21:
        if ((n-7)%4==0 or (n-14)%4==0 or (n-21)%4==0 or n%4==0
        or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=20:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or (n-20)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=16:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or (n-16)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=14:
        if ((n-7)%4==0 or (n-14)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=12:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or (n-12)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=8:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or (n-8)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=7:
        if ((n-7)%4==0 or n%4==0 or (n-4)%7==0 or n%7==0):
            print("Yes")
            return
    if n>=4:
        if (n%4==0 or (n-4)%7==0 or n%7==0):
            print("Yes")
            return
    print("No")
        
if __name__ == '__main__':
    piyo()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def piyo():
    _ = int(input())
    b = np.array(list(int(i) for i in input().split()),dtype=int)
    fuga = []
    piyopiyo = []
    for hoge in range(10 ** 5):
        for hogehoge in b:
            piyopiyo.append((hoge+1)%hogehoge)
        fuga.append(np.sum(piyopiyo))
        piyopiyo.clear()
    print(max(fuga))
        
if __name__ == '__main__':
    piyo()

Fixed submission:
import numpy as np
def piyo():
    a = int(input())
    b = np.array(list(int(i) for i in input().split()),dtype=int)
    print(np.sum(b)-a)

if __name__ == '__main__':
    piyo()
Buggy python submission (verdict: Runtime Error):
import sys

targetPrice = int(input())
cakePrice = 4
donutPrice = 7
maxDonutCount = int(targetPrice / 7)

for i in range(maxDonutCount + 1):
    targetCakePrice = targetPrice - (donutPrice * i)
    if targetCakePrice % cakePrice == 0:
        print("Yes")
        sys.exit()
print("No")


Fixed submission:
numSenbei, numPeople = [int(i) for i in str(input()).split()]

if numSenbei % numPeople == 0:
    print(0)
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
(numSenbei, numPeople) = input().split()

if numSenbei % numPeople == 0:
    print(1)
else:
    print(0)


Fixed submission:
numSenbei, numPeople = [int(i) for i in str(input()).split()]

if numSenbei % numPeople == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
import math
import sys

N = int(input())
max = math.ceil(math.log(abs(N), 2)) + 3

result = []
numerator = N
for i in range(0, max):
    if numerator % (math.pow(2, i + 1)) == 0:
        result.append(str(0))
    else:
        result.append(str(1))
        numerator -= math.pow(-2, i)

    if numerator == 0:
        break
result.reverse()
print("".join(result))

Fixed submission:
import math
import sys

N = int(input())
if N == 0:
    max = 1
else:
    max = math.ceil(math.log(abs(N), 2)) + 3

result = []
numerator = N
for i in range(0, max):
    if numerator % (math.pow(2, i + 1)) == 0:
        result.append(str(0))
    else:
        result.append(str(1))
        numerator -= math.pow(-2, i)

    if numerator == 0:
        break
result.reverse()
print("".join(result))
Buggy python submission (verdict: Time Limit Exceeded):
numBox, numnClild = [int(i) for i in input().split()]
numCandies = [int(i) for i in input().split()]

def find(left):
    acc = 0
    for i in range(left, numBox):
        acc += numCandies[i]
        if acc % numnClild == 0:
            return i + 1
    return -1

done_list = []
count = 0
for left in range(0, numBox):
    tmp_count = 0
    right = left
    while right != -1:
        right = find(right)
        if right != -1:
            if right in done_list:
                break
            else:
                done_list.append(right)
                tmp_count += 1
    count += int(tmp_count * (tmp_count + 1) / 2)
print(count)

Fixed submission:
numBox, numClild = [int(i) for i in input().split()]
numCandies = [int(i) for i in input().split()]

subsequences = {}
acc = 0
for i in range(0, numBox):
    acc += numCandies[i]
    if (acc % numClild) in subsequences:
        subsequences[acc % numClild].append(i)
    else:
        subsequences[acc % numClild] = [i]

count = 0
for k, v in subsequences.items():
    count += int(len(v) * (len(v) - 1) / 2)
    if k == 0:
        count += len(v)
print(count)
Buggy python submission (verdict: Runtime Error):
def solve(n,l,dp):
    if n<=0:
        return 0
    elif n==1:
        return abs(l[n]-l[n-1])
    if dp[n]!=-1:
        return dp[n]
    dp[n]= min(abs(l[n]-l[n-1])+solve(n-1,l,dp),abs(l[n]-l[n-2])+solve(n-2,l,dp))
    return dp[n]
n=int(input())
l=[int(x) for x in input().split()]
if n==1:
    print(0)
else:
    dp=[-1]*(n+1)
    ans=solve(n-1,l,dp)
    print(ans)

Fixed submission:
n=int(input())
l=[int(x) for x in input().split()]
dp=[0]*n
for i in range(n):
    if i==0:
        dp[i]=0
    elif i==1:
        dp[i]=abs(l[i]-l[i-1])
    else:
	    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
def solve(n,l,dp):
    if n<=0:
        return 0
    elif n==1:
        return abs(l[n]-l[n-1])
    if n in dp:
        return dp[n]
    dp[n]= min(abs(l[n]-l[n-1])+solve(n-1,l,dp),abs(l[n]-l[n-2])+solve(n-2,l,dp))
    return dp[n]
n=int(input())
l=[int(x) for x in input().split()]
if n==1:
    print(0)
else:
    ans=solve(n-1,l,{})
    print(ans)

Fixed submission:
n=int(input())
l=[int(x) for x in input().split()]
dp=[0]*n
for i in range(n):
    if i==0:
        dp[i]=0
    elif i==1:
        dp[i]=abs(l[i]-l[i-1])
    else:
	    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
def solve(n,l,dp):
    if n==0:
        return l[0]
    elif n==1:
        return abs(l[n-1]-l[n-2])
    if n in dp:
        return dp[n]
    dp[n]= min((abs(l[n-1]-l[n-2])+solve(n-1,l,dp)),abs(l[n-1]-l[n-3])+solve(n-2,l,dp))
    return dp[n]
n=int(input())
l=[int(x) for x in input().split()]
if n==1:
    print(0)
else:
    ans=solve(n,l,{})
    print(ans)

Fixed submission:
n=int(input())
l=[int(x) for x in input().split()]
dp=[0]*n
for i in range(n):
    if i==0:
        dp[i]=0
    elif i==1:
        dp[i]=abs(l[i]-l[i-1])
    else:
	    dp[i]=min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0]*n
dp[0]=0
for i in range(1,n):
    m=10**20
    if i-k<=0:
        for j in range(i):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    else:
        for j in range(i-1,i-k-1,-1):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    dp[i]=m
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
l=[int(x) for x in input().split()]
dp=[0]*n
dp[0]=0
for i in range(1,n):
    m=10**20
    if i-k<=0:
        for j in range(i):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    else:
        for j in range(i-1,i-k-1,-1):
            t=dp[j]+abs(l[i]-l[j])
            m=min(t,m)
    dp[i]=m
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
arr = list(map(int, input().strip().split()))

mem = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    mem[i][i] = arr[i]

for diff in range(1, n):
    for L in range(n-diff):
        H = L+diff
        mem[L][H] = max(arr[L]-mem[L+1][H], arr[H]-mem[L][H-1])

print(mem[0][n-1])

Fixed submission:
n = int(input())
arr = list(map(int, input().strip().split()))

mem = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    mem[i][i] = arr[i]

for diff in range(1, n):
    for L in range(n-diff):
        H = L+diff
        mem[L][H] = max(arr[L]-mem[L+1][H], arr[H]-mem[L][H-1])

print(mem[0][n-1])

Buggy python submission (verdict: Runtime Error):
dp = {}

def getAns(arr, L, H):
    # print(arr)
    if (L, H) in dp:
        return dp[(L, H)]
    if L == H:
        return arr[L]
    else:
        res =  max(
            arr[L]-getAns(arr, L+1, H), 
            arr[H]-getAns(arr, L, H-1)
            )
        
        dp[(L, H)] = res
        
        return res

n = int(input())
arr = list(map(int, input().strip().split()))
print(getAns(arr, 0, n-1))

Fixed submission:
n = int(input())
arr = list(map(int, input().strip().split()))

mem = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    mem[i][i] = arr[i]

for diff in range(1, n):
    for L in range(n-diff):
        H = L+diff
        mem[L][H] = max(arr[L]-mem[L+1][H], arr[H]-mem[L][H-1])

print(mem[0][n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        

print((dp[-1][-1]-dp[-2][-1])%1000000007)

Fixed submission:
mod = 1000000007
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        
        dp[i][j] %= mod


print((dp[-1][-1]-dp[-2][-1] + mod)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

inf = 10**10
dp = [0] + [inf] * (n-1)

for i in range(1,n):
    j = 1
    while j <= k and j <= i:
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        j += 1
    
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))

inf = 10**10
dp = [0] + [inf] * (n-1)

for i in range(1,n):
    j = 1
    while j <= k and j <= i:
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        j += 1
    
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] + [float("inf")] * (n-1)
dp[1] = abs(h[0]-h[1])

for i in range(2,n):
    j = 1
    while j <= k and j <= i:
        cost = dp[i-j]+abs(h[i]-h[i-j])
        if cost < dp[i]:
            dp[i] = cost
        j += 1
    
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))

inf = 10**10
dp = [0] + [inf] * (n-1)

for i in range(1,n):
    j = 1
    while j <= k and j <= i:
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        j += 1
    
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
h = list(map(int, input().split()))
INF = 999999999999999999999999999
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
    
print(dp[n-1])
        

Fixed submission:
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
for i in range(1, n):
    if i - 2 < 0:
        dp[i] = dp[i-1] + abs(h[i] - h[i-1])
    else: 
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))
INF = 999999999999999999999999999
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
    
print(dp[n-1])
        

Fixed submission:
n,k = map(int, input().split())
h = list(map(int, input().split()))
INF = 999999999999999999999999999
dp = [INF] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + 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()))
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
	for j in range(1,k+1):
		
		if(i-j<0):
			break
		else:
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf') for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
	for j in range(1,k+1):
		
		if(i-j<0):
			break
		else:
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[0 for i in range(w+1)]
dp1=dp.copy()
for i in range(1,n+1):

	
    
	a,b=map(int,input().split())
	
	for j in range(1,w+1):
		dp1[j]=dp[j]
		if(a<=j):
			dp1[j]=max(dp1[j],dp[j-a]+b)
	
	dp=dp1.copy()
print(dp[w])





Fixed submission:
n,w=map(int,input().split())
dp=[[0 for i in range(w+1)] for j in range(n+1)]
for i in range(w):
	dp[0][i]=0
for i in range(n):
	dp[i][0]=0
l=[]
for k in range(n):
	l.append(list(map(int,input().split())))

for i in range(1,n+1):
	for j in range(1,w+1):
		dp[i][j]=dp[i-1][j]
		if(l[i-1][0]<=j):
			dp[i][j]=max(dp[i-1][j-l[i-1][0]]+l[i-1][1],dp[i][j])
print(dp[n][w])