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

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

memo = dict()
res = [-1]*(2*n)
for i,c in enumerate(a*2):
    if c in memo:
        res[memo[c]] = i+1
    memo[c] = i


res2 = [0]*(n)

def dfs(i):
    if res[i] < n:
        res2[i] = dfs(res[i])
    else:
        res2[i] = res[i]
    return res2[i]

for i in range(n): dfs(i)
#print(res)        
#print(res2)        


cycle = [0]
offset = 0
now = res2[0]-n

while now != 0:
    if now == n:
        offset += 1
        break
    else:
        cycle.append(now)
        now = res2[now]-n


#print(cycle,offset)

l = len(cycle)
k-=1
k %= (l+offset)

#print("k =",k)

if k != l: ans = p = cycle[k]
else: ans = p = n+1
while p <= n:
    ans = p
    p = res[p]
#    print(ans,p)

if ans >= n: exit()
else:
    s = []
    for i in range(ans,n):
        ai = str(a[i])
        if ai not in s:
            s.append(ai)
        else:
            while ai in s: s.pop()
    
print(" ".join(s))




### FIXED CODE ###

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

memo = dict()
res = [0]*(2*n)
for i,c in enumerate(a*2):
    if c in memo: res[memo[c]] = i+1
    memo[c] = i

#print(res)

res2 = res[:n]

for i in range(n-1,-1,-1):
    if res2[i] < n:
        res2[i] = res2[res2[i]]

cycle = [0]
offset = 0
now = res2[0]-n

while now != 0:
    if now == n:
        offset = 1
        break
    else:
        cycle.append(now)
        now = res2[now]-n

#print(res2)
#print(cycle,offset)

l = len(cycle)
k-=1
k %= (l+offset)

#print("k =",k)

if k != l: ans = cycle[k]
else: exit()
while res[ans] < n:
    ans = res[ans]

"""
if k != l: ans = p = cycle[k]
else: ans = p = n+1
while p <= n:
    ans = p
    p = res[p]
#    print(ans,p)
"""


if ans >= n: exit()
else:
    s = []
    ss = set()
    for i in range(ans,n):
        if a[i] in ss:
            while a[i] in ss:
                c = s.pop()
                ss.remove(c)
        else:
            s.append(a[i])
            ss.add(a[i])
    
print(" ".join(map(str,s)))
### BUGGY CODE ###

r,g,b,n = map(int,input().split())
count = 0
rr = n // r
gg = n // g
bb = n // b
l = sorted([[gg,g],[rr,r],[bb,b]])
for i in range(l[0][0]+1):
  for j in range(l[1][0]+1):
    if n >= i*l[0][1] + j*l[1][1] and (n - (i*l[0][1] + j*l[1][1])) %  l[2][1] == 0:
        count += 1
print(count)

### FIXED CODE ###

r,g,b,n = map(int,input().split())
count = 0
rr = n // r
for i in range(rr+1):
  for j in range((n-i*r)//g+1):
    tmp = n - (i*r + j*g)
    if tmp >= 0 and tmp %  b == 0:
        count += 1
print(count)
### BUGGY CODE ###

import collections
 
n=int(input())
s=[]
 
for i in range(n):
    s.append(input())
 
d=collections.Counter(s)
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
 
for i in range(len(max_k_list)):
    print(max_k_list[i])

### FIXED CODE ###

import collections

n=int(input())
s=[]

for i in range(n):
    s.append(input())

d=collections.Counter(s).most_common()

ans=[]
past=d[0][1]

for i,m in d:
    if past==m:
        ans.append(i)
        past=m
    else:
        break

ans.sort()
for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)

for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

