Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n = int(input())
a = list(input().split())
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print(' '.join(b))

### FIXED CODE ###

n = int(input())
a = list(input().split())
print(' '.join(a[::-2] + a[n%2::2]))
### BUGGY CODE ###

n,m = map(int, input().split())
bl = [int(input())-1 for _ in range(m)]
l = [i for i in range(n)]
for num in bl:
    l.remove(num)
mod = 1000000007

al = [0]*n
if 0 in l and 1 in l:
    al[0] = 1
    al[1] = 2
elif 0 in l:
    al[0] =1
elif 1 in l:
    al[1] = 1
else:
    print(0)
    exit()
    
li = [i for i in l if i>=2]
for i in li:
    al[i] = al[i-1] + al[i-2]
    if al[i] == 0:
        print(0)
        exit()

print(al[-1]%mod)

### FIXED CODE ###

n,m = map(int, input().split())
bl = [int(input())-1 for _ in range(m)]
l = [i for i in range(n)]
cnt = 0
for num in bl:
    del l[num-cnt]
    cnt +=1
    
mod = 1000000007

al = [0]*n
if 0 in l and 1 in l:
    al[0] = 1
    al[1] = 2
elif 0 in l:
    al[0] =1
elif 1 in l:
    al[1] = 1
else:
    print(0)
    exit()
    
li = [i for i in l if i>=2]
for i in li:
    al[i] = al[i-1] + al[i-2]
    if al[i] == 0:
        print(0)
        exit()

print(al[-1]%mod)
### BUGGY CODE ###

import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())

n,m=reads()
link=[[]for i in range(n)]
for i in range(m):
  x,y=reads()
  link[x-1].append(y-1)
def dp(k):
  res=0
  for ele in link[k]:
    res=max(res,dp(ele)+1)
  return res
res=1
for i in range(n)  :
  res=max(res,dp(i))
print(res)

### FIXED CODE ###

import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)
#read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def read():
  return int(readline())
def reads():
  return map(int, readline().split())
def mp(arg):
  return map(int,arg.split())

n,m=reads()
link=[[]for i in range(n)]
for i in range(m):
  x,y=reads()
  link[x-1].append(y-1)
#print(link)
@lru_cache(None)
def dp(k):
  res=0
  for ele in link[k]:
    res=max(res,dp(ele)+1)
  return res
res=1
for i in range(n)  :
  res=max(res,dp(i))
print(res)
### BUGGY CODE ###

import queue
inf = float('inf')
N = int(input())
paths = [{} for i in range(N+1)]
for i in range(N-1):
    s,t = list(map(int, input().split()))
    paths[s][t] = 1
    paths[t][s] = 1

def dijkstra(start, nodes, N):
    fixed = {}
    cost = [inf] * (N + 1)
    cost[start] = 0
    q = queue.PriorityQueue()
    q.put((0, start))
    while q.empty() == False:
        w, x = q.get()
        if cost[x] < w: continue
        for y in nodes[x]:
            if cost[x] + paths[x][y] < cost[y]:
                cost[y] = cost[x] + paths[x][y]
                q.put((cost[y], y))
    return cost

# それぞれの位置からの到達コストを調べている
score_f = dijkstra(1, paths, N)
score_s = dijkstra(N, paths, N)

score = 0
for i in range(1, N+1):
    if score_f[i] > score_s[i]:
        score -= 1
    else:
        score += 1

if score > 0:
    print("Fennec")
else:
    print("Snuke")


### FIXED CODE ###

#import queue
import heapq
inf = float('inf')
N = int(input())
paths = [{} for i in range(N+1)]
for i in range(N-1):
    s,t = list(map(int, input().split()))
    paths[s][t] = 1
    paths[t][s] = 1

def dijkstra(start, nodes, N):
    cost = [inf] * (N + 1)
    cost[start] = 0
    q = []
    heapq.heappush(q, (0, start))
#    q.put((0, start))
    while q: #q.empty() == False:
        w, x = heapq.heappop(q)
        if cost[x] < w: continue
        for y in nodes[x]:
            if cost[x] + paths[x][y] < cost[y]:
                cost[y] = cost[x] + paths[x][y]
