Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n = int(input())

    count = {}
    for _ in range(n):
        name = input()
        if name not in count.keys():
            count[name] = 1

        else:
            count[name] += 1

    max_polls = max(count.values())

    names = []
    for k, v in count.items():
        if v == max_polls:
            names.append(k)

    names.sort()
    for name in names:
        print(name)
        
resolve()

Fixed submission:
from collections import OrderedDict
import sys
input = sys.stdin.readline

def resolve():
    n = int(input())

    count = OrderedDict()
    for _ in range(n):
        name = input()
        if name not in count.keys():
            count[name] = 1

        else:
            count[name] += 1

    count = OrderedDict(
        sorted(count.items(), key=lambda x: x[0])
    )
    max_polls = max(count.values())

    for k, v in count.items():
        if v == max_polls:
            print(k)
            
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import OrderedDict
def resolve():
    n = int(input())

    l = []
    for _ in range(n):
        l.append(input())

    count = OrderedDict()

    for name in l:
        if name not in count.keys():
            count[name] = 1

        else:
            count[name] += 1

    count = OrderedDict(
        sorted(count.items(), key=lambda x: x[0])
    )
    max_polls = max(count.values())

    for k, v in count.items():
        if v == max_polls:
            print(k)
            
resolve()

Fixed submission:
from collections import OrderedDict
import sys
input = sys.stdin.readline

def resolve():
    n = int(input())

    count = OrderedDict()
    for _ in range(n):
        name = input()
        if name not in count.keys():
            count[name] = 1

        else:
            count[name] += 1

    count = OrderedDict(
        sorted(count.items(), key=lambda x: x[0])
    )
    max_polls = max(count.values())

    for k, v in count.items():
        if v == max_polls:
            print(k)
            
resolve()
Buggy python submission (verdict: Runtime Error):
s, t = map(int, input().split())
a, b = map(int, input().split())
u = input()

if u == s:
  print(a-1, b)

if u == t:
  print(a, b-1)

Fixed submission:
def resolve():
    s, t = input().split()
    a, b = map(int, input().split())
    u = input()

    if u == s:
        print(a - 1, b)

    if u == t:
        print(a, b - 1)

resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n, m = map(int, input().split())

    penalties = 0
    wa_counts = [0] * n
    ac_flags = [0] * n

    for _ in range(m):
        line = input().split()
        q = int(line[0])
        r = line[1]

        if ac_flags[q-1] == 0:
            if r == 'WA':
                wa_counts[q-1] += 1

            else:
                ac_flags[q-1] = 1
                penalties += wa_counts[q-1]

    print(sum(ac_flags), penalties)

resolve()

Fixed submission:
def resolve():
    a = input()

    print(chr(ord(a) + 1))
    
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n, m = map(int, input().split())

    ac_list = []
    penalties = 0
    wa_counts = [0] * n

    for _ in range(m):
        line = input().split()
        q = int(line[0])
        r = line[1]

        if q not in ac_list:
            if r == 'WA':
                wa_counts[q-1] += 1

            else:
                ac_list.append(q)
                penalties += wa_counts[q-1]

    print(len(ac_list), penalties)

resolve()


Fixed submission:
def resolve():
    n, m = map(int, input().split())

    penalties = 0
    wa_counts = [0] * n
    ac_flags = [0] * n

    for _ in range(m):
        line = input().split()
        q = int(line[0])
        r = line[1]

        if ac_flags[q-1] == 0:
            if r == 'WA':
                wa_counts[q-1] += 1

            else:
                ac_flags[q-1] = 1
                penalties += wa_counts[q-1]

    print(sum(ac_flags), penalties)
    
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    n, m = map(int, input().split())

    ac_list = []
    penalties = 0
    wa_counts = [0] * n

    for _ in range(m):
        line = input().split()
        q = int(line[0])
        r = line[1]

        if q not in ac_list:
            if r == 'WA':
                wa_counts[q-1] += 1

            else:
                ac_list.append(q)
                penalties += wa_counts[q-1]

    print(len(ac_list), penalties)

resolve()

