Harryxun/stf_run huggingface dataset:
def test(t):
    if len(t)==len(s):
        print('YES')
        exit()
    if s[len(t):len(t)+5]=='dream':
        test(t+'dream')
    if s[len(t):len(t)+7]=='dreamer':
        test(t+'dreamer')
    if s[len(t):len(t)+5]=='erase':
        test(t+'erase')
    if s[len(t):len(t)+6]=='eraser':
        test(t+'eraser')
s=input()
test('')
print('NO')

### FIXED CODE ###

s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')
N,T=input().split()
a=0
b=0
for i in range(int(N)):
    c,t=input().split()
    if int(t)<=int(T):
        if b==0:
            a=c
            b+=1
        if int(c)<int (a):
            a=c
            i+=1
if a==0:
    print("TLE")
else :
    print(a)
    ckdljfskldklsakldlksafkdshfhkfhsdkfkjdshfjkhskfkjsfkjlsalkjdhkjashdkhJKDHKAJHDKSHDSAHDIUAHFIUAHSFUAHFAULHFLKUASHFKULHSUAKLHDKUHFSUKHN,T=input().split()
a=0
b=0
for i in range(int(N)):
    c,t=input().split()
    if int(t)<=int(T):
        if b==0:
            a=c
            b+=1
        if int(c)<int (a):
            a=c
            i+=1
if a==0:
    print("TLE")
else :
    print(a)
    ckdljfskldklsakldlksafkdshfhkfhsdkfkjdshfjkhskfkjsfkjlsalkjdhkjashdkhJKDHKAJHDKSHDSAHDIUAHFIUAHSFUAHFAULHFLKUASHFKULHSUAKLHDKUHFSUKH

### FIXED CODE ###

N,T=map(int,input().split())
c=[]
mn=1001
for i in range(N):
    cost,time=map(int,input().split())
    if time<=T:
        c.append(cost)
for i in c:
    if i<=mn:
        mn=i
if len(c)==0:
    print('TLE')
else:
    print(mn)
a=input()
b=input()

print(a*b)
print(2a+2b)


### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,2*(a+b))
S,T=input().split()
for i in range(0,len(S)):
  cr=0
  if S[i]==T[i]:
    cr+=1
print(cr)

### FIXED CODE ###

s=input()
t=input()
cr=0
for i in range(3):
  if s[i]==t[i]:
    cr+=1
print(cr)
N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}

for i in S:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for first, second, third in combinations(march.values(), 3):
    ans += first * second * third

print(ans)

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
march = {"M":0, "A":0, "R":0, "C":0, "H":0}

for i in S:
    if i[0] in march:
        march[i[0]] += 1

ans = 0
for key1, value1 in march.items():
    for key2, value2 in march.items():
        for key3, value3 in march.items():
            if key1 < key2 < key3:
                ans += value1 * value2 * value3