res = [set() for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
  v, d, c = map(int, input().split())
  qd[i] = d
  qc[i] = c
  res[v].add(i)
#print(qc)

def clean():
  global res
  for i in range(1, N + 1):
    a = sorted(res[i], reverse = True)
    d = -1
    for j in range(len(a)):
      x = a[j]
      if qd[x] <= d: res[i].discard(x)
      d = max(d, qd[x])
clean()
for t in range(10):
  tres = [set() | s for s in res]
  for x in range(1, N + 1):
    for y in e[x]:
      for z in res[x]:
        if qd[z] > t: tres[y].add(z)
  res = tres
  #clean()
#print(res)

for r in res[1: ]:
  if len(r): print(qc[max(r)])
  else: print(0)


### FIXED CODE ###

import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
e = dd(list)

for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
mxd = 0
res = [[-1] * 11 for _ in range(N + 1)]
Q = int(input())
qd = [0] * Q
qc = [0] * Q
for i in range(Q):
  v, d, c = map(int, input().split())
  qd[i] = d
  qc[i] = c
  res[v][d] = i
  mxd = max(mxd, d)
#print(qc)

#print(mxd)
for t in range(mxd):
  tres = [x[: ] for x in res]
  for x in range(1, N + 1):
    for y in e[x]:
      for i in range(t + 1, 11):
        res[y][i] = max(res[y][i], tres[x][i])

#print(res)
for r in res[1: ]:
  x = -1
  for i in range(11):
    if r[i] != -1: x = max(x, r[i])
  if x == -1: print(0)
  else: print(qc[x])
### BUGGY CODE ###

import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)


### FIXED CODE ###

import itertools
from collections import deque

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
Q = deque([])
for i, j in itertools.product(range(H), range(W)):
    if A[i][j] == '#':
        Q += [[i, j, 0]]
while Q:
    i, j, d = Q.popleft()
    for ni, nj in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == '.':
            A[ni][nj] = '#'
            Q += [[ni, nj, d + 1]]
print(d)
### BUGGY CODE ###

h, w, m = map(int, input().split())
grid = [[0 for _ in range(w)] for _ in range(h)]
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    grid[hi][wi] = 1

rowsum = [0] * h
colsum = [0] * w
for i in range(h):
    for j in range(w):
        rowsum[i] += grid[i][j]
        colsum[j] += grid[i][j]

rowmax = max(rowsum)
rowindices = []
for i, v in enumerate(rowsum):
    if v == rowmax:
        rowindices.append(i)

colmax = max(colsum)
colindices = []
for i, v in enumerate(colsum):
    if v == colmax:
        colindices.append(i)

ans = 0
for ri in rowindices:
    for ci in colindices:
        ans = max(ans, rowmax + colmax - grid[ri][ci])

print(ans)

### FIXED CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())

rowsum = [0] * h
rowmax = 0
colsum = [0] * w
colmax = 0
targets = defaultdict(int)
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    rowsum[hi] += 1
    rowmax = max(rowmax, rowsum[hi])
    colsum[wi] += 1
    colmax = max(colmax, colsum[wi])
    targets[(hi, wi)] = 1

rowindices = []
for i, v in enumerate(rowsum):
    if v == rowmax:
        rowindices.append(i)

colindices = []
for i, v in enumerate(colsum):
    if v == colmax:
        colindices.append(i)

ans = rowmax + colmax - 1
for ri in rowindices:
    for ci in colindices:
        if targets[(ri, ci)]:
            continue
        print(rowmax + colmax)
        exit()

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

import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,x = na()
a = na()
dp = [i for i in a]
ans = sum(dp)

for i in range(1,n):
    for j in range(n):
        dp[(j+i)%n] = min(dp[(j+i)%n], a[j])
    ans = min(ans, sum(dp)+x*i)

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,x = na()
a = na()
dp = [i for i in a]
ans = sum(dp)

for i in range(1,n):
    for j in range(n):
        dp[(j+i)%n] = min(dp[(j+i)%n], a[j])
    ans = min(ans, sum(dp)+x*i)

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

import heapq
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])


que = [[0, 0]]
heapq.heapify(que)
mi = [10 ** 16] * (n + 2)
mi[0] = 0
used = [False]*(n+2)