#                q.put((cost[y], y))
                heapq.heappush(q, (cost[y], y))
    return cost

# それぞれの位置からの到達コストを調べている
score_f = dijkstra(1, paths, N)
score_s = dijkstra(N, paths, N)

score = 0
for i in range(1, N+1):
    if score_f[i] > score_s[i]:
        score -= 1
    else:
        score += 1

if score > 0:
    print("Fennec")
else:
    print("Snuke")
### BUGGY CODE ###

set = int(input())

lis = list(map(int, input().split()))

v = 0

for i in range(set):
    for k in range(1 + i, set):
        #print()
        if lis[i] == lis[k]:
            v = 1
            
if v == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

set = int(input())
 
lis = list(map(int, input().split()))
 
v = 0
lis.sort()

for i in range(set-1):
    if lis[i] == lis[i + 1]:
        v =1
            
if v == 0:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

from pprint import pprint as pp
from functools import lru_cache
import math
"""
問題文
「N も (N+1)÷2 も素数」を満たす奇数 N を 2017に似た数 とします。
Q 個のクエリが与えられます。
クエリ i(1≦i≦Q) では奇数 li,ri が与えられるので、li≦x≦ri かつ 2017に似た数 となる奇数 x の個数を求めてください。
制約
    1≦Q≦105
    1≦li≦ri≦105
    li,ri は奇数
    入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q
l1 r1
:
lQ rQ
出力
i 行目 (1≦i≦Q) に、クエリ i の答えが x 個のとき、x を出力せよ。
"""
q=int(input())
lr_ary = []
for _ in range(q):
  lr_ary.append(list(map(int, input().split())))

@lru_cache(maxsize=300000)
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    sqrt_n = int(math.floor(math.sqrt(n)))
    for i in range(3, sqrt_n + 1, 2):
        if n % i == 0:
            return False
    return True

rets = []
for l,r in lr_ary:
    ret=0
    for x in range(l,r+1,2):
        if is_prime(x) and is_prime((x+1)/2):
            ret += 1
    rets.append(ret)

for ret in rets:
    print(ret)

### FIXED CODE ###

from pprint import pprint as pp
from functools import lru_cache
import math
"""
問題文
「N も (N+1)÷2 も素数」を満たす奇数 N を 2017に似た数 とします。
Q 個のクエリが与えられます。
クエリ i(1≦i≦Q) では奇数 li,ri が与えられるので、li≦x≦ri かつ 2017に似た数 となる奇数 x の個数を求めてください。
制約
    1≦Q≦105
    1≦li≦ri≦105
    li,ri は奇数
    入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
Q
l1 r1
:
lQ rQ
出力
i 行目 (1≦i≦Q) に、クエリ i の答えが x 個のとき、x を出力せよ。
"""

prime = [True] * 100000
prime[0] = False
prime[1] = False
for i in range(2,len(prime)):
    if prime[i]:
        for j in range(i*2, len(prime), i):
            prime[j] = False
prime2017 = [0] * 100000
prime2017[0] = 0
prime2017[1] = 0
prime2017[2] = 0
ruiseki=0
for x in range(3,len(prime)):
    if prime[x] and prime[int((x+1)/2)]:
        ruiseki+=1
    prime2017[x] = ruiseki
q=int(input())
lr_ary = []
for _ in range(q):
    l,r=list(map(int, input().split()))
    print(prime2017[r]-prime2017[l-1])
### BUGGY CODE ###

n = int(input())
l = [input() for i in range(n)]

from collections import Counter
ans = 0
for i in range(len(l)):
  for j in range((i+1),len(l)):
    if Counter(l[i]) == Counter(l[j]):
      ans += 1
print(ans)

### FIXED CODE ###

N=int(input())
l=[]
from collections import Counter
for i in range(N):
  l.append(''.join(sorted(input())))
l1=Counter(l).values()
from math import factorial
ans=0
for a in l1:
  if a >= 2:
    ans+=int(factorial(a)/(factorial(a-2)*factorial(2)))
print(ans)
### BUGGY CODE ###