print(ans)
import math
A,B = map(int,input().split())
print((A*B) // math.gcd(A,B))


### FIXED CODE ###

import fractions
A,B = map(int,input().split())
print((A*B)//fractions.gcd(A,B))
N, K = map(int, input().split())
a_array = [int(i) for i in input().split()]

right_counter = 0
all_counter = 0
multier = K * (K-1) / 2
if multier >= 10 ** 9 + 7:
    multier %= (10 ** 9 + 7)
threshold = -(-(10 ** 9 + 7) // multier)
threshold_right = -(-(10 ** 9 + 7) // K)
for i in range(N):
    a_i = a_array[i]
    left_over = 0
    right_over = 0
    for j in range(i):
        if a_array[j] < a_i:
            left_over += 1
    for j in range(i+1, N):
        if a_array[j] < a_i:
            right_over += 1
    right_counter += right_over
    all_counter += right_over + left_over
    if right_counter >= threshold_right:
        right_counter %= threshold_right
    if all_counter >= threshold:
        all_counter %= threshold
sum = all_counter * multier + right_counter * K
sum %= (10 ** 9 + 7)
print(sum)

### FIXED CODE ###

N, K = map(int, input().split())
a_array = [int(i) for i in input().split()]

countR=0
countA=0

for i in range(N):
    for j in range(i+1, N):
        if a_array[i] > a_array[j]:
            countR += 1

    for j in range(N):
        if a_array[i] > a_array[j]:
            countA += 1

print(int((countR * K + countA * K * (K-1) // 2)%(10**9+7)))
a,b=map(int,input().split)
print(a-b if b<a else a-b+1)

### FIXED CODE ###

a,b=map(int,input().split())
print(a if a<=b else a-1)
a , b = map(int,input().split())
list = []
papa = ""
for i in range(b):
  list.append(input()) 
c = sorted(list)
for x in c:
  papa += x
print(papa)

### FIXED CODE ###

a , b = map(int,input().split())
c_list = sorted([input() for i in range(a)])
print("".join(c_list))
s = input
s[3] = "8"
print(s)

### FIXED CODE ###

s = input()

print("2018/01/" + s[-2:])
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    if A[i] >= K:
        cnt += 1

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    if A[i] >= K:
        ans += 1

print(ans)
from math import factorial as f
n,k=[int(i) for i in input().split()]
d=[0]*n
for j in range(n-1):
  a,b=[int(i)-1 for i in input().split()]
  d[a]+=1
  d[b]+=1
m=1000000007
l=k*(f(k-1)//f(k-d[0]))%m
for i in d[1:]:
  l=l*(f(k-2)//f(k-i-1))%m
print(l)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, k = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
ans = 1
mod = 10**9+7


def dfs(i=0, r=-1):
    global ans
    if r == -1:
        ans *= k
        ans %= mod

        p = k-1
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)
    else:
        p = k-2
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)


dfs()
print(ans)
# To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'

# %%
one = lst[0][0]
two = lst[0][1]
three = lst[0][2]


# %%
one_two = one == two
two_three = two == three
three_one = three == one




# %%
if any([one_two, two_three, three_one]):
    print('Yes')
else:
    print('No')


# %%




### FIXED CODE ###

# To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'

# %%
lst = input().split()

# %%
one = lst[0][0]
two = lst[0][1]
three = lst[0][2]


# %%
one_two = one != two
two_three = two != three
three_one = three != one


# %%
any([one_two, two_three, three_one])


# %%
if any([one_two, two_three, three_one]):
    print('Yes')
else:
    print('No')


# %%
n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
test = dict(zip(a,b))
test = sorted(test.items())

# test_item = test.values()
# test_key = test.keys()
# print(test_item)
# print(test_key)
# for i in range(n):
#     if m-test[i][1] >=0:

i=0
while m>0:
    if m-test[i][1] >=0:
        ans += test[i][0]*test[i][1]
        m -=test[i][1]
        i += 1
    else:
        ans += test[i][0]*m
        m=0
        print(ans)
        exit()
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
test = list(zip(a,b))
test = sorted(test)
i=0
while m>0:
    if m-test[i][1] >=0:
        ans += test[i][0]*test[i][1]
        m -=test[i][1]
    else:
        ans += test[i][0]*m
        m=0
        print(ans)
        exit()
    i+=1
print(ans)
import sys
readline = sys.stdin.readline

sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    As = list(map(int, input().split()))

    query = (map(int, readline().strip().split()) for _ in range(N-1))

    tree = [[] for _ in range(N)]
    for u, v in query:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)

    inf = 10 ** 9 + 7
    dp = [inf] * N
    ans = [0] * N

    def dfs(node, parent):
        v = As[node]
        lb = binary_search(dp, v)
        old = dp[lb]
        dp[lb] = v
        ans[node] = dp.index(inf)
        for child in tree[node]:
            if child == parent:
                continue
            dfs(child, node)
        dp[lb] = old

    dfs(0, 0)

    for k in range(N):
        print(ans[k])


def binary_search(seq, v):
    left = 0
    right = len(seq) - 1
    center = right // 2

    while left != right:
        if v <= seq[center]:
            right = center
        else:
            left = center+1
        center = (right + left) // 2

    return center


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
readline = sys.stdin.readline

sys.setrecursionlimit(10**6)


def main():
    N = int(input())
    As = list(map(int, input().split()))

    query = (map(int, readline().strip().split()) for _ in range(N-1))

    tree = [[] for _ in range(N)]
    for u, v in query:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)

    inf = 10 ** 18
    dp = [inf] * (N+1)
    ans = [0] * N

    def dfs(node, parent):
        v = As[node]
        lb = binary_search(dp, v)
        old = dp[lb]
        dp[lb] = v
        ans[node] = binary_search(dp, inf)
        for child in tree[node]:
            if child == parent:
                continue
            dfs(child, node)
        dp[lb] = old

    dfs(0, 0)

    for k in range(N):
        print(ans[k])


def binary_search(seq, v):
    left = 0
    right = len(seq) - 1
    center = right // 2

    while left != right:
        if v <= seq[center]:
            right = center
        else:
            left = center+1
        center = (right + left) // 2

    return center


if __name__ == "__main__":
    main()
N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)

### FIXED CODE ###

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

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
N = int(input())
M = int(input())
answer = (N*(N-1) / 2) + (M*(M-1) / 2)

print(int(answer))

### FIXED CODE ###

a = input().split()
N = int(a[0])
M = int(a[1])

answer = (N*(N-1) / 2) + (M*(M-1) / 2)

print(int(answer))
import heapq

def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    #breakするタイミングを作るため、Mより大きい値の仕事を作成
    banpei_list=[[i,0] for i in range(1,m+2)]
    #リストの統合
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    print(jobs_list)
    ans=0
    index=0
    que=[]
    while 1:
        day,pay=jobs_list[index]
        print(jobs_list[index])
        #dayがMを超えていればbreak
        if day>m:
            break
        #同じdayのデータが次にもあれば-1倍してheapにpush
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        #仕事の報酬の最大値を答えに加える
        #前の日のデータからも報酬が良い仕事は選べるようにqueにデータは貯めておく
        else:
            heapq.heappush(que,-pay)
            print(que)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()

### FIXED CODE ###

#-*-coding:utf-8-*-

import heapq

def main2():
    n,m=map(int,input().split())
    jobs_list=[list(map(int,input().split())) for _ in range(n)]
    #breakするタイミングを作るため、Mより大きい値の仕事を作成
    banpei_list=[[i,0] for i in range(1,m+2)]
    #リストの統合
    jobs_list.extend(banpei_list)
    jobs_list=sorted(jobs_list)
    ans=0
    index=0
    que=[]
    while 1:
        day,pay=jobs_list[index]
        #dayがMを超えていればbreak
        if day>m:
            break
        #同じdayのデータが次にもあれば-1倍してheapにpush
        if day==jobs_list[index+1][0]: 
            heapq.heappush(que,-pay)
        #仕事の報酬の最大値を答えに加える
        #前の日のデータからも報酬が良い仕事は選べるようにqueにデータは貯めておく
        else:
            heapq.heappush(que,-pay)
            ans-=heapq.heappop(que)
        index+=1
    print(ans)

if __name__ == "__main__":
    main2()
if N >= 90:
    print("Yes")
elif (N+1)%10 is 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = int(input())

if N >= 90:
    print("Yes")
elif (N+1)%10 is 0:
    print("Yes")
else:
     print("No")
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    name_roop = []

    level = 1

    ans = ""
    n = 26
    for i in range(100):
        if N > n:
            n += 26**(i+2)
            level += 1
        else:
            break

    for i in range(level, 1, -1):
        count = 0
        a = 26**(i-1)
        for j in range(26):
            if N-a > 26**(i-2):
                N -= a
                count += 1

        name_roop.append(count)

    name_roop.append(N)
    for i in name_roop:
        ans += ascii_lowercase[i-1]
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    name_roop = []

    level = 1

    ans = ""
    while N > 0:
        N -= 1
        n = N % 26
        ans += ascii_lowercase[n]
        N //= 26
    print(ans[::-1])
    # for i in range(level, 1, -1):
    #     count = 0
    #     a = 26**(i-1)
    #     for j in range(26):
    #         if N-a > 26**(i-2):
    #             N -= a
    #             count += 1
    #     name_roop.append(count)

    # name_roop.append(N)
    # for i in name_roop:
    #     ans += ascii_lowercase[i-1]
    # print(ans)


if __name__ == '__main__':
    main()
def main():
    N, W = map(int, input().split())
    l = []
    w, v = map(int, input().split())
    ww = w
    dp = [[[0] * (3*N) for _ in range(N+1) ]for _ in range(N)]
    dp[0][1][0] = v
    l.append((0, v))
    for _ in range(N-1):
        w, v = map(int, input().split())
        l.append((w-ww, v))
    if W < ww:
        return 0
    for i in range(1, N):
        w, v = l[i]
        for j in range(1, N+1):
            for k in range(w):
                dp[i][j][k] = dp[i-1][j][k]
            for k in range(w, 3*N):
                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)
    r = 0
    for i in range(N+1):
        wt = W - i * ww
        r = max(r, max(dp[-1][i][:wt+1]))
    return r
print(main())


### FIXED CODE ###

def main():
    N, W = map(int, input().split())
    l = []
    w, v = map(int, input().split())
    ww = w
    dp = [[[0] * (3*N) for _ in range(N+1) ]for _ in range(N)]
    dp[0][1][0] = v
    l.append((0, v))
    for _ in range(N-1):
        w, v = map(int, input().split())
        l.append((w-ww, v))
    if W < ww:
        return 0
    for i in range(1, N):
        w, v = l[i]
        for j in range(1, N+1):
            for k in range(w):
                dp[i][j][k] = dp[i-1][j][k]
            for k in range(w, 3*N):
                dp[i][j][k] = max(dp[i-1][j][k], dp[i-1][j-1][k-w] + v)
    r = 0
    for i in range(N+1):
        wt = W - i * ww
        if wt < 0:
            break
        r = max(r, max(dp[-1][i][:wt+1]))
    return r
print(main())
a,b,x=map(int,input().split())
count=0
lst=[0]*(b+1)

for i in range(0,b+1):
    lst[i]=i//x
print(lst[b]-lst[a-1])

### FIXED CODE ###

a,b,x=map(int,input().split())

fb=b//x
fa=(a-1)//x
print(fb-fa)
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
s = []

for i in A:
    for j in B:
        for k in C:
            s.append(i+j+k)

s = sorted(s, reverse=True)

for i in range(K):
    print s[i]

### FIXED CODE ###

X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
e = []
s = []

for i in A:
    for j in B:
        e.append(i+j)
e = sorted(e, reverse=True)

if K<len(e):
    e = e[0:K]

for i in e:
    for j in C:
        s.append(i+j)

s = sorted(s, reverse=True)

for i in range(K):
    print(s[i])
N,I=[int(a) for a in input().split(" ")]
print(N-i+1)

### FIXED CODE ###

N,I=[int(a) for a in input().split(" ")]
print(N-I+1)
n = int(input())
if n % 2 == 0:
  print(-1)
else:
  a = 7
  b = 0
  for i in range(1000000):
    if a % n == 0:
      print(i+1)
      b = 1
      break
    a = (a%n) * 10 + 7
	if b == 0:
      print(-1)

### FIXED CODE ###

n = int(input())
if n % 2 == 0:
  print(-1)
else:
  a = 7
  b = 0
  for i in range(1000000):
    if a % n == 0:
      print(i+1)
      b = 1
      break
    a = (a%n) * 10 + 7
  if b == 0:
    print(-1)
n = str(input())
if n == n[::-1]:
    print("Yes")
else("No")

### FIXED CODE ###

n = input()
if n == n[::-1]:
    print("Yes")
else:
    print("No")
n=int(input())
ans=1+n
if(n%2==0):
  ans=2+int(n/2)
  
for i in range(3,int(sqrt(n))+1,2):
  if(n%i==0):
    ans=min(ans,(i+int(n/i)))
print(ans)

### FIXED CODE ###

n=int(input())
ans=n-1
e=int(n**(1/2))+1
for i in range(2,e):
  if(n%i==0):
    ans=min(ans,i+int(n/i)-2)
print(ans)
from collections import deque

a = [int(i) for i in input().split()]
q = deque([])
for i in range(a[0]): q.append(deque([]))

for i in range(a[1]):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        q[cmd[1]].append(cmd[2])

    elif cmd[0] == 1:
        if q[cmd[1]] != []: print(q[cmd[1]][0])

    elif cmd[0] == 2:
        if q[cmd[1]] != []: q[cmd[1]].popleft()



### FIXED CODE ###

from collections import deque

a = [int(i) for i in input().split()]
q = deque([])
for i in range(a[0]): q.append(deque([]))

for i in range(a[1]):
    cmd = [int(i) for i in input().split()]

    if cmd[0] == 0:
        q[cmd[1]].append(cmd[2])

    elif cmd[0] == 1:
        if q[cmd[1]] != deque([]): print(q[cmd[1]][0])

    elif cmd[0] == 2:
        if q[cmd[1]] != deque([]): q[cmd[1]].popleft()
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

A,B,K = [int(x) for x in input().split()]
ls =[]
for i in range(1,A+1):
    if A % i == 0 and B % i == 0:
        ls.append(i)

print(ls[K])

### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

A,B,K = [int(x) for x in input().split()]
ls =[i for i in range(1,A+1) if A % i == 0 and B % i == 0]
ls.reverse()
answer = ls[K-1]
print(answer)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(int argc, char* argv[])
{
  int H,N,A,B;
  cin >> H >> N;
  vector<int> dp(H+1,1000000000);
  dp[0] = 0;
  for(int n=0; n<N; n++){
    cin >> A >> B;
    for(int h=1; h<H+1; h++){
      dp[h] = min(dp[h],dp[max(0,h-A)]+B);
    }
  }
  cout << dp[H];
  return 0;
}

### FIXED CODE ###

H,N,*AB = map(int, open(0).read().split())
dp = [0]+[10**8]*H
for n in range(N):
  A,B = AB[2*n:2*(n+1)]
  for h in range(1,H+1): dp[h] = min(dp[h],dp[max(0,h-A)]+B)
print(dp[-1])
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))    
    score = 0
    pre = -1
    for i in a:
        score += b[i]
        if(i==pre+1):
            score += c[i-2]
            pre=i
    print(score)

if __name__ == "__main__":
    main()

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)
a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]