Fixed submission:
def resolve():
    n, m = map(int, input().split())

    penalties = 0
    wa_counts = [0] * n
    ac_flags = [0] * n

    for _ in range(m):
        line = input().split()
        q = int(line[0])
        r = line[1]

        if ac_flags[q-1] == 0:
            if r == 'WA':
                wa_counts[q-1] += 1

            else:
                ac_flags[q-1] = 1
                penalties += wa_counts[q-1]

    print(sum(ac_flags), penalties)
    
resolve()
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

print(set([1,2,3]) - a - b)

Fixed submission:
a = int(input())
b = int(input())

l = [1,2,3]
l.remove(a)
l.remove(b)

print(l[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
  ai = a[i]
  pre_ai = 0
  if i != 0:
    pre_ai = a[i-1]
    
  ans += b[ai]
  if ai - pre_ai = 1:
    ans += c[pre_ai]
    
print (ans)
  

Fixed submission:
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
  ai = a[i] -1
  pre_ai = -10
  if i != 0:
    pre_ai = a[i-1] -1
    
  ans += b[ai]
  if ai - pre_ai == 1:
    ans += c[pre_ai]
    
print (ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))

b.append(100010)
a = []
a.append(b[0])

for i in range(1,n):
  a.append(min(b[i], b[i-1])
           
print(sum(a))

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

b.append(100010)
a = 0
a += b[0]

for i in range(1,n):
  a += (min(b[i], b[i-1]))
           
print(a)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

ans = 0
for i in range(3)
  
  a = s[i]
  b = t[i]
  
  if a == b:
    ans += 1
    
print(ans)

Fixed submission:
s = input()
t = input()

ans = 0
for i in range(3):
  
  a = s[i]
  b = t[i]
  
  if a == b:
    ans += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():

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

    for i in range(2 ** n):

        new_h = []

        for j in range(n):

            if i >> j & 1:
                new_h.append(h[j] - 1)
            else:
                new_h.append(h[j])

        flg = 0
        for k in range(n-1):
            if new_h[k] > new_h[k+1]:
                flg = 1

        if flg == 0:
            print('Yes')
            return

    print('No')
    
resolve()

Fixed submission:
def resolve():

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

    for i in range(n):

        if i == 0:
            h[i] -= 1
            continue

        if h[i-1] < h[i]:
            h[i] -= 1

        if h[i-1] > h[i]:
            print('No')
            return

    print('Yes')
    
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    dataset = set(map(int, input().split()))
    
    xor = 0

    for i in range(n):
        xor ^= dataset[n]
    
    if xor == 0:
        print('Yes')
    else:
        print('No')

resolve()

Fixed submission:
def resolve():
    n = int(input())
    dataset = list(map(int, input().split()))

    xor = 0

    for i in range(n):
        xor ^= dataset[i]

    if xor == 0:
        print('Yes')
    else:
        print('No')
        
resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():

    n = int(input())
    dataset = set(map(int, input().split()))

    li_dataset = list(dataset)
    xor = li_dataset[0] ^ li_dataset[1]

    flag = 0
    if xor in dataset:
        flag = 1

    if len(dataset) <= 3 and n % 3 == 0 and flag:
        print('Yes')

    else:
        print('No')
        
resolve()

Fixed submission:
def resolve():
    n = int(input())
    dataset = list(map(int, input().split()))

    xor = 0

    for i in range(n):
        xor ^= dataset[i]

    if xor == 0:
        print('Yes')
    else:
        print('No')
        
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    heights = list(map(int, input().split()))
    dp = [-1] * n
    dp[0] = 0

    print(jump(n - 1, heights, dp))

# i番目の足場にたどり着いたときの、コストの最小値を返す関数
def jump(i, heights, dp):
    # 足場 0 のコスト
    if i == 0:
        return 0

    if dp[i] != -1:
        return dp[i]

    res = jump(i - 1, heights, dp) + abs(heights[i] - heights[i - 1])
    if i > 1:
        res = min(res, jump(i - 2, heights, dp) + abs(heights[i] - heights[i - 2]))
    dp[i] = res
    return res
  
resolve()

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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[i], dp[i-1] + abs(li[i] - li[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(li[i] - li[i-2]))

print(dp[n - 1])

Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    heights = list(map(int, input().split()))
    dp = [-1] * n
    dp[0] = 0

    print(jump(n - 1, heights, dp))

# i番目の足場にたどり着いたときの、コストの最小値を返す関数
def jump(i, heights, dp):
    # 足場 0 のコスト
    if i <= 0:
        return 0

    else:
        if dp[i] != -1:
            return dp[i]
        res = jump(i - 1, heights, dp) + abs(heights[i] - heights[i - 1])
        
        if i > 1:
            res = min(res, jump(i - 2, heights, dp) + abs(heights[i] - heights[i - 2]))
        dp[i] = res
        
        return res

resolve()

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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[i], dp[i-1] + abs(li[i] - li[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(li[i] - li[i-2]))

print(dp[n - 1])

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())

data = np.zeros((n, 3), dtype=np.int64)

for i in range(n):

  data[i] = list(map(int, input().split()))

dp = np.zeros((n+1, 3), dtype=np.int64)

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i+1][j] = np.maximum(dp[i][k] + data[i][j], dp[i+1][j])

print(np.max(dp[n]))


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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):

  dp[i] = min(dp[i], dp[i-1] + abs(li[i] - li[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(li[i] - li[i-2]))

print(dp[n - 1])
Buggy python submission (verdict: Runtime Error):
import numpy as np

def resolve():
    n = int(input())
    h = np.array(list(map(int, input().split())))
    k = 2

    dp = np.zeros(n, dtype=int)

    for i in range(1, n):
        start = max(0, i - k)
        dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))

    print(dp[n - 1])
    
resolve()

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

dp = [float('inf')] * n

dp[0] = 0

for i in range(n):
  for j in range(1, k + 1):
    if i + j < n:
      dp[i + j] = min(dp[i + j], dp[i] + abs(li[i] - li[i + j]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())

data = np.zeros((n, 3), dtype=np.int64)

for i in range(n):

  data[i] = list(map(int, input().split()))

dp = np.zeros((n+1, 3), dtype=np.int64)

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i+1][j] = np.maximum(dp[i][k] + data[i][j], dp[i+1][j])

print(np.max(dp[n]))


Fixed submission:
n = int(input())
li = []

for _ in range(n):
  li.append(list(map(int, input().split())))

dp = [[0] * 3 for _ in range(100010)]

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + li[i][k])

