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

N = int(input())
A = list(map(int, input().split()))
flag = False
for i in range(N-1):
    j = i+1
    while(j<N):
        if A[i]==A[j]:
            flag = True
            break
        j += 1
    if flag:
        break
if flag:
    print("NO")
else:
    print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort()
flag = False

for i in range(N-1):
    if A[i]==A[i+1]:
        flag=True
        break
if flag:
    print("NO")
else:
    print("YES")
### BUGGY CODE ###

n=int(input())
alist=list(map(int,input().split()))
sosu=10**9+7
tenlist=[0]*60

for a in alist:
    tmp=str(format(a,"b"))
    for i in range(len(tmp)):
        if tmp[-(i+1)]=="1":
            tenlist[i] = tenlist[i]+1

out=0
for i, ten in enumerate(tenlist):
    out += (ten*(n-ten))*pow(2,i,sosu)
    out %= sosu


print(int(out))

        

### FIXED CODE ###

n=int(input())
alist=list(map(int,input().split()))
sosu=10**9+7
tenlist=[0]*60

for a in alist:
    tmp=str(format(a,"b"))
    for i in range(len(tmp)):
        if tmp[-(i+1)]=="1":
            tenlist[i] = tenlist[i]+1

out=0
for i, ten in enumerate(tenlist):
    out += (ten*(n-ten))*pow(2,i,sosu)
    out %= sosu


print(int(out))
### BUGGY CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()


