Harryxun/stf_run huggingface dataset:
import numpy as np
n, m = map(int, input().split())
r = [[] for i in range(m)]
for i in range(m):
    f, s = map(int, input().split())
    r[f-1].append(s - 1)
    r[s-1].append(f - 1)
ans = []
def dfs(now, visited = []):
    try:
        global ans
        if len(visited) == n:
            ans.append([visited])
            return
        for j in r[now]:
            if j not in visited:
                dfs(j, visited + [j])
    except:
        return
dfs(0, [0])
print(len(ans))

### FIXED CODE ###

import numpy as np
n, m = map(int, input().split())
if m == 0:
    print(0)
    exit()
r = [[] for i in range(n)]
for i in range(m):
    f, s = map(int, input().split())
    r[f-1].append(s - 1)
    r[s-1].append(f - 1)
ans = []
def dfs(now, visited = []):
    global ans
    if len(visited) == n:
        ans.append([visited])
        return
    for j in r[now]:
        if j not in visited:
            dfs(j, visited + [j])
dfs(0, [0])
print(len(ans))
import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N)-1)
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            if a > max(useList):
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, int(N[i-1]))])
                result += str(useList[0])*(len(N)-i)
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)

### FIXED CODE ###

import bisect

N, K = input().split()
dList = [int(x) for x in input().split()]
useList = [0,1,2,3,4,5,6,7,8,9]
for d in dList:
    useList.remove(d)
result = ''
if int(N[0]) > max(useList):
    # 桁上げが必要
    if useList[0] != 0:
        result += str(useList[0])
    else:
        result += str(useList[1])
    result += str(useList[0])*(len(N))
else:
    for i in range(len(N)):
        a = int(N[i])
        if a in useList:
            result += N[i]
            continue
        else:
            count = 0
            if a > max(useList):
                while not max(useList) > int(result[-1]):
                    count += 1
                    result = result[:-1]
                    if result == '':
                        break
                if result == '':
                    if useList[0] != 0:
                        result += str(useList[0])
                    else:
                        result += str(useList[1])
                    result += str(useList[0])*(len(N))
                    break
                count += 1
                sect = int(result[-1])
                result = result[:-1]
                result += str(useList[bisect.bisect_right(useList, sect)])
                result += str(useList[0])*(len(N)-len(result))
            else:
                result += str(useList[bisect.bisect_right(useList, a)])
                result += str(useList[0])*(len(N)-i-1)
            break
print(result)
from sys import stdin