while que:
    w, x = heapq.heappop(que)
    if x == n + 1:
        break
    if used[x]:
        continue
    used[x] = True
    for i in range(n + 2):
        if used[i]:
            continue
        cost = dif(xy[x], xy[i])
        if w + cost < mi[i]:
            mi[i] = w + cost
            heapq.heappush(que, [w + cost, i])
print(mi[-1])


### FIXED CODE ###

import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
n = int(input())

xy = [[x1, y1, 0]]
for _ in range(n):
    xy.append([int(i) for i in input().split()])
xy.append([x2, y2, 0])


def dif(x, y):
    return max(0, math.sqrt((x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2) - x[2] - y[2])




q = set([i for i in range(n + 2)])
mi = [10 ** 16] * (n + 2)
mi[0] = 0

while q:
    u = -1
    mm = 10**16
    for i in q:
        if mm > mi[i]:
            mm = mi[i]
            u = i
    
    q.remove(u)
    for i in q:
        mi[i] = min(mi[i], mi[u] + dif(xy[i], xy[u]))

print(mi[-1])
### BUGGY CODE ###

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

count = 0
while True:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] /= 2
        else:
            print(count)
            break
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
count = 0
while True:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i]//2
        else:
            print(count)
            exit()
    count += 1
print(count)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(0, N):
    print(A.index(i+1)+1,end=" ")

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(0, N):
    B[A[i]-1]=i+1
for i in range(0, N):
    print(B[i],end=" ")
### BUGGY CODE ###

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

for i in range(n):
    if a[i]==min(a[0:i+1]) :
        
        ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
mini=a[0]
for i in range(n):
    if mini>=a[i]:ans+=1
    mini=min(a[i],mini)
print(ans)
### BUGGY CODE ###

import numpy as np
import sys

n = int(input())
a = list(map(int, input().split()))
ans = 1;
for i in range(n):
  ans = ans * a[i]
  if ans > 10**18:
    ans = -1
if ans < 0:
  print(-1)
else:
  print(ans)
  

### FIXED CODE ###

over = 10**18

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

for i in range(n):
  if a[i] == 0:
    ans = 0
if not ans == 0:
  for i in range(n):
    ans = ans * a[i]
    if ans > over:
      ans = -1
      break
if ans < 0:
  print(-1)
else:
  print(ans)
### BUGGY CODE ###

from collections import Counter
import sys
from functools import lru_cache
from functools import reduce
from operator import mul
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


@lru_cache(None)
def cmb(n: int, r: int):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    _ = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    cnts = Counter(A)
    for a in A:
        tmp = 0
        cnts[a] -= 1
        for k, v in cnts.items():
            tmp += cmb(v, 2)
        print(tmp)
        cnts[a] += 1
    return


if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter
import sys
from functools import lru_cache
from functools import reduce
from operator import mul
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


@lru_cache(None)
def cmb(n: int, r: int):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def main():
    _ = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    cnts = Counter(A)
    d = {}
    _sum = 0
    for k, v in cnts.items():
        d[k] = (cmb(v, 2), cmb(v - 1, 2))
        _sum += d[k][0]
    for a in A:
        dif = d[a][0] - d[a][1]
        print(_sum - dif)
    return


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

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

def ans() :
    n, m  = map(int, input().split())
    a = list(map(int, input().split()))

    for i in range(m):
        j = a.index(max(a))
        a[j] = a[j] >> 1

    print(sum(a))

if __name__ == '__main__':
    ans()

### FIXED CODE ###

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

import heapq