### FIXED CODE ###

a,b,c=input().split()
if a[-1]==b[0] and b[-1]==c[0]:
    print("YES")
else:
    print("NO")
import math
import os
import random
import re
import sys
def dpkfindpath(a,k):
	dpath=[int(0) for _ in range(len(a))]
	for i in range(k):
		dpath[i]=abs(a[i]-a[0])
	
	for i in range(k,len(a)):
		m=abs(a[i]-a[i-1])+dpath[i-1]
		for j in range(1,k+1):
			if (abs(a[i]-a[i-j])+dpath[i-j])<m:
				m=abs(a[i]-a[i-j])+dpath[i-j]
		dpath[i]=m
	return dpath[len(a)-1]
		
n,k=input().split()
n=int(n)
k=int(k)
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpkfindpath(a,k))

### FIXED CODE ###

import math
import os
import random
import re
import sys
def dpfindpath(a):
	dpath=[int(0) for _ in range(len(a))]
	dpath[0]=0
	dpath[1]=abs(a[1]-a[0])
	for i in range(2,len(a)):
		dpath[i]=min(abs(a[i]-a[i-1])+dpath[i-1],abs(a[i]-a[i-2])+dpath[i-2])
	return dpath[len(a)-1]
n=int(input())
a=input().split()
for i in range(n):
  a[i]=int(a[i])