### FIXED CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = sorted(a)[::-1]
import bisect
import math
def combinations_count(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
ret = 0
for i in range(n//2):
    kl = bisect.bisect_left(a_,a[i]//2)
    kr = bisect.bisect_right(a_,a[i]//2)
    cmb = max(combinations_count(a[i],a_[kl]),combinations_count(a[i],a_[kr]))
    if ret<cmb:
        ans = [a[i],a_[kr]]
        ret = cmb
print(ans[0],ans[1])


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a_ = sorted(a)
if len(a)==2:
    print(a_[1],a_[0])
    exit()
a = a_[::-1]
k = 10**9
for i in range(1,n):
    if k>abs(a[0]/2-a[i]):
        k=abs(a[0]/2-a[i])
        ans = [a[0],a[i]]
print(ans[0],ans[1])
### BUGGY CODE ###

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

town = [n, 0, 0, 0, 0, 0]
count = 0

while(town[5] < n):
  for i in range(4, -1, -1):
    if town[i] > 0:
      if town[i] < ways[i]:
        town[i+1] += town[i]
        town[i] = 0
      else:
        town[i] -= ways[i]
        town[i+1]+= ways[i]
  count+=1
print(count)
  

### FIXED CODE ###

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

ans = n//min(ways) if n%min(ways) == 0 else n//min(ways)+1
print(ans+4)
### BUGGY CODE ###

import numpy

N,D=(int(x) for x in input().split())

answer=0
for i in range(N):
  A,B=(int(x) for x in input().split())
  a = numpy.array([0,0])
  b = numpy.array([A,B])
  u = b - a
  h=numpy.linalg.norm(u)
  if  D>=h:
    answer+=1
print(answer)

### FIXED CODE ###

import math

N,D=(int(x) for x in input().split())

answer=0
for i in range(N):
  A,B=(int(x) for x in input().split())
  h=math.sqrt(A*A+B*B)
  if  D>=h:
    answer+=1
print(answer)
### BUGGY CODE ###

N = int(input())
data = [list(map(int, input().split())) for _ in range(N)]

dif = [data[i][0] - data[i][1] for i in range(N)]
A = [data[i][0] for i in range(N)]
B = [data[i][1] for i in range(N)]
count1 = 0
count2 = 0

def fa():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) > -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    B.pop(index)
    return A.pop(index)

def fb():
    if max(dif) > 0 or min(dif) < 0:
        if max(dif) < -min(dif):
            index = dif.index(max(dif))
        else:
            index = dif.index(min(dif))
    else:
        index = A.index(max(A))

    dif.pop(index)
    A.pop(index)
    return B.pop(index)

while True:
    count1 += fa()
    if len(A) == 0:
        break
    count2 += fb()
    if len(A) == 0:
        break

print(count1 - count2)

### FIXED CODE ###

N = int(input())

AB = []
sum = 0
for i in range(N):
    a, b = [int(i) for i in input().split()]
    sum -= b
    AB.append(a+b)

AB.sort(reverse=True)

count = 0
for _ in range(N//2):
    count += AB.pop(0)
    AB.pop(0)
if N%2 == 1:
    count += AB.pop(0)

print(count + sum)
### BUGGY CODE ###

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

flag = True

if N % 2 != 0:
    for i in range(0,N,2):
        if i == 0:
            if A.count(0) != 1:
                flag = False
                break
        else:
            if A.count(i) != 2:
                flag = False
                break
else:
    for i in range(1,N,2):
        if A.count(i) != 2:
            flag = False
            break
            
if flag == False:
    print(0)
else:
    print(pow(2,N//2,10**9+7))

### FIXED CODE ###

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

from collections import Counter
MOD = 10**9 + 7
c = Counter(a)

ans = 0

if n % 2 == 1:
    for i in range(2, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    if c[0] == 1:
        ans = pow(2, n // 2, MOD)
else:
    for i in range(1, n, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = pow(2, n // 2, MOD)
print(ans)
### BUGGY CODE ###

N = int(input())
P = 1
for n in range(1,N + 1):
    P = P * n
print(P % ((10**9) + 7))

### FIXED CODE ###

N = int(input())
P = 1
for n in range(1,N + 1):
    P = (P * n) % ((10**9)+7)
print(P)
### BUGGY CODE ###

n,m,l = map(int,input().split())
road = [[] for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  road[a].append([b,c])
  road[b].append([a,c])
cango = []
for i in range(n):
  tmp = [l+1 for _ in range(n)]
  tmp[i] = 0
  now = [[i,0]]
  while now:
    last = now
    now = []
    for x in last:
      for yz in road[x[0]]:
        y,z = yz
        if x[1] + z < tmp[y]:
          tmp[y] = x[1] + z
          now.append([y,tmp[y]])
  add = []
  for i in range(n):
    if tmp[i] == 0:
      add.append(0)
    elif tmp[i] <= l:
      add.append(1)
    else:
      add.append(1000)
  cango.append(add)
#print(cango)
for k in range(n):
  for i in range(n):
    for j in range(n):
      if cango[i][k] + cango[k][j] < cango[i][j]:
        cango[i][j] = cango[i][k] + cango[k][j]
#print(cango)
q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  ans = cango[s-1][t-1]-1
  if ans > 500:
    print(-1)
  else:
    print(ans)

### FIXED CODE ###

n,m,l = map(int,input().split())
road = [[10**18 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  road[a][b] = c
  road[b][a] = c
#print(road)
for k in range(n):
  for i in range(n):
    for j in range(n):
      road[i][j] = min(road[i][j],road[i][k]+road[k][j])
#print(road)
cango = [[1000 for _ in range(n)] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if road[i][j] == 0:
      cango[i][j] = 0
    elif road[i][j] <= l:
      cango[i][j] = 1
#print(cango)
for k in range(n):
  for i in range(n):
    for j in range(n):
      cango[i][j] = min(cango[i][j],cango[i][k]+cango[k][j])
#print(cango)
q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  ans = cango[s-1][t-1]-1
  if ans > 500:
    print(-1)
  else:
    print(ans)
### BUGGY CODE ###

import itertools

def main():
    N, M, R = map(int, input().split())
    RR = tuple(map(int, input().split()))
    ABC = {tuple(map(int, input().split())) for _ in range(M)}

    dist = [[float('inf') for i in range(N + 1)] for j in range(N + 1)]
    for a, b, c in ABC:
        dist[a][b] = dist[b][a] = c
    for k in range(N + 1):
        for i in range(N + 1):
            for j in range(N + 1):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = float('inf')
    for r in itertools.permutations(RR):
        move = 0
        for i in range(R - 1):
            a = r[i]
            b = r[i+1]
            move += dist[a][b]
        ans = min(ans, move)

    print(ans)

main()


### FIXED CODE ###

import itertools

def main():
    N, M, R = map(int, input().split())
    RR = tuple(map(int, input().split()))
    ABC = {tuple(map(int, input().split())) for _ in range(M)}

    dist = [[float('inf')] * (N + 1) for j in range(N + 1)]
    for a, b, c in ABC:
        dist[a][b] = dist[b][a] = c
        dist[a][a] = dist[b][b] = 0
    for k in range(1, N + 1):
        for i in range(1, N + 1):
            for j in range(1, N + 1):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = float('inf')
    for r in itertools.permutations(RR):
        move = 0
        for i in range(R - 1):
            a = r[i]
            b = r[i+1]
            move += dist[a][b]
        ans = min(ans, move)

    print(ans)

main()
### BUGGY CODE ###

import numpy as np
from copy import deepcopy
def draft(A, K, N):
    A = np.array(A)
    for _ in range(1, K+1):# 2 * 10**5
        tmp = np.zeros(N+1, dtype=np.int64)
        for i in range(N):# 2 * 10**5
            L = max(0, i - A[i])
            R = min(N, i + A[i]+1)
            tmp[L] += 1
            tmp[R] -= 1
        A = np.cumsum(tmp)[:-1]
        if not np.count_nonzero(A < N) > 0:
            break
    for i in range(N):
        print(int(A[i]), end=" ")

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    draft(A, K, N)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def draft(A, K, N):
    for _ in range(1, K+1):# 2 * 10**5
        tmp = [0]*(N+1)
        for i in range(N):# 2 * 10**5
            L = max(0, i - A[i])
            R = min(N, i + A[i]+1)
            tmp[L] += 1
            tmp[R] -= 1
        f = True
        for i in range(N):
            tmp[i+1] += tmp[i]
            A[i] = tmp[i]
            if A[i] != N:
                f = False
        if f:
            break
    for i in range(N):
        print(A[i], end=" ")

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    draft(A, K, N)

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

S=input()
count=0
end=0
while "BW" in S:
    i=S.find("BW") + 1
    S=S.replace("BW","BB",1)
    count+=i-end
    end+=1
print(count)

### FIXED CODE ###

S=input()
count=0
def sigma(i):
    a=[b for b in range(0,i+1)]
    return sum(a)
place=0
flag=0
start=0
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i - start
        else:
            start+=1
ans=place-sigma(count-1)
print(ans)
### BUGGY CODE ###

N = int(input())
L = [int(i) for i in input().split()]
L.sort()

def bisecsearch(l,t,lo,hi):
  while lo < hi:
    mid = (lo+hi)//2
    if l[mid] < t:
      lo = mid + 1
    else:
      hi = mid
  return lo

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    k = bisecsearch(L,t,j+1,N)
    cnt += max(0,k-j-1)
print(cnt)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)
### BUGGY CODE ###

from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a.sort(key=lambda x:-x)
d = defaultdict(int)
for i in a:
    d[i] += 1
beki = [2**i for i in range(60,0,-1)]
ans = 0
for i in a:
    if d[i] == 0:
        continue
    for j in beki:
        if j <= i:
            break
        ni = j - i
        if ni == i:
            if d[i] >= 2:
                ans +=1
                d[i]-=2
                break
        elif d[ni] > 0:
            ans += 1
            d[ni]-=1
            d[i]-=1
            break
print(ans)

### FIXED CODE ###

from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a.sort(key=lambda x:-x)
d = defaultdict(int)
for i in a:
    d[i] += 1
beki = [2**i for i in range(32,0,-1)]
ans = 0
for i in a:
    if d[i] == 0:
        continue
    for j in beki:
        if j <= i:
            break
        ni = j - i
        if ni == i:
            if d[i] >= 2:
                ans +=1
                d[i]-=2
                break
        elif d[ni] > 0:
            ans += 1
            d[ni]-=1
            d[i]-=1
            break
print(ans)
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
A=[0]*N
for i in range(1,N+1):
	if S[i-1:i+1]=="AC":
		A[i]+=1
for i in range(Q):
	l,r=map(int,input().split())
	print(sum(A[l:r]))

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
A=[0]*N
for i in range(1,N+1):
	if S[i-1:i+1]=="AC":
		A[i]+=1
for i in range(1,N):
	A[i]=A[i]+A[i-1]
for i in range(Q):
	l,r=map(int,input().split())
	print(A[r-1]-A[l-1])
### BUGGY CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
for i in range(q):
    t = s[l[i][0]-1:l[i][1]]
    c = 0
    f = False
    for j in t:
        if f:
            if j=="C":
                c += 1
                f = False
            else:
                f = False
        if j=="A":
            f = True
    print(c)

### FIXED CODE ###

n, q = map(int,input().split())
s = input()
l = [[int(i) for i in input().split()] for i in range(q)]
c = [0 for i in range(n)]
cc = 0
f = False
for i in range(n):
    if f:
        f = False
        if s[i] == "C":
            cc += 1
    if s[i] == "A":
        f = True
    c[i] = cc
for i in range(q):
    print(c[l[i][1]-1]-c[l[i][0]-1])
### BUGGY CODE ###

"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()[::-1]

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for c in s:
        b = b + int(c) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10 % 2019

    for i in range(2019):
        ans += cnt[i] * (cnt[i] - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

s = input()[::-1]

sum_of_digits = 0

cnts = [0] * 2019

cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0

for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)
### BUGGY CODE ###

n = int(input())

slist = []
for h in range(n):
  slist.append(input())

newlist = []
word=[]
wordy = ""
for i in range(n):
  word = list(slist[i])
  word.sort()
  for jk in range(len(word)):
	  wordy = wordy+word.pop()
  newlist.append(wordy)
  wordy=""
new2list = sorted(newlist)

count= 0
for j in range(n-1):
  k = j+1
  while (new2list[j] == new2list[k]):
    count += 1
    k += 1
    if k == n:
      break

print(count)


### FIXED CODE ###

n = int(input())

slist = []
for h in range(n):
  slist.append(input())

newlist = []
word=[]
wordy = ""
for i in range(n):
  word = list(slist[i])
  word.sort()
  for jk in range(len(word)):
	  wordy = wordy+word.pop()
  newlist.append(wordy)
  wordy=""

resdic = {}
count = 0
for item in newlist:
  if not item in resdic:
    resdic[item] = 1
  else:
    count += resdic[item]
    resdic[item] += 1
    
print(count)
### BUGGY CODE ###

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

for i in range(n):
	cnt = 0
	c = []
	c = copy.copy(a)
	c.pop(i)
	iti = 0
	for j in range(len(c)):
		cnt += abs(c[j] - iti)
		iti = c[j]
	cnt += abs(c[-1])
	print (cnt)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0,0)
cnt = 0
for i in range(n+1):
	cnt += abs(a[i+1] - a[i])

for i in range(n):
	print (cnt + abs(a[i] - a[i+2]) - abs(a[i] -a[i+1]) - abs(a[i+1] - a[i+2]))
### BUGGY CODE ###

import math
import bisect
q = int(input())
lr = [list(map(int, input().split())) for i in range(q)]

def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

prime = set(eratosthenes(10**5))
like = []
for p in prime:
    if (p+1)//2 in prime:
        like.append(p)
like.sort()

for l, r in lr:
    st = bisect.bisect_left(like, l)
    en = bisect.bisect_left(like, r)

    print(en-st)

### FIXED CODE ###

import math
import bisect
import sys
input = sys.stdin.readline
q = int(input())

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

prime = set([i for i, f in enumerate(sieve_of_erastosthenes(10**5)) if f])
like = []
for p in prime:
    if (p+1)//2 in prime:
        like.append(p)
like.sort()

for i in range(q):
    l, r = map(int, input().split())
    st = bisect.bisect_left(like, l)
    en = bisect.bisect_right(like, r)

    print(en-st)
### BUGGY CODE ###

import heapq

def main():
    n, k, q = map(int, input().split())
    a = tuple(map(int, input().split()))

    m = float('inf')
    for y in sorted(set(a)):
        x = find_x(a, y, k, q)
        if x is not None:
            m = min(m, x - y)
    
    print(m)

def find_x(a, y, k, q):
    gs = groups(a, y)
    xs = []

    for g in gs:
        xs.extend(heapq.nsmallest(len(g) - k + 1, g))
    
    xss = heapq.nsmallest(q, xs)
    if len(xss) < q:
        return None
    
    return xss[-1]

def groups(a, m):
    g = []

    pos = 0
    while pos < len(a):
        i = pos
        while i < len(a) and a[i] < m:
            i += 1
        
        j = i
        while j < len(a) and a[j] >= m:
            j += 1
        
        if j > i:
            g.append(a[i:j])
        
        pos = j
    
    return g

main()

### FIXED CODE ###

import heapq

def main():
    n, k, q = map(int, input().split())
    a = tuple(map(int, input().split()))

    m = float('inf')
    for y in sorted(set(a)):
        x = find_x(a, y, k, q)
        if x is None:
            break
        m = min(m, x - y)
    
    print(m)

def find_x(a, y, k, q):
    gs = groups(a, y, k)
    xs = []

    for g in gs:
        xs.extend(heapq.nsmallest(len(g) - k + 1, g))
    
    xss = heapq.nsmallest(q, xs)
    if len(xss) < q:
        return None
    
    return xss[-1]

def groups(a, m, k):
    g = []

    pos = 0
    while pos < len(a):
        i = pos
        while i < len(a) and a[i] < m:
            i += 1
        
        j = i
        while j < len(a) and a[j] >= m:
            j += 1
        
        if j - i >= k:
            g.append(a[i:j])
        
        pos = j
    
    return g

main()
### BUGGY CODE ###

h, n = map(int, input().split())
a, b= [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

max_v = 10100
x = float("inf")

dp = [x] * max_v

dp[0] = 0
for i in range(1,max_v):
    for j in range(n):
        dp[i] = min(dp[i], dp[i - a[j]] + b[j])

ans = x
for i in range(max_v):
    if i >= h:
        ans = min(ans, dp[i])

print(ans)

### FIXED CODE ###

h, n = map(int, input().split())
a, b= [0] * n, [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

max_v = 10100
x = float("inf")

dp = [x] * max_v

dp[0] = 0
for i in range(1,max_v):
    for j in range(n):
        dp[i] = min(dp[i], dp[i - a[j]] + b[j])

ans = x
for i in range(max_v):
    if i >= h:
        ans = min(ans, dp[i])

print(ans)
### BUGGY CODE ###

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

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()
while True:
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)


### FIXED CODE ###

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

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()

i = N // K
N = N - K * i
while True:
    i = N // K
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n

for i in range(1,n):
    cost=[]
    for j in range(max(0,i-k), i):
        cost.append(dp[j] + abs(h[i]-h[j]))
    dp[i] = min(cost)
print(dp[n-1])


### FIXED CODE ###

def main():
    n,k=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[0]*n

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

if __name__ == "__main__":
    main()