def ans() :
    n, m  = map(int, input().split())
    aa = map(int, input().split())
    a = []
    for i in aa:
        heapq.heappush(a, int(i) * (-1))

    for i in range(m):
        head = heapq.heappop(a)
        head = (-1) * (-head // 2)
        heapq.heappush(a, head)

    print(-sum(a))

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

A, B = map(int, input().split())
ans = A
for i in range(A + 1, B + 1):
  ans = ans ^ i
print(ans)

### FIXED CODE ###

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

def xor(n):
  if n % 2 == 0:
    if int(n / 2) % 2 == 0:
      return n
    else:
      return n ^ 1
  else:
    if int((n + 1) / 2) % 2 == 0:
      return 0
    else:
      return 1

if A == B:
  print(A)
else:
  print(xor(A - 1) ^ xor(B))
### BUGGY CODE ###

import sys
inputs = sys.stdin.readline
N, Q= map(int,inputs().split())
V = [None]*N
E = []
for n in range(N):
	V[n] = list(map(int,inputs().split()))
	V[n][0] -= V[n][2]
	V[n][1] -= V[n][2]
	E.append([V[n][0],1,V[n][2]])
	E.append([V[n][1],-1,V[n][2]])
E.sort(key = lambda x:x[0])
d = int(inputs())
mini = 1000000001
kouho = [1000000001]
q = 0
flag = False
for e in E:
	while(e[0] > d):
		if kouho[0] < 1000000001:
			print(kouho[0])
		else:
			print(-1)
		if q < Q-1:
			q = q + 1
			d = int(inputs())
		else:
			flag = True
			q = q + 1
			break
	if flag == True:
		break
	if  e[1] == 1:
		for k in range(len(kouho)):
			if e[2] < kouho[k]:
				kouho.insert(k,e[2])
				break
	elif e[1] == -1:
		kouho.remove(e[2])
for t in [None]*(Q-q):
	print(-1)

### FIXED CODE ###

import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a.sort(reverse=True)
    a[0] = a[0] >> 1
print(sum(a))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import heapq as hp
n, m = map(int, input().split())
a = list(map(int, input().split()))
items = []
for ai in a:
    hp.heappush(items, (-ai, ai))

for i in range(m):
    item = hp.heappop(items)
    nv = item[1] >> 1
    hp.heappush(items, (-nv, nv))
count = 0
while len(items) > 0:
    v = hp.heappop(items)
    count += v[1]
print(count)
### BUGGY CODE ###

import math

n = int(input())

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num
ans = 0

for i in range(1,n+1):
    ans += i * search_divisor_num_1(i)

print(ans)

### FIXED CODE ###

n = int(input())
ans  = 0
for i in range(1,n+1):
    ans += (i + i*(n//i))*(n//i)/2

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

num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
words_oc = set(words)
res = 0
for i in words_oc:
    c = 0
    for j in words:
        if i == j:
            c += 1
    res += (c**2 - c)//2
print(res)

### FIXED CODE ###

from collections import Counter

num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
x = Counter(words)
res = 0
for c in x.values():
    res += (c**2 - c)//2
print(res)
### BUGGY CODE ###

n,q = map(int, input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
tmp = []
for i in range(1,n+1):
  tmp.append(s[:i].count('AC'))

for i in range(q):
  print(tmp[lr[i][1]-1]-tmp[lr[i][0]-1])

### FIXED CODE ###

n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])
### BUGGY CODE ###

s = list(input())
n = len(s)
a_count = 0
ans = 0
i = 0
while i < n-2:
    min(i,0)
    if s[i:i+3] == ['A','B','C']:
        ans +=  1
        s[i:i+3] = ['B','C','A']
        i -= 2
    i += 1
print(ans)

### FIXED CODE ###

s = input()
n = len(s)
s = list(s.replace('BC','D'))
a_count = 0
ans = 0
i = 0
while i < len(s) - 1 :
    if s[i:i+2] == ['A','D']:
        ans += a_count + 1
        s[i+1] = 'A'
        s[i] = 'D'
    else:
        if s[i] == 'A':
            a_count += 1
        else:
            a_count = 0
    i += 1
print(ans)
### BUGGY CODE ###

S = input()
T = input()

dp = [[''] * (len(T)+1) for i in range(len(S)+1)]
for i, s in enumerate(S):
  for j, t in enumerate(T):
    if s == t:
      dp[i+1][j+1] = dp[i][j] + s
    else:
      a1, a2 = dp[i][j+1], dp[i+1][j]
      if len(a1) > len(a2):
        dp[i+1][j+1] = a1
      else:
        dp[i+1][j+1] = a2

print(dp[-1][-1])

### FIXED CODE ###

S = input()
T = input()

dp = [[0] * (len(T)+1) for i in range(len(S)+1)]
for i, s in enumerate(S, 1):
  for j, t in enumerate(T, 1):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = []
while i > 0 and j > 0:
  if dp[i][j] == dp[i][j-1]:
    j -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    ans.append(S[i-1])
    i -= 1
    j -= 1

print(''.join(ans[::-1]))
### BUGGY CODE ###

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


K = int(input())
abc_list = []


for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      abc_list.append([a, b, c])

gcds = [gcd_list(x) for x in abc_list]

print(sum(gcds))

### FIXED CODE ###

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

K = int(input())
gcd = 0

for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      gcd += (gcd_list([a, b, c]))

print(gcd)
### BUGGY CODE ###

n,k=map(int,input().split())
dp=[10**4*n]*n
l=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
  dp[i]=min(dp[i-j]+abs(l[i-j]-l[i]) for j in range(1,min(i,k)+1))
print(dp[-1])

### FIXED CODE ###

n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])
### BUGGY CODE ###