n = int(input())
d = [[float("inf")]*n for i in range(n)]

ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
INF = float('inf')
dist0 = [INF] * n
dist0[0] = 0
visited0 = [0]*n
def dfs0(v, parent = -1):
    if dist0[v] == INF:
        dist0[v] = dist0[parent]+1
    for next_v in es[v]:
        if dist0[next_v] == INF:
            dfs0(next_v,v)
dfs0(0)

distn = [INF] * n
distn[n-1] = 0
visitedn = [0]*n
def dfsn(v, parent = -1):
    if distn[v] == INF:
        distn[v] = distn[parent]+1
    for next_v in es[v]:
        if distn[next_v] == INF:
            dfsn(next_v,v)
dfsn(n-1)

count_f = 0
for i in range(n):
    if dist0[i] <= distn[i]:
        count_f+=1

if count_f > n-count_f: print('Fennec')
else: print('Snuke')


### FIXED CODE ###

n = int(input())

ab = [tuple(map(int,input().split())) for i in range(n-1)]
es = [[] for i in range(n)]
for a,b in ab:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
INF = float('inf')
dist0 = [INF] * n
dist0[0] = 0
import heapq
hq = [(0,0)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to in es[v]:
        if c+1 >= dist0[to]: continue
        dist0[to] = c+1
        heapq.heappush(hq,(c+1,to))

distn = [INF] * n
distn[n-1] = 0
hq = [(0,n-1)]
heapq.heapify(hq)
while hq:
    c,v = heapq.heappop(hq)
    for to in es[v]:
        if c+1 >= distn[to]: continue
        distn[to] = c+1
        heapq.heappush(hq,(c+1,to))


count_f = 0
for i in range(n):
    if dist0[i] <= distn[i]:
        count_f+=1

if count_f > n-count_f: print('Fennec')
else: print('Snuke')
### BUGGY CODE ###

import itertools

N, K = map(int, input()  .split())
candidate = list(range(N+1))
comb = list(itertools.product(candidate, repeat=3))
i = 0
for c in comb:
    if sum(c) == K:
        i += 1

print(i)

### FIXED CODE ###

k, s = map(int, input().split())

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

print(cnt)
### BUGGY CODE ###

from fractions import gcd

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

ans = 0
for i in range(n):
  g = 0
  for j in range(n):
    if i != j:
      g = gcd(g, a[j])
  ans = max(ans, g)
print(ans)

### FIXED CODE ###

from fractions import gcd

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

l = []
g = 0
for i in range(n):
  tmp = gcd(g, a[i])
  if tmp < g or g == 0:
    l.append(i)
  g = tmp

ans = 0
for i in l:
  g = 0
  for j in range(n):
    if i != j:
      g = gcd(g, a[j])
  ans = max(ans, g)
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
def main():
  input = sys.stdin.readline
  n, k = map(int , input().split())
  p_list = np.array(list(map(int, input().split())))
  c_list = np.array(list(map(int, input().split())))
  
  dp = [[float('-inf')]*n for _ in range(k+1)]
  dp[0] = [0]*n
  for i in range(k):
    for j in range(n):
      if i==0:
        dp[i+1][p_list[j]-1] = dp[i][j]+c_list[j]
      else:
        dp[i+1][p_list[j]-1] = max(dp[i][p_list[j]-1], dp[i][j]+c_list[j])
  print(max(dp[-1]))

if (__name__=='__main__'):
  main()

### FIXED CODE ###

import sys
def main():
  input = sys.stdin.readline
  n, k = map(int , input().split())
  p_list = list(map(int, input().split()))
  c_list = list(map(int, input().split()))
  res = -float('inf')
  
  for s in range(n):
    S = []
    i = p_list[s] - 1
    S.append(c_list[i])
    while i != s:
      i = p_list[i]-1
      S.append(S[-1] + c_list[i])
    if k <= len(S):
      score = max(S[:k])
    elif S[-1] <= 0:
      score = max(S)
    else:
      score1 = S[-1] * (k//len(S) - 1)
      score1 += max(S)
      
      score2 = S[-1] * (k//len(S))
      r = k%len(S)
      if r!=0:
        score2 += max(0, max(S[:r]))
      score = max(score1, score2)
    res = max(res, score)
  print(res)
      

if (__name__=='__main__'):
  main()
### BUGGY CODE ###

T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())
    if A < B:
        print('No')
        continue
    if B > D:
        print('No')
        continue
    if C >= B - 1:
        print('Yes')
        continue
    A = A % B
    D = D % B
    first_A = A
    while True:
        if A > C:
            print('No')
            break
        A = (A + D) % B
        if A == first_A:
            print('Yes')
            break


### FIXED CODE ###

import fractions

T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())
    if A < B:
        print('No')
        continue
    if B > D:
        print('No')
        continue
    if C >= B - 1:
        print('Yes')
        continue
    A = A % B
    D = D % B
    BD = fractions.gcd(B, D)
    A_max = A + BD * ((B - 1 - A) // BD)
    if A_max > C:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(10000)

(R, C) = reads()
N = read()

d = defaultdict(list)
V = set()

for _ in range(N):
  (r, c, a) = reads()
  d["R", r-1].append((("C", c-1), a))
  d["C", c-1].append((("R", r-1), a))
  V.add(("R", r-1))
  V.add(("C", c-1))

def walk(v):
  for (w, a) in d[v]:
    wcol = a - col[v]
    if w in col:
      if col[w] != wcol:
        print("No"); exit()
    else:
      col[w] = wcol
      walk(w)

while len(V) > 0:
  col = dict()
  v = V.pop()
  col[v] = 0
  walk(v)
  rcol = min(a for (v, a) in col.items() if v[0] == "R")
  ccol = min(a for (v, a) in col.items() if v[0] == "C")
  if rcol + ccol < 0:
    print("No"); exit()

print("Yes")


### FIXED CODE ###

from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(R, C) = reads()
N = read()

d = defaultdict(list)
V = set()

for _ in range(N):
  (r, c, a) = reads()
  (r, c) = (r-1, c-1)
  d["R", r].append((("C", c), a))
  d["C", c].append((("R", r), a))
  V.add(("R", r))
  V.add(("C", c))

def walk(v):
  V.discard(v)
  for (w, a) in d[v]:
    wcol = a - col[v]
    if w in col:
      if col[w] != wcol:
        print("No"); exit()
    else:
      col[w] = wcol
      walk(w)

while len(V) > 0:
  v = V.pop()
  col = dict()
  col[v] = 0
  walk(v)
  rcol = min(a for (v, a) in col.items() if v[0] == "R")
  ccol = min(a for (v, a) in col.items() if v[0] == "C")
  if rcol + ccol < 0:
    print("No"); exit()

print("Yes")
### BUGGY CODE ###

n=int(input())
s=list(input())
x=[]
y=[]
z=[]
count=0

for i in range(n-2):
    y=[]
    if x.count(s[i])!=0:
        continue
    else:
        x.append(s[i])
        for j in range(i+1,n-1):
                for k in range(j+1,n):
                    v=s[j]+s[k]
                    if y.count(v)!=0:
                        continue
                    else:
                        y.append(v)
                        count+=1
                        

                
                        
                
        
    
print(count)


### FIXED CODE ###

n=int(input())
s=list(input())
count=0

for i in range(1000):
    if len(str(i))==1:
        i=str(0)+str(0)+str(i)
    elif len(str(i))==2:
        i=str(0)+str(i)
    else:
        i=str(i)
    x=0
    for j in range(n):
        if s[j]==i[x]:
            x+=1
            if x==3:
                count+=1
                break
print(count)
### BUGGY CODE ###

s=input()
k=int(input())
a=[]
for i in range(0,len(s)):
    for j in range(1,len(s)+1):
        a.append(s[i:j])
num = a.count("")
for i in range(num):
    a.remove("")
a=sorted(a)
b=[]
for i in a:
    if i not in b:
        b.append(i)
print(b[k-1])



### FIXED CODE ###

s=input()
k=int(input())
a=[s[i:i+j+1] for i in range(len(s)) for j in range(k+1)]
a=set(a)
a=sorted(a)
print(a[k-1])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
na = max(a)+1
for i in range(1,na+1):
	ans[i] += a.count(i)
ans.pop(0)
for j in range(n):
	print(ans[j])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
for i in range(len(a)):
	ans[a[i-1]] += 1
ans.pop(0)
for j in range(n):
	print(ans[j])
### BUGGY CODE ###

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

import sys

lis = []
lis2 = []

def sum(lis):
  s = 0
  for e in lis:
    s += e
  return s

while True:
  num = input()
  if num == 0:
    break
  else:
    lis = []
    lis2 = []
    maxnum = -99999
    for i in range(num):
      lis.append(input())
    for i in range(len(lis)):
      for j in range(i+1,len(lis)+1):
        su = sum(lis[i:j])
        if su > maxnum:
          maxnum = su
    print maxnum

### FIXED CODE ###

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

while True:
  num = input()
  if num == 0:
    break
  lis = [0]*num
  for i in range(num):
    n = input()
    if i == 0:
      lis[0] = n
    else:
      lis[i] = max( lis[i-1] + n , n )
  print max(lis)
### BUGGY CODE ###

n = int(input())
s = [input() for i in range(n)]
used = [s[0]] + [0 for i in range(n-1)]
co = [1] + [0 for i in range(n-1)]
if n == 1:
    print(used[0])
else:
    ind = 1
    for i in s[1:]:
        if i in used[:ind]:
            co[used[:ind].index(i)] += 1
        else:
            used[ind] = i
            co[ind] = 1
            ind += 1
    ma = max(co)
    arg = [i for i in range(n) if co[i]==ma]
    ans = [used[i] for i in arg]
    print("\n".join(sorted(ans)))

### FIXED CODE ###

n = int(input())
s = sorted([input() for i in range(n)])
s_ = sorted(list(set(s)))
if len(s_) != n:
    s.append(0)
    co = [1] + [0 for i in range(len(s_)-1)]
    ind = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            co[ind] += 1
        else:
            ind += 1
            co[ind] += 1
    ma = max(co)
    arg = [i for i in range(len(s_)) if co[i]==ma]
    ans = [s_[i] for i in arg]
    print("\n".join(sorted(ans)))
    
else:
    print("\n".join(s))
### BUGGY CODE ###

s=input()
q=int(input())

for _ in range(q):
    query=list(input().split())
    if query[0]=='1':
        s=s[::-1]
    else:
        if query[1]=='1':
            s=query[2]+s
        else:
            s+=query[2]
print(s)

### FIXED CODE ###

from collections import deque

s=input()
q=int(input())
d=deque(s)

cnt=0
for _ in range(q):
    query=list(input().split())
    if query[0]=='1':
        cnt=(cnt+1)%2
    else:
        if query[1]=='1':
            if cnt==1:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if cnt==1:
                d.appendleft(query[2])
            else:
                d.append(query[2])
                
ans=list(d)
                
if cnt==1:
    print(*ans[::-1],sep='')
else:
    print(*ans,sep='')
### BUGGY CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

T = S()

def match(v):
    return int(v) % 2019 == 0

cnt = 0

M = {}

for i in range(0, len(T)):
    for j in range(i+1, len(T)+1):
        s = T[i:j]
        if s in M and M[s] == False:
            continue

        if match(s):
            M[s] = True
            cnt += 1
            continue

        M[s] = False

print(cnt)

### FIXED CODE ###

from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

T = S()

revT = reversed(T)

n, d, mods = 0, 1, [1]+[0]*2019

for i in revT:
    n = (n + int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1

sum = 0
for j in mods:
    sum += j*(j-1)//2

print(sum)
### BUGGY CODE ###

N, Q = map(int, input().split())
s = input()
TD = [input().split() for i in range(Q)]


def check(i):
    """どっちに落ちるかを返す
    -1,0,1

    Args:
        i ([type]): [description]
    """

    if i == -1:
        return -1
    if i == N:
        return 1

    for q in range(Q):
        t, d = TD[q]
        if t == s[i]:
            if d == "L":
                i -= 1
            if d == "R":
                i += 1

            if i == -1:
                return -1
            if i == N:
                return 1
    return 0


s_index = -1  # include
e_index = N  # include
while s_index+1 < e_index:
    c_index = (s_index+e_index)//2
    if check(c_index) == -1:
        s_index = c_index
    else:
        e_index = c_index
left = s_index

s_index = -1  # include
e_index = N  # include
while s_index+1 < e_index:
    c_index = (s_index+e_index)//2
    if check(c_index) == 1:
        e_index = c_index
    else:
        s_index = c_index
right = e_index


print(right-left-1)


### FIXED CODE ###

N, Q = map(int, input().split())
s = input()
TD = [input().split() for i in range(Q)]


def simulate(n):
    if n == -1:
        return -1
    if n == N:
        return 1
    for t, d in TD:
        if t == s[n]:
            if d == "L":
                n -= 1
            else:
                n += 1
        if n == -1:
            return -1
        elif n == N:
            return 1
    return 0


l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == -1:
        l = n
    else:
        r = n
L = l

l = -1
r = N
while l+1 < r:
    n = (l+r)//2
    sim = simulate(n)
    if sim == 1:
        r = n
    else:
        l = n
R = r
print(R-L-1)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2000000001)
ab = abs

def solve(n,k,ar,dp,x):
	if x>=n-2: return dp[x]
	if not dp[x] is -1: return dp[x]
	m = 1e9; tmp = x+k+1
	for i in range(x+1,n if n<tmp else tmp):
		t = ab(ar[x]-ar[i])+solve(n,k,ar,dp,i)
		m = t if t<m else m
	dp[x] = m
	# pr(f'{x} => {dp[x]}')
	return dp[x]

def main():
	I = lambda:map(int,sys.stdin.readline().split())
	pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [ab(ar[-2]-ar[-1]),0]
	# pr((n,k,ar,dp))
	pr(solve(n,k,ar,dp,0))

main()

### FIXED CODE ###

import sys
from functools import reduce
sys.setrecursionlimit(2000000001)

def solve(n,k,ar,dp,x):
	ab = abs; mn = min
	if x>=n-2: return dp[x]
	if not dp[x] is -1: return dp[x]
	# t = [ for i in range(x+1,mn(n,x+k+1))]
	t = map(lambda i:ab(ar[x]-ar[i])+solve(n,k,ar,dp,i), range(x+1,mn(n,x+k+1)))
	dp[x] = reduce(lambda a,b : a if a < b else b,t)
	return dp[x]

def main():
	I = lambda:map(int,sys.stdin.readline().split())
	pr = lambda x:sys.stdout.write(f'{x}\n')
	n,k, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	pr(solve(n,k,ar,dp,0))

main()
### BUGGY CODE ###

import sys

def expand(bou_len, cost):
    bou_len += 1
    cost += 1
    return bou_len, cost

def shrink(bou_len, cost):
    bou_len -= 1
    cost += 1
    return bou_len, cost

lines = sys.stdin.readlines()
N = int(lines[0])

lst = []
for n in map(int,lines[1].split(' ')):
    lst.append(n)

lst_sum = sum(lst)
half_len = lst_sum / 2

center_idx = 0
bar_len = 0
center_dist = 1000000
for index, element in enumerate(lst):
    bar_len += element
    if abs(half_len - bar_len) < center_dist:
        center_idx = index
        center_dist = abs(half_len - bar_len)
        if center_dist == 0:
            break

left_half = lst[:center_idx+1]
right_half = lst[center_idx+1:]

left_sum = sum(left_half)
right_sum = sum(right_half)

cost = 0
while (left_sum != right_sum):
    if left_sum < right_sum:
        left_sum, cost = expand(left_sum, cost)
    if left_sum > right_sum:
        left_sum, cost = shrink(left_sum, cost)

print(cost)

### FIXED CODE ###

import sys
import numpy as np

lines = sys.stdin.readlines()
N = int(lines[0])

stdin = list(map(int,lines[1].split(' ')))

lst = []
S1, S2 = 0, sum(stdin)
for i, a in enumerate(stdin):
    S1 += a
    S2 -= a
    lst.append(abs(S1-S2))

print(min(lst))