print (dpfindpath(a))
import numpy as np

A_list = []

for i in range(3):
    a = list(map(int, input().split()))
    A_list.append(a)

N = int(input())
narray = np.zeros((3, 3), dtype=np.int)


for j in range(N):
    b = int(input())

    for n in range(3):
        for m in range(3): 
            if A_list[n][m] == b:
                narray[n, m] = 1


n_list = np.count_nonzero(narray == 1, axis = 0)
m_list = np.count_nonzero(narray == 1, axis = 1)

if 3 in n_list or 3 in m_list:
    print('Yes')
    exit()

if narray[0, 0] == 1 and narray[1, 1] == 1 and narray[2, 2] == 1:
    print('Yes')
    exit()

if narray[0, 2] == 1 and narray[1, 1] == 1 and narray[2, 0] == 1:
    print('Yes')
    exit()

print('No')

### FIXED CODE ###

# https://atcoder.jp/contests/abc157/tasks/abc157_b

A_list = [[] for _ in range(3)]

for i in range(3):
    A1, A2, A3 = map(int, input().split())
    A_list[i] += [A1, A2, A3]

N = int(input())

set1 = {A_list[0][0], A_list[0][1], A_list[0][2]}
set2 = {A_list[1][0], A_list[1][1], A_list[1][2]}
set3 = {A_list[2][0], A_list[2][1], A_list[2][2]}
set4 = {A_list[0][0], A_list[1][0], A_list[2][0]}
set5 = {A_list[0][1], A_list[1][1], A_list[2][1]}
set6 = {A_list[0][2], A_list[1][2], A_list[2][2]}
set7 = {A_list[0][0], A_list[1][1], A_list[2][2]}
set8 = {A_list[0][2], A_list[1][1], A_list[2][0]}


b_set = set()

for n in range(N):
    b = int(input())
    b_set.add(b)

if (set1 <= b_set or 
    set2 <= b_set or
    set3 <= b_set or
    set4 <= b_set or
    set5 <= b_set or
    set6 <= b_set or
    set7 <= b_set or
    set8 <= b_set):

    print('Yes')
else:
    print('No')