s = input()
j = [str(x) for x in list(str(s))]
t = input()
k = [str(x) for x in list(str(t))]

ar = []

for i in range(len(j)):
    if j[i] != k[i]:
        if j[i] in ar:
            break
        """if j[i] not in ar:
            ar.append(j[i])"""
        com = j[i]
        j[i] = k[i]
        if j[i] not in ar:
            ar.append(j[i])
        for h in range(len(j)):
            if j[h] == com:
                j[h] = k[i]
            elif j[h] == k[i] and h != i:
                j[h] = com

if j == k:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input()
j = [str(x) for x in list(str(s))]
t = input()
k = [str(x) for x in list(str(t))]

ar = []

for i in range(len(j)):
    if j[i] != k[i]:
        if j[i] in ar:
            break
        """if j[i] not in ar:
            ar.append(j[i])"""
        com = j[i]
        j[i] = k[i]
        if j[i] not in ar:
            ar.append(j[i])
        for h in range(len(j)):
            if j[h] == com:
                j[h] = k[i]
            elif j[h] == k[i] and h != i:
                j[h] = com
        for g in range(i + 1):
            if j[g] != k[g]:
                break
        else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
            continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
        break  # 外側のforを抜ける

if j == k:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

class Transporter():
    def __init__(self, cap_out, temp=0):
        self.temp_num = temp
        self.cap_out = cap_out

    def transport(self):
        if self.temp_num < self.cap_out:
            num = self.temp_num
            self.temp_num = 0
            return num
        else:
            self.temp_num -= self.cap_out
            return self.cap_out

A_ = Transporter(A, temp=N)
B_ = Transporter(B)
C_ = Transporter(C)
D_ = Transporter(D)
E_ = Transporter(E)

time = 0
while (A_.temp_num!=0):
    time += 1
    a=A_.transport()
    b=B_.transport()
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    B_.temp_num+=a
    C_.temp_num+=b
    D_.temp_num+=c
    E_.temp_num+=d

while (B_.temp_num!=0):
    time += 1
    b=B_.transport()
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    C_.temp_num+=b
    D_.temp_num+=c
    E_.temp_num+=d

while (C_.temp_num!=0):
    time += 1
    c=C_.transport()
    d=D_.transport()
    e=E_.transport()
    D_.temp_num+=c
    E_.temp_num+=d

while (D_.temp_num!=0):
    time += 1
    d=D_.transport()
    e=E_.transport()
    E_.temp_num+=d

while (E_.temp_num!=0):
    time += 1
    E_.transport()
print(time)


### FIXED CODE ###

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min_city = min([A, B, C, D, E])

print(4+(N+min_city-1)//min_city)