Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int, input().split())
f=[[1 for _ in range(m+2)] for _ in range(n+2)]

# 1:表，0:裏
# 裏返す:-1を加える

for i in range(1,n+1):
    for j in range(1,m+1):
        for k in range(i-1,i+2):
            for l in range(j-1,j+2):
                f[k][l]-=1
                if f[k][l]==-1:
                    f[k][l]=1

cnt=0
for i in range(1,n+1):
    for j in range(1,m+1):
        if f[i][j]==0:
            cnt+=1
print(cnt)


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

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
else:
    print((n-2)*(m-2))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())

if k==0:
    print(n**2)
    quit()

cnt=0
for a in range(k,n+1):
    b=list(range(k,n+1))
    cnt+=len(list(filter(lambda x: a%x>=k, b)))

print(cnt)


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

s = 0
for b in range(1, n+1):
    s += max(0, b-k)*(n//b) + max(0, n%b-k+1)

if k == 0:
    s = n*n
print(s)

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

if k==0:
    print(n**2)
    quit()

cnt=0
for a in range(k,n+1):
    for b in range(k,n+1):
        if a<k or b<k:
            continue
        if a%b >= k:
            cnt+=1

print(cnt)


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

s = 0
for b in range(1, n+1):
    s += max(0, b-k)*(n//b) + max(0, n%b-k+1)

if k == 0:
    s = n*n
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
s=list(filter(lambda _s: _s == "M" or _s == "A" or _s == "R" or _s == "C" or _s == "H", (input()[0] for _ in range(n))))

if len(s) < 3:
    print(0)
    quit()

print(len(list(filter(lambda x: len(set(x))==3, itertools.combinations(s, 3)))))


Fixed submission:
import itertools
n = int(input())
s = [input()[0] for _ in range(n)]
c = list(itertools.combinations(set(filter(lambda x: x in "MARCH", s)), 3))

ans = 0
for _c in c:
    ans += s.count(_c[0])*s.count(_c[1])*s.count(_c[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
s=list(map(lambda _s: _s[0], filter(lambda _s: _s[0] == "M" or _s[0] == "A" or _s[0] == "R" or _s[0] == "C" or _s[0] == "H", list(input() for _ in range(n)))))

if len(s) == 0:
    print(0)
    quit()

print(len(list(filter(lambda x: len(set(x))==3, itertools.combinations(s, 3)))))


Fixed submission:
import itertools
n = int(input())
s = [input()[0] for _ in range(n)]
c = list(itertools.combinations(set(filter(lambda x: x in "MARCH", s)), 3))

ans = 0
for _c in c:
    ans += s.count(_c[0])*s.count(_c[1])*s.count(_c[2])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n=int(input())
s=list(input() for _ in range(n))
s=list(map(lambda _s: _s[0], filter(lambda _s: _s[0] == "M" or _s[0] == "A" or _s[0] == "R" or _s[0] == "C" or _s[0] == "H", s)))

if len(s) == 0:
    print(0)
    quit()

print(len(list(filter(lambda x: len(x)==3, map(set, itertools.combinations(s, 3))))))


Fixed submission:
import itertools
n = int(input())
s = [input()[0] for _ in range(n)]
c = list(itertools.combinations(set(filter(lambda x: x in "MARCH", s)), 3))

ans = 0
for _c in c:
    ans += s.count(_c[0])*s.count(_c[1])*s.count(_c[2])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = 10**5
e = [True]*(n+1)
e[0] = False
e[1] = False
for i in range(2, int(n**0.5)+1):
    if not e[i]:
        continue
    for j in range(i*2, n+1, i):
        e[j] = False

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())

    ans = 0
    for i in range(l, r+1, 2):
        if e[i] and e[(i+1)//2]:
            ans += 1
    print(ans)


Fixed submission:
n = 10**5
e = [True]*(n+1)
e[0] = False
e[1] = False
for i in range(2, int(n**0.5)+1):
    if not e[i]:
        continue
    for j in range(i*2, n+1, i):
        e[j] = False

c = [0]*(n+2)
for i in range(3, n+1, 2):
    if e[i] and e[(i+1)//2]:
        c[i] += 1

for i in range(3, n+1):
    c[i] += c[i-1]

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(c[r]-c[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ans = 0
for _c in c:
    i = bisect.bisect_left(b, _c)
    for j in range(i):
        ans += bisect.bisect_left(a, b[j])

print(ans)


Fixed submission:
import bisect

n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ans = 0
for _b in b:
    aNum = bisect.bisect_left(a, _b)
    cNum = len(c) - bisect.bisect_right(c, _b)
    ans += aNum*cNum

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = []
for _ in range(n):
    a = int(input())
    if a in ans:
        ans.pop(ans.index(a))
    else:
        ans.append(a)
print(len(ans))


Fixed submission:
import collections
n = int(input())
a = [int(input()) for _ in range(n)]
c = collections.Counter(a)

print(len(list(filter(lambda x: x[1]%2 == 1, c.items()))))
Buggy python submission (verdict: Runtime Error):
s = sorted(set(input()))

ans = "None"
for i in range(26):
    a = chr(ord("a") + i)
    if s[i] != a:
        ans = a
        break
print(ans)


Fixed submission:
s = sorted(set(input()))

alphabet = [chr(ord("a") + i) for i in range(26)]
ans = "None"
for actual, expected in zip(s, alphabet):
    if actual != expected:
        ans = expected
        break

if ans == "None" and s[len(s)-1] != "z":
    ans = alphabet[len(s)]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s: int, n: int, w: int, cost: list) -> list:
    d = [float("inf")]*n
    used = [False]*n
    d[s] = 0

    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i

        if v == -1:
            break

        used[v] = True

        for j in range(n):
            d[j] = min(d[j], d[v]+cost[v][j])

    return d

n = int(input())
t = [[float("inf")]*(n) for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    t[a-1][b-1] = c
    t[b-1][a-1] = c

q, k = map(int, input().split())
k -= 1
d = dijkstra(k, n, n-1, t)

for _ in range(q):
    x, y = map(int, input().split())
    print(d[x-1]+d[y-1])



Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(v: int, p: int = -1, s: int = 0):
    dist[v] = s
    for i, j in t[v]:
        if i == p:
            continue
        dfs(i, v, s + j)

n = int(input())
t = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1;
    t[a].append((b, c))
    t[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dist = [0]*n

dfs(k)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s: int, n: int, w: int, cost: list) -> list:
    d = [float("inf")]*n
    used = [False]*n
    d[s] = 0

    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i

        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j], d[v]+cost[v][j])

    return d

n = int(input())
t = [[float("inf")]*(n) for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    t[a-1][b-1] = c
    t[b-1][a-1] = c

q, k = map(int, input().split())
k -= 1
d = dijkstra(k, n, n-1, t)

for _ in range(q):
    x, y = map(int, input().split())
    print(d[x-1]+d[y-1])


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def dfs(v: int, p: int = -1, s: int = 0):
    dist[v] = s
    for i, j in t[v]:
        if i == p:
            continue
        dfs(i, v, s + j)

n = int(input())
t = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    a -= 1; b -= 1;
    t[a].append((b, c))
    t[b].append((a, c))

q, k = map(int, input().split())
k -= 1

dist = [0]*n

dfs(k)

for _ in range(q):
    x, y = map(int, input().split())
    print(dist[x-1]+dist[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, k = map(int, input().split())
*l, = map(int, input().split())

ans = 0
for c in itertools.combinations(l, k):
    ans = max(ans, sum(c))

print(ans)


Fixed submission:
n, k = map(int, input().split())
l = sorted(map(int, input().split()), reverse=True)

print(sum(l[:k]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
*a, = map(int, input().split())

b = []
for i in range(n):
    b.append(a[i])
    b.reverse()

print(" ".join(map(str, b)))


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

b = list(reversed(a[1::2]))+a[0::2]
print(" ".join(map(str, b if n%2 == 0 else reversed(b))))
Buggy python submission (verdict: Runtime Error):
import itertools

n, m = map(int, input().split())
am = [[False]*m for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    am[a-1][b-1] = True
    am[b-1][a-1] = True

ans = 0
for p in itertools.permutations(list(range(n)), n):
    if p[0] != 0:
        continue

    isok = True
    for i in range(len(p)-1):
        if not am[p[i]][p[i+1]]:
            isok = False
            break

    if isok:
        ans += 1

print(ans)


Fixed submission:
n, m = map(int, input().split())
g = {}
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g.setdefault(a, [])
    g[a].append(b)
    g.setdefault(b, [])
    g[b].append(a)

isVisited = [False]*n
isVisited[0] = True

def dfs(v: int) -> int:
    if all(isVisited):
        return 1

    ret = 0

    for i in g[v]:
        if isVisited[i]:
            continue

        isVisited[i] = True
        ret += dfs(i)
        isVisited[i] = False

    return ret

print(dfs(0))
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <= k and x+y+z == s:
            ans += 1

print(ans)


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

ans = 0
for x in range(k+1):
    for y in range(k+1):
        if x+y > s:
            continue
        if 0 <= s-x-y <= k:
            ans += 1

print(ans)

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

ans = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if sum([i, j, k]) == s:
                ans += 1
print(ans)


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

ans = 0
for x in range(k+1):
    for y in range(k+1):
        if x+y > s:
            continue
        if 0 <= s-x-y <= k:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ans = [False]*100
ans[a] |= True
ans[b] |= True
ans[c] |= True

print(sum(ans))


Fixed submission:
print(len(set(map(int, input().split()))))
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
s=sorted([input() for i in range(n)])
print(*s,sep="")


Fixed submission:
a, b, c = map(int, input().split())
print("YES" if a == b == 5 and c == 7 or a == c == 5 and b == 7 or b == c == 5 and a == 7 else "NO")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A_line = map(int, input().split())

A_flags = [0] * pow(10, 8)

for A in A_line:
  A_flags[A-1] += 1

res = 'YES'
for A_flag in A_flags:
  if A_flag >= 2:
    res = 'NO'

print(res)

Fixed submission:
N = int(input())
A_line = list(map(int, input().split()))

A_line.sort()

res = "YES"
for i in range(len(A_line) - 1):
  if A_line[i] == A_line[i + 1]:
    res = "NO"

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

for i in range(len(p_list)):
  EV_p_list[i] = (p_list[i] + 1) / 2

max_EV = 0
for i in range(N - K + 1):
  tmp = 0
  for j in range(K):
    tmp += EV_p_list[i + j]
  
  if tmp >= max_EV:
    max_EV = tmp

print(max_EV)

Fixed submission:
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

for i in range(len(p_list)):
  EV_p_list[i] = (p_list[i] + 1) / 2

# 最初のsum
sum_EV = 0
for i in range(K):
  sum_EV = sum_EV + EV_p_list[i]

# それ以降の比較
max_EV = sum_EV
for i in range(1, N - K + 1):
  sum_EV = sum_EV - EV_p_list[i - 1] + EV_p_list[i + K - 1]
  if sum_EV > max_EV:
    max_EV = sum_EV

print(max_EV)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

EV_list = [0] * 1000

for i in range(len(EV_list)):
  EV_list[i] = (i + 2) / 2

for i in range(len(p_list)):
  index = p_list[i]
  EV_p_list[i] = EV_list[index - 1]

max_EV = 0
for i in range(N - K + 1):
  tmp = 0
  for j in range(K):
    tmp += EV_p_list[i + j]
  
  if tmp >= max_EV:
    max_EV = tmp

print(max_EV)

Fixed submission:
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
EV_p_list = [0] * len(p_list)

for i in range(len(p_list)):
  EV_p_list[i] = (p_list[i] + 1) / 2

# 最初のsum
sum_EV = 0
for i in range(K):
  sum_EV = sum_EV + EV_p_list[i]

# それ以降の比較
max_EV = sum_EV
for i in range(1, N - K + 1):
  sum_EV = sum_EV - EV_p_list[i - 1] + EV_p_list[i + K - 1]
  if sum_EV > max_EV:
    max_EV = sum_EV

print(max_EV)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

cnt = 0
flag = True

for i in range(N):
  flag = True
  P_i = P[i]
  for j in range(i + 1):
    if P_i > P[j]:
      flag = False
  if flag:
    cnt += 1

print(cnt)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))

cnt = 1
min = P[0]
flag = True

for i in range(1, N):
  if P[i] <= min:
    cnt += 1
    min = P[i]
    

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
sheet = [[0 for i in range(10)] for i in range(10)]
cnt = 0

for i in range(1, N + 1):
  str_i = str(i)
  if sheet[int(str_i[0])][int(str_i[-1])] == 0:
    for j in range(N + 1):
      str_j = str(j)
      if str_j[0] == str_i[-1] and str_j[-1] == str_i[0]:
        sheet[int(str_i[0])][int(str_i[-1])] += 1
    cnt += sheet[int(str_i[0])][int(str_i[-1])]

  else:
    cnt += sheet[int(str_i[0])][int(str_i[-1])]


print(cnt)

Fixed submission:
N = int(input())
sheet = [[0 for i in range(10)] for i in range(10)]
cnt = 0

for i in range(1, N + 1):
  str_i = str(i)
  sheet[int(str_i[0])][int(str_i[-1])] += 1

res = 0
for i in range(10):
  for j in range(10):
    res += sheet[i][j] * sheet[j][i]

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
robot_list = []
for i in range(N):
  robot_list.append(list(map(int, input().split())))

def choose_coordinate(now_edge):
  global robot_list
  global res
  next_edge = pow(10, 10)

  for i in range(N):
    robot_right_edge = robot_list[i][0] + robot_list[i][1]
    robot_left_edge = robot_list[i][0] - robot_list[i][1]
    if robot_left_edge >= now_edge and robot_right_edge <= next_edge:
      next_edge = robot_right_edge
    
  if next_edge == pow(10, 10):
    return
  else:
    res += 1
    choose_coordinate(next_edge)

res = 0
choose_coordinate(- pow(10,10))

print(res)

Fixed submission:
N = int(input())
robot_list = []
for i in range(N):
  X, L = map(int, input().split())
  left_edge = X - L
  right_edge = X + L
  robot_list.append([left_edge, right_edge])

robot_list.sort(key=lambda x: x[1])

res = 0
index = - pow(10, 10)
for i in range(N):
  if robot_list[i][0] >= index:
    index = robot_list[i][1]
    res += 1

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
'use strict'
import math
N, M = map(int, input().split())
goods_price_list = list(map(int, input().split()))

for i in range(M):
  max_index = goods_price_list.index(max(goods_price_list))
  goods_price_list[max_index] = math.floor(goods_price_list[max_index]/2)

print(sum(goods_price_list))

Fixed submission:
'use strict'
import heapq

N, M = map(int, input().split())
goods_price_list = [-int(_) for _ in input().split()]

heapq.heapify(goods_price_list)

for i in range(M):
  heapq.heappush(goods_price_list, -((-heapq.heappop(goods_price_list) // 2)))

print(-sum(goods_price_list))

Buggy python submission (verdict: Time Limit Exceeded):
'use strict'
import math
N, M = map(int, input().split())
goods_price_list = (list(map(int, input().split())))
goods_price_list.sort(reverse=True)

if len(goods_price_list) == 1:
  for i in range(M):
    goods_price_list[0] = math.floor(goods_price_list[0]/2)

else:
  for i in range(M):
    goods_price_list[0] = math.floor(goods_price_list[0]/2)
    
    if goods_price_list[0] < goods_price_list[1]:
      num = 1
      while goods_price_list[0] <= goods_price_list[num]:
        num += 1
        if num == len(goods_price_list):
          break

      goods_price_list.insert(num,goods_price_list[0])
      del goods_price_list[0]

print(sum(goods_price_list))

Fixed submission:
'use strict'
import heapq

N, M = map(int, input().split())
goods_price_list = [-int(_) for _ in input().split()]

heapq.heapify(goods_price_list)

for i in range(M):
  heapq.heappush(goods_price_list, -((-heapq.heappop(goods_price_list) // 2)))

print(-sum(goods_price_list))

Buggy python submission (verdict: Time Limit Exceeded):
'use strict'
import math

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

for i in range(M):
  goods_price_list.sort(reverse=True)
  goods_price_list[0] = math.floor(goods_price_list[0]/2)

print(sum(goods_price_list))

Fixed submission:
'use strict'
import heapq

N, M = map(int, input().split())
goods_price_list = [-int(_) for _ in input().split()]

heapq.heapify(goods_price_list)

for i in range(M):
  heapq.heappush(goods_price_list, -((-heapq.heappop(goods_price_list) // 2)))

print(-sum(goods_price_list))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
max_move_cnt = 0
tmp_move_cnt = 0

for i in range(N):
    tmp_move_cnt = 0

    for i in range(i, N-1):
        if H[i] >= H[i+1]: 
            tmp_move_cnt += 1
        else:
            break

    if tmp_move_cnt >= max_move_cnt:
        max_move_cnt = tmp_move_cnt


print(max_move_cnt)

        


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
max_move_cnt = 0
tmp_move_cnt = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        tmp_move_cnt += 1
    else:
        tmp_move_cnt = 0

    max_move_cnt = tmp_move_cnt if tmp_move_cnt >= max_move_cnt else max_move_cnt

print(max_move_cnt)
Buggy python submission (verdict: Runtime Error):
def calc_cost(now, next):
  global h_list
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

  calc_cost(next, next + 1)
  calc_cost(next, next + 2)

N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

calc_cost(0, 0)

print(dp[N - 1])

Fixed submission:
N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def calc_cost(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

for i in range(N):
  calc_cost(i, i + 1)
  calc_cost(i, i + 2)

print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
def calc_cost(now, next):
  global h_list
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

  calc_cost(next, next + 1)
  calc_cost(next, next + 2)

N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

calc_cost(0, 1)
calc_cost(0, 2)

print(dp[N - 1])

Fixed submission:
N = int(input())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def calc_cost(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])

for i in range(N):
  calc_cost(i, i + 1)
  calc_cost(i, i + 2)

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def change_min(a, b):
  if a > b: return b
  else: return a

for i in range(N):
  for j in range(1, K + 1):
    if i + j > N - 1: continue
    dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def change_min(a, b):
  if a > b: return b
  else: return a

for i in range(N):
  for j in range(1, K + 1):
    if i + j > N - 1: continue
    dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])

print(dp[N - 1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def update_dp(now, next):
  global h_list
  global dp
  global N
  if next > N - 1: return
  if dp[next] > dp[now] + abs(h_list[next] - h_list[now]):
    dp[next] = dp[now] + abs(h_list[next] - h_list[now])
  return

for i in range(N):
  for j in range(1, K + 1):
    update_dp(i, i + j)

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
dp = [float('INF') for i in range(N)]
dp[0] = 0

def change_min(a, b):
  if a > b: return b
  else: return a

for i in range(N):
  for j in range(1, K + 1):
    if i + j > N - 1: continue
    dp[i + j] = change_min(dp[i] + abs(h_list[i] - h_list[i + j]), dp[i + j])

print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

if length_substring_S == 0:
  print('YES')
else:
  print('NO')

Fixed submission:
S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

if length_substring_S == 0:
  print('YES')
else:
  print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break
    flag = False

if length_substring_S == 0:
  print('YES')
else:
  print('NO')

Fixed submission:
S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

if length_substring_S == 0:
  print('YES')
else:
  print('NO')