print(max(dp[n]))

Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())

data = np.zeros((n, 3), dtype=np.int64)

for i in range(n):

  data[i] = list(map(int, input().split()))

dp = np.zeros((n+1, 3), dtype=np.int64)

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i+1][j] = np.maximum(dp[i][k] + data[i][j], dp[i+1][j])

print(np.max(dp[n]))


Fixed submission:
n = int(input())
li = []

for _ in range(n):
  li.append(list(map(int, input().split())))

dp = [[0] * 3 for _ in range(100010)]

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + li[i][k])

print(max(dp[n]))

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

data = np.zeros((n, 3), dtype=np.int64)

for i in range(n):

  data[i] = list(map(int, input().split()))

dp = np.zeros((n+1, 3), dtype=np.int64)

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i+1][j] = np.maximum(dp[i][k] + data[i][j], dp[i+1][j])

print(np.max(dp[n]))

Fixed submission:
n = int(input())
li = []

for _ in range(n):
  li.append(list(map(int, input().split())))

dp = [[0] * 3 for _ in range(100010)]

for i in range(n):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + li[i][k])

print(max(dp[n]))
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    t = input()

    dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

    for i in range(len(s)):
        for j in range(len(t)):
            match = s[i] == t[j]
            dp[i + 1][j + 1] = max(dp[i][j] + match , dp[i + 1][j + 1])
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i + 1][j + 1])
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1])

    res = ''
    i = len(s)
    j = len(t)

    while i > 0 and j > 0:
        if dp[i][j] == dp[i - 1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j - 1]:
            j -= 1
        elif dp[i][j] == dp[i - 1][j - 1] + 1:
            res = s[i - 1] + res
            i -= 1
            j -= 1

    print(res)
    