def prime_factorization(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


def num_of_prime_factorization(n):
    i = 2
    table = []
    while i * i <= n:
        loop_num = 0
        while n % i == 0:
            n //= i
            loop_num += 1
            if n % i != 0:
                table.append(loop_num)
        i += 1
    return table


def factorial(n):
    if n > 1:
        return n * factorial(n - 1)
    else:
        return 1


N, M = [int(i) for i in stdin.readline().rstrip().split()]

lst = num_of_prime_factorization(M)
ans = 1

for b in lst:
    ans *= factorial(b + N - 1) // (factorial(b) * factorial(N - 1))

print(ans)

### FIXED CODE ###

from sys import stdin


def num_of_prime_factorization(n):
    i = 2
    table = []
    while i * i <= n:
        loop_num = 0
        while n % i == 0:
            n //= i
            loop_num += 1
            if n % i != 0:
                table.append(loop_num)
        i += 1
    if n > 1:
        table.append(1)
    return table


def comb(n, r):
    a = 1
    for num in range(n, n - r, -1):
        a *= num

    b = 1
    for num in range(r, 0, -1):
        b *= num

    return a // b


N, M = [int(i) for i in stdin.readline().rstrip().split()]

lst = num_of_prime_factorization(M)
ans = 1

for b in lst:
    ans *= comb(b + N - 1, b)

print(ans % (10**9 + 7))
from sys import stdin
input = stdin.readline

import sys

A, B, C, D= map(int, input().split())

if C - B <= 0:
    print("yes")
    sys.exit()
elif A - D <= 0:
    print("No")
    sys.exit()

aoki = C - B
taka = A - D

for i in range(1000):
    aoki -= B
    if aoki <= 0:
        print("Yes")
        break
    
    taka -= D
    if taka <= 0:
        print("No")
        break
    


### FIXED CODE ###

from sys import stdin
input = stdin.readline

S,W = map(int, input().split())

if W >= S :
    print("unsafe")
else:
    print("safe")
import itertools
import sys

def findRoot(uf,value):
  if uf[value]==None:
    return value
  else:
#経路圧縮
    uf[value]=findRoot(uf,uf[value])
    return uf[value]


sys.setrecursionlimit(10000)
n,m=[int(x) for x in input().split(' ')]

uf=[None]*n
b=[]
s=[1]*n
r=[]

for x in range(0,m):
  b.append([int(x)-1 for x in input().split(' ')])

for x in b[::-1]:
  r1=findRoot(uf,x[0])
  r2=findRoot(uf,x[1])

  if r1==r2:
    r.append(0)
  else:
    r.append(s[r1]*s[r2])
#木の結合
    uf[r2]=r1
    s[r1]+=s[r2]

for x in itertools.accumulate(r[::-1]):
  print(x)

### FIXED CODE ###

import itertools
import sys

def findRoot(uf,value):
  if uf[value]==None:
    return value
  else:
#経路圧縮
    uf[value]=findRoot(uf,uf[value])
    return uf[value]


sys.setrecursionlimit(50000)
n,m=[int(x) for x in input().split(' ')]

uf=[None]*n
b=[]
s=[1]*n
r=[]

for x in range(0,m):
  b.append([int(x)-1 for x in input().split(' ')])

for x in b[::-1]:
  r1=findRoot(uf,x[0])
  r2=findRoot(uf,x[1])

  if r1==r2:
    r.append(0)
  else:
    r.append(s[r1]*s[r2])
#木の結合
    uf[r2]=r1
    s[r1]+=s[r2]

for x in itertools.accumulate(r[::-1]):
  print(x)
n = int(input())
a = list(map(int,input().split()))

b = [0] * max(a)
d = 'YES'

for i in range(n):
  b[a[i]-1] += 1

if max(b) > 1:
  d = 'NO'

print(d)

### FIXED CODE ###

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

b = set(a)

if len(a) == len(b):
  print('YES')
else:
  print('NO')
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
ti, ai = list(map(int, input().split()))
vp = ti + ai
tp = ti
ap = ai
for i in range(1,n):
    ti, ai = list(map(int, input().split()))
    ni = math.ceil(vp/(ti+ai))
    while ni*ti < tp:
        ni += 1
    while ni*ai < ap:
        ni += 1
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 14:44:47 2018
ABC046C
@author: maezawa
"""
import math
n = int(input())
tp = 1
ap = 1
for i in range(n):
    ti, ai = list(map(int, input().split()))
    #nit = math.ceil(tp/ti)
    #nia = math.ceil(ap/ai)
    nit = -tp//ti
    nia = -ap//ai
    ni = max(-nit, -nia)
    vi = ni*(ti+ai)
    #print(ni, vi)
    tp = ni*ti
    ap = ni*ai

print(vi)
cond = raw_input.split()
a = cond[0]
b = cond[1]

print a*2 + b*2

### FIXED CODE ###

cond = map(int, raw_input().split())
a = cond[0]
b = cond[1]

print (a*b),
print (a*2 + b*2)
A, B, N = list(map(int,input().split()))

def f(x):
    return math.floor(A * x / B) - A * math.floor(x / B)

if B - 1 <= N:
    ans = f(B - 1)
else:
    ans = f(N)
print(ans)

### FIXED CODE ###

import math

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

def f(x):
    return math.floor(A * x / B) - A * math.floor(x / B)

if B - 1 <= N:
    ans = f(B - 1)
else:
    ans = f(N)
print(ans)
import sys
import io
import re
import math
start = time.clock()
i = [0]*255
#n = raw_input()
for x in sys.stdin.read().lower:
    i[ord(x)]+=1
for y in xrange(ord('a'), ord('z')+1):
    print chr(y)+ ' : ' +i[y]

### FIXED CODE ###

import time
import sys
import io
import re
import math
#start = time.clock()
i = [0]*127
#n = raw_input()
for x in sys.stdin.read().lower():
    i[ord(x)]+=1
for y in range(ord('a'), ord('z')+1):
    print chr(y)+ ' : ' + str(i[y])
n = input()
a = int(n[0:2])
b = int(n[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12 and b > 12:
	print('MMYY')
elif 1 <= b <= 12 and a > 12:
	print('YYMM')
else:
print('NA')


### FIXED CODE ###

n = input()
a = int(n[:2])
b = int(n[2:])
if 1 <= a <= 12 and 1 <= b <= 12:
	print('AMBIGUOUS')
elif 1 <= a <= 12:
	print('MMYY')
elif 1 <= b <= 12:
	print('YYMM')
else:
	print('NA')
n, m = [int(x) for x in input().split()]

s = [0]*(n+1)
d = [0]*(n+1)

for i in range(m):
	a, b = [int(x) for x in input().split()]
	if a == 1:
		s[b] = 1
	elif b == n:
		d[a] = 1

for i in range(1,m+1):
	if s[i] == 1 and d[i] == 1:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')


### FIXED CODE ###

n, m = [int(x) for x in input().split()]

s = [0]*(n+1)
d = [0]*(n+1)

for i in range(m):
	a, b = [int(x) for x in input().split()]
	if a == 1:
		s[b] = 1
		if d[b] == 1:
			print('POSSIBLE')
			break
	elif b == n:
		d[a] = 1
		if s[a] == 1:
			print('POSSIBLE')
			break
else:
	print('IMPOSSIBLE')
N = int(input())

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

dp = [0]*(N+1)
dp[2] = abs(H[0] - H[1])
if len(H) > 2:
    cnt = 3
    while dp[N] == 0:
        dp[cnt] = min((dp[cnt-1] + abs(H[cnt-1] - H[cnt-2])), dp[cnt-2] + abs(H[cnt-1] - H[cnt-3]))
        cnt += 1
else:
    dp[N] = abs(H[0] - H[1])

print(dp[N])


### FIXED CODE ###

N = int(input())
H = tuple(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])
if N > 2:
    for i in range(2, N):
        dp[i] = min(dp[i-2] + abs(H[i]-H[i-2]), dp[i-1] + abs(H[i]-H[i-1]))
else:
    print(dp[-1])
    exit()

print(dp[-1])
n = input().split()
a = 0
for i in n:
  if i = "+"
    a+=1
  else
    a-=1
print(a)

### FIXED CODE ###

n = input()
a = 0
for i in n:
  if i == "+":
    a+=1
  else:
    a-=1
print(a)
import sys

sys.setrecursionlimit(2000)

tmp=input().split(" ")
n = int(tmp[0])
m = int(tmp[1])

node_groups = [ i for i in range(n)]
group_sizes = [ 1 for _ in range(n)]

edges = []
for i in range(m):
    tmp=input().split(" ")
    edges.append([int(tmp[0])-1, int(tmp[1])-1])

hubensa_list = [0] * (m + 1)
hubensa_list[m] = n*(n-1)//2

def root(i):
    if node_groups[i] == i:
        return i
    else:
        node_groups[i] = root(node_groups[i])
        return node_groups[i]

def same(a, b):
    return root(a) == root(b)

def size(i):
    return group_sizes[root(i)]

def unite(a, b):
    a = root(a)
    b = root(b)

    if a == b:
        return
    
    group_sizes[a] += size(b)
    node_groups[b] = a


for i in range(m-1, 0, -1):
    edge = edges[i]
    print("node_groups: ", node_groups)
    node_1 = edge[0]
    node_2 = edge[1]

    root_1 = root(node_1)
    root_2 = root(node_2)
    if root_1 == root_2:
        hubensa_list[i] = hubensa_list[i+1]
        continue

    # 不便さをだす
    hubensa_list[i] = hubensa_list[i+1] - (size(root_1) * size(root_2))

    unite(root_1, root_2)

print("node_groups: ", node_groups)


for i in range(1, m+1):
    print(hubensa_list[i])

### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

tmp=input().split(" ")
n = int(tmp[0])
m = int(tmp[1])

node_groups = [ i for i in range(n)]
group_sizes = [ 1 for _ in range(n)]

edges = []
for i in range(m):
    tmp=input().split(" ")
    edges.append([int(tmp[0])-1, int(tmp[1])-1])

hubensa_list = [0] * (m + 1)
hubensa_list[m] = n*(n-1)//2

def root(i):
    if node_groups[i] == i:
        #print(i, "is root.")
        return i
    else:
        #_1 = node_groups[i]
        node_groups[i] = root(node_groups[i])
        #_2 = node_groups[i]
        #print ("root: ", _1, _2)
        return node_groups[i]

def same(a, b):
    return root(a) == root(b)

def size(i):
    return group_sizes[root(i)]

def unite(a, b):
    a = root(a)
    b = root(b)

    if a == b:
        return
    
    group_sizes[a] += size(b)
    node_groups[b] = a


for i in range(m-1, -1, -1):
    edge = edges[i]
    # print("edge: ",edge)
    #print("node_groups: ", node_groups)
    node_1 = edge[0]
    node_2 = edge[1]

    root_1 = root(node_1)
    root_2 = root(node_2)
    if root_1 == root_2:
        hubensa_list[i] = hubensa_list[i+1]
        continue

    # 不便さをだす
    hubensa_list[i] = hubensa_list[i+1] - (size(root_1) * size(root_2))

    unite(root_1, root_2)

#print("node_groups: ", node_groups)


for i in range(1, m+1):
    print(hubensa_list[i])
import fractions
from functools import reduce
import math
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
List=list(map(int,input().split()))
aa = int(lcm_list(List)/2)
cnt = 0
a = List[0]
while a%2 == 0:
  cnt+=1
  a = int(a/2)
out = 0
if cnt == 0:
  out = 1
  cnt = 1
for i in range(len(List)):
  if List[i] % (2**cnt) > 0:
    out = 1
  if List[i] % (2**(cnt+1)) == 0:
    out = 1

if out == 1:
  print(0)
else:
  print(int(math.ceil((M / aa)) // 2))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))
def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
  return (x * y) // gcd(x, y)
l = A[0]
for a in A[1:]:
  l = lcm(l, a)
ans = (M // l + 1) // 2
for a in A[1:]:
  if (l // a) % 2 == 0:
    ans = 0
    break
print(ans)
N = int(input())
l = input()
arr = []
for i in range(N):
    arr.append(l[i])

c = 0
left = 0
right = N-1
while True:
    while True:
        if arr[left] == 'R':
            left += 1
        else:
            break
    while True:
        if arr[right] == 'W':
            right -= 1
        else:
            break
    arr[left] = 'R'
    arr[right] = 'W'
    if left >= right:
        break
    else:
        c += 1

print(c)


### FIXED CODE ###

N = int(input())
l = input()
arr = []
for i in range(N):
    arr.append(l[i])

c = 0
left = 0
right = N-1

T = False
for i in arr:
    if i == 'R':
        T = True
if T == False:
    print(c)
else:
    T = False
    for i in arr:
        if i == 'W':
            T = True
    if T == False:
        print(c)
    else:
        while True:
            while True:
                if arr[left] == 'R':
                    left += 1
                else:
                    break
            while True:
                if arr[right] == 'W':
                    right -= 1
                else:
                    break
            arr[left] = 'R'
            arr[right] = 'W'
            if left >= right:
                break
            else:
                c += 1
        print(c)
import sys
input = sys.stdin.readline
A, B, K = [int(x) for x in input().split()]
import numpy as np
x = np.arange(A, B + 1)
left = x[:K]
right = x[::-1][:K]
ans = []
for i in left:
    if i not in ans:
        ans.append(i)
for j in right:
    if j not in ans:
        ans.append(j)
ans.sort()
for k in ans:
    print(k)

### FIXED CODE ###

import sys
input = sys.stdin.readline
A, B, K = [int(x) for x in input().rstrip().split()]
left = [int(x) for x in range(A, A+K)]
right = [int(x) for x in range(B, B-K, -1)]
ans = []
for i in left:
    if i not in ans and i <= B:
        ans.append(i)
for j in right:
    if j not in ans and j >= A:
        ans.append(j)
ans.sort()
for k in ans:
    print(k)
n = int(input())
h = [int (i) for i in input().split()]
ans=0

l=[]

for i in range(1,n):
	if h[i-1] >= h[i]:

		ans+=1

		if i==n-1:
			l.append(ans)

	else:

		l.append(ans)

		ans=0

print(max(l))


### FIXED CODE ###

n = int(input())
h = [int (i) for i in input().split()]
ans=0

l=[]

if n==1:
	l.append(ans)

else:
	for i in range(1,n):
		if h[i-1] >= h[i]:

			ans+=1

			if i==n-1:
				l.append(ans)

		else:

			l.append(ans)

			ans=0

print(max(l))
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1)
    ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    # print(R, KC, ans)
    print((ans*KC) % m)


### FIXED CODE ###

import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1) // math.factorial(K-i)
    if R < 0:
        ans = 0
    else:
        ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    print((ans*KC) % m)
N, K = input().split(" ")
H = list(map(int, input().split()))
H.sort()
K = int(K)

if K >= N:
	print(0)
elif: K == 0:
    print(sum(H))
else:
	print(sum(H[:-K]))

### FIXED CODE ###

N, K = input().split(" ")
H = list(map(int, input().split()))
H.sort()
K = int(K)

if K >= int(N):
	print(0)
elif K == 0:
	print(sum(H))
else:
	print(sum(H[:-K]))
N,M=map(int,input().split(' '))
H=map(int,input().split(' '))

data={{0 for in range(N)} for n in range(N)}

for m in range(M):
  

### FIXED CODE ###

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

data=[]
for n in range(N):
  data.append(H[n]-1)
    
for m in range(M):
  a,b=map(int,input().split(' '))
  data[a-1]=max(data[a-1],H[b-1])
  data[b-1]=max(data[b-1],H[a-1])
  
ans=0
for n in range(N):
  if H[n-1]-1==data[n-1]:
    ans+=1
print(ans)
import math
from functools import reduce

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


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


# print(gcd_list(A))

max_A = max(A)
# エラトステネスの篩により素数を高速で求める
# そのかんにある数値がふるい落とされたその素数をメモしておく

D = [0] * (max_A + 1)
primes = list(range(2, max_A + 1))
prime = []
for i in range(max_A):
    if len(primes) == 0:
        break
    first = primes[0]
    prime.append(first)
    new_prime = []
    for j in range(len(primes)):
        if primes[j] % first == 0:
            D[primes[j]] = first
            continue
        else:
            new_prime.append(primes[j])

    primes = new_prime

# print(prime)
# print(D)

pairwise = True
check = [0] * (max_A + 1)
new_A = A[:]
for i in range(N):
    min_prime = D[new_A[i]]
    check[min_prime] += 1
    while True:
        new_A[i] //= min_prime
        if new_A[i] == 1:
            break

    if max(check) > 1:
        pairwise = False
        break

if pairwise:
    print('pairwise coprime')
else:
    if gcd_list(A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')


### FIXED CODE ###

import math
from functools import reduce
from collections import deque

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


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


max_A = max(A)

if max_A == 1:
    print('pairwise coprime')
    exit()
# エラトステネスの篩により素数を高速で求める
# そのかんにある数値がふるい落とされたその素数をメモしておく

D = [0] * (max_A + 1)
is_prime = [True] * (max_A + 1)
is_prime[0] = False
is_prime[1] = False
prime = deque()
for i in range(2, int(max_A ** 0.5) + 1):
    if not is_prime[i]:
        continue
    for j in range(i * 2, max_A + 1, i):
        is_prime[j] = False
        D[j] = i

for i in range(len(is_prime)):
    if is_prime[i]:
        D[i] = i

pairwise = True
check = [0] * (max_A + 1)
new_A = A[:]
for i in range(N):
    min_prime = D[new_A[i]]
    while True:
        if D[min_prime] == 0:
            break

        check[D[min_prime]] += 1
        while new_A[i] % min_prime == 0:
            new_A[i] //= min_prime

        min_prime = new_A[i]

        # print(check)


# print(D)
# print(check)

if max(check) > 1:
    pairwise = False
# print(check)
if pairwise:
    print('pairwise coprime')
else:
    if gcd_list(A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')
h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]

def otoshidama(a,b):
	ok_flag = 0
	money = 0
	for i in range(N+1):
  		for j in range(N+1-i):
      		money = 10000*i + 5000*j + 1000*(N-i-j)
      		if money == Y:
        		print(i,j,N-i-j)
        		ok_flag = 1
        		return
      		money = 0 
	if ok_flag == 0:
  		print(-1 -1 -1)
  
otoshidama(N,Y)

### FIXED CODE ###

h = [int(s) for s in input().split()]
N = h[0]
Y = h[1]

def otoshidama(N,Y):
	ok_flag = 0
	money = 0
	for i in range(N+1):
		for j in range(N+1-i):
			money = 10000*i + 5000*j + 1000*(N-i-j)
			if money == Y:
				print(i,j,N-i-j)
				ok_flag = 1
				return
			money = 0
		money = 0
	if ok_flag == 0:
		print(-1,-1,-1)
  
otoshidama(N,Y)
oo = 1000000000 + 5

def main():
    n, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    
    dp = [oo for _ in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(i + 1, i + k + 1):
            if j < n:
                dp[j] = min(dp[j], dp[i] + fabs(a[i] - a[j]))
                
    print(int(dp[n - 1]))

main()

### FIXED CODE ###

def main():
  import sys
  input = sys.stdin.readline
  n, k = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [1000000000] * n
  dp[0] = 0
  for i in range(1, n):
    for j in range(max(0, i - k), i):
      dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]))
  print(dp[-1])
main()
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, dp[i] + dp[i | b])
        i = (i - 1) & c
    dp[b] = nlargest(2, dp[0] + dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


### FIXED CODE ###

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)
while True:
    m=input().split()
    h=int(m[0])
    w=int(m[1])
    if a==0&b==0:
      break
    for i in range(h):
       print("#"*w)
    print()
    


### FIXED CODE ###

while True:
    v=input().split()
    a=int(v[0])
    b=int(v[1])
    if a==0 and b==0:
       break
    for i in range (a):
        print('#'*b)
    print()
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
for i range(m):
    a, b = map(int, input().split())
    l.append([a, b])

ll = [0]*n

for j in l:
    if h[j[0] - 1] > h[j[1] - 1]:
        ll[j[1] - 1] += 1
    elif h[j[0] - 1] > h[j[1] - 1]:
        ll[j[1] - 1] += 1
        ll[j[0] - 1] += 1
    else:
        ll[j[0] - 1] += 1

ans = 0

for k in ll:
    if k == 0:
        ans += 1
    else:
        ans += 0
    
print(ans)

### FIXED CODE ###

import copy

n, m = map(int, input().split())
h = list(map(int, input().split()))
l = []
for i in range(m):
    a, b = map(int, input().split())
    l.append([a, b])

ll = [0]*n

for j in l:
    if h[j[0] - 1] > h[j[1] - 1]:
        ll[j[1] - 1] += 1
    elif h[j[0] - 1] == h[j[1] - 1]:
        ll[j[1] - 1] += 1
        ll[j[0] - 1] += 1
    else:
        ll[j[0] - 1] += 1

ans = 0

for k in ll:
    if k == 0:
        ans += 1
    else:
        ans += 0
    
print(ans)