resolve()

Fixed submission:
def resolve():
    s = input()
    t = input()

    dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

    for i in range(len(s)):
        for j in range(len(t)):
            match = s[i] == t[j]
            dp[i + 1][j + 1] = max(dp[i][j] + match , dp[i + 1][j + 1])
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i + 1][j + 1])
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1])

    res = ''
    i = len(s)
    j = len(t)

    while i > 0 and j > 0:
        if dp[i][j] == dp[i - 1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j - 1]:
            j -= 1
        elif dp[i][j] == dp[i - 1][j - 1] + 1:
            res = s[i - 1] + res
            i -= 1
            j -= 1

    print(res)
resolve()
Buggy python submission (verdict: Runtime Error):
n = int(inout())
if n < 1200:
  print('ABC')
elif n < 2800:
  print('ARC')
else:
  print('AGC')

Fixed submission:
n = int(input())
if n < 1200:
  print('ABC')
elif n < 2800:
  print('ARC')
else:
  print('AGC')

Buggy python submission (verdict: Runtime Error):
def resolve():

    d, g = map(int, input().split())

    p = [0] * d
    c = [0] * d

    for i in range(d):
        p[i], c[i] = map(int, input().split())

    ans = 1010

    for i in range(d ** 2):

        sum = 0
        cnt = 0

        for j in range(d):

            if (i >> j) & 1:

                sum += (j + 1) * 100 * p[j]
                sum += c[j]

                cnt += p[j]

        if sum < g:

            for k in range(d)[::-1]:

                flag = 0

                if not (i >> k) & 1:

                    for _ in range(p[k] -1):

                        if sum >= g:
                            flag = 1
                            break

                        sum += (k+1) * 100
                        cnt += 1

                if flag:
                    break

        if sum >= g:
            ans = min(cnt, ans)

    print(ans)
    
resolve()

Fixed submission:
n = int(input())
if n < 1200:
  print('ABC')
elif n < 2800:
  print('ARC')
else:
  print('AGC')
Buggy python submission (verdict: Runtime Error):
import heapq
from itertools import product
def resolve():
    n, m = map(int, input().split())
    cakes = [list(map(int, input().split())) for _ in range(n)]

    ans = 0

    for i in product([1, -1], repeat=3):
        hq = []
        heapq.heapify(hq)
        for x, y, z in cakes:
            point = i[0] * x + i[1] * y + i[2] * z
            if len(hq) != m:
                heapq.heappush(hq, point)
            elif hq[0] < point:
                heapq.heapreplace(hq, point)

        ans = max(ans, sum(hq))

    print(ans)
    
resolve()

Fixed submission:
import heapq
from itertools import product
def resolve():
    n, m = map(int, input().split())
    cakes = [list(map(int, input().split())) for _ in range(n)]

    ans = 0

    if m == 0:
        print(0)
        return 

    for i in product([1, -1], repeat=3):
        hq = []
        heapq.heapify(hq)
        for x, y, z in cakes:
            point = i[0] * x + i[1] * y + i[2] * z
            if len(hq) != m:
                heapq.heappush(hq, point)
            elif hq[0] < point:
                heapq.heapreplace(hq, point)

        ans = max(ans, sum(hq))

    print(ans)
    
resolve()

Buggy python submission (verdict: Runtime Error):
import heapq
from itertools import product
def resolve():
    n, m = map(int, input().split())
    cakes = [list(map(int, input().split())) for _ in range(n)]

    ans = 0

    for i in product([1, -1], repeat=3):
        hq = []
        heapq.heapify(hq)
        for x, y, z in cakes:
            point = i[0] * x + i[1] * y + i[2] * z
            if len(hq) != m:
                heapq.heappush(hq, point)
            elif hq[0] < point:
                heapq.heapreplace(hq, point)

        ans = max(ans, sum(hq))

    print(ans)
    
resolve()

Fixed submission:
import heapq
from itertools import product
def resolve():
    n, m = map(int, input().split())
    cakes = [list(map(int, input().split())) for _ in range(n)]

    ans = 0

    if m == 0:
        print(0)
        return 

    for i in product([1, -1], repeat=3):
        hq = []
        heapq.heapify(hq)
        for x, y, z in cakes:
            point = i[0] * x + i[1] * y + i[2] * z
            if len(hq) != m:
                heapq.heappush(hq, point)
            elif hq[0] < point:
                heapq.heapreplace(hq, point)

        ans = max(ans, sum(hq))

    print(ans)
    
resolve()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
from math import factorial


n = int(input())
a = list(map(int, input().split()))

s = [0]
s_elem = 0

for ai in a:
  
  s_elem += ai
  s.append(s_elem)

ans = 0
for c in Counter(s).values():
  if c > 1:
    ans += i*(i-1)//2
    
print(ans)

Fixed submission:
from collections import Counter
from math import factorial


n = int(input())
a = list(map(int, input().split()))

s = [0]
s_elem = 0

for ai in a:
  
  s_elem += ai
  s.append(s_elem)

ans = 0
for c in Counter(s).values():
  ans += c*(c-1)//2
    
print(ans)

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


n = int(input())
a = list(map(int, input().split()))

s = [0]
s_elem = 0

for ai in a:
  
  s_elem += ai
  s.append(s_elem)

ans = 0
for c in Counter(s).values():
  if c > 1:
    com = factorial(c) / factorial(2) / factorial(c-2)
    ans += int(com)

print(ans)

Fixed submission:
from collections import Counter
from math import factorial


n = int(input())
a = list(map(int, input().split()))

s = [0]
s_elem = 0

for ai in a:
  
  s_elem += ai
  s.append(s_elem)

ans = 0
for c in Counter(s).values():
  ans += c*(c-1)//2
    
print(ans)
Buggy python submission (verdict: Runtime Error):
_ = input()
num_list = list(map(int, input().split()))

res = 0

for num in range(num_list):
  count = 0
  
  while(num % 2  == 0):
    num /= 2
    count += 1
  
  if count > res:
    res = count
    
print(res)

Fixed submission:
_ = input()
num_list = list(map(int, input().split()))

res = 1000000

for num in num_list:
  count = 0
  
  while(num % 2  == 0):
    num /= 2
    count += 1
  
  if count < res:
    res = count
    
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()
print(s[0] + len(s[:-2]) + s[-1])

Fixed submission:
s = input()
print(s[0] + str(len(s[:-2])) + s[-1])
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    for c in range(k + 1):
      if a + b + c == s:
        res += 1
        break
        
print(res)

Fixed submission:
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    z = s - a - b
    if z >= 0 and z <= k:
        res += 1
        
print(res)

Buggy python submission (verdict: Runtime Error):
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    for c in range(k + 1):
      if a + b + c == s:
        res += 1
        break:
        
print(res)

Fixed submission:
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    z = s - a - b
    if z >= 0 and z <= k:
        res += 1
        
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    for c in range(k + 1):
      if a + b + c == s:
        res += 1
        
print(res)

Fixed submission:
k, s = map(int, input().split())
res = 0
for a in range(k + 1):
  for b in range(k + 1):
    z = s - a - b
    if z >= 0 and z <= k:
        res += 1
        
print(res)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))e

dp = [1000000000] * N
dp[0] = 0

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

print(dp[N - 1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())), dtype='int')
dp = np.ones(N, dtype='int') * 1000000000
dp[0] = 0

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

print(dp[N - 1])

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

dp = [1000000000] * N
dp[0] = 0

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

print(dp[N - 1])

Fixed submission:
import numpy as np

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())), dtype='int')
dp = np.ones(N, dtype='int') * 1000000000
dp[0] = 0

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

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

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

print(dp[N - 1])


Fixed submission:
import numpy as np

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())), dtype='int')
dp = np.ones(N, dtype='int') * 1000000000
dp[0] = 0

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

print(dp[N - 1])