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

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

import fractions
from functools import reduce

def gcd_list(numbers):
    return int(reduce(fractions.gcd, numbers))

f1 = gcd_list(a)
b = [int(_a / f1) for _a in a]

f2_list = []
for i in range(len(b)):
    tmp = b[i]
    b.pop(i)
    f2_list.append(gcd_list(b))
    b.insert(i, tmp)

print(f1 * max(f2_list))


### FIXED CODE ###

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

import fractions
left, right = [], []
for arr, l in zip([a, a[::-1]], [left, right]):
    l.append(arr[0])
    for i in range(1, n):
        l.append(fractions.gcd(l[-1], arr[i]))

left = [right[-1], right[-2]] + left
right = right[::-1] + [left[-2], left[-1]]

ans = 0
for (l, r) in zip(left, right):
    ans = max(ans, fractions.gcd(l, r))

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

def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]

    N = int(input())
    S = list(input())

    if S[0]!='B' or S[-1]!='B':
        print(0)
        exit()

    mod = 10**9 + 7
    cnt_l = 1
    cnt = 1
    pre = 'B'
    d = 1 #1がleft
    ans = 1

    for i in range(1,N*2):
        if S[i-1]==S[i]:
            if d:
                d = 0
                ans *= cnt%mod
                cnt -= 1
            else:
                d = 1
                cnt_l += 1
                cnt += 1
        else:
            if d:
                cnt_l += 1
                cnt += 1
            else:
                ans *= cnt%mod
                cnt -= 1

    for i in range(1,N+1):
        ans *= i
        ans %= mod
    if cnt_l!=N:
        print(0)
        exit()

    print(ans)

if __name__=='__main__':
    main()

### FIXED CODE ###

import math
n = int(input())
S = input()
 
RL = [None]*2*n
 
for i in range(2*n):
    if i % 2 == 0:
        if S[i] == 'B':
            RL[i] = 'L'
        else:
            RL[i] = 'R'
 
    else:
        if S[i] == 'B':
            RL[i] = 'R'
        else:
            RL[i] = 'L'
 
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit()
 
left = 0
count = 1
mod = 10**9 + 7
 
for check in RL:
    if check == 'L':
        left += 1
    else:
        count = count * left % mod
        left -= 1
 
    if left < 0:
        print(0)
        exit()
 
count = count * math.factorial(n) % mod
 
if left != 0:
    print(0)
else:
    print(count)
### BUGGY CODE ###

from statistics import median

R, G, B, N = map(int,input().split())
 
i = 0
j = 0
cnt = 0

maxi = max(R, G, B)
mini = min(R, G, B)
medi = median([R, G, B])

 
while i*maxi <= N:
    while i*maxi + j*medi <= N:
        if (N - i*maxi - j*medi) % mini == 0:
            cnt += 1
        j += 1
    j = 0
    i += 1
 
print(cnt)

### FIXED CODE ###

R, G, B, N = map(int,input().split())
 
i = 0
j = 0
cnt = 0
 
while i*R <= N:
    while i*R + j*G <= N:
        temp = N - i*R - j*G
        if temp % B == 0:
            cnt += 1
        j += 1
    j = 0
    i += 1
 
print(cnt)
### BUGGY CODE ###

import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

mod = 998244353

N, K = rl()
lr = []
for i in range(K):
	l, r = rl()
	lr.append((l,r))

dp = [0] * (N+1)
dp[1] = 1
dp[2] = -1

ans = 0
s = 0
for i in range(1, N+1):
	s += dp[i]
	for k in range(K):
		l, r = lr[k]
		if i+l <= N:
			dp[i+l] += s
			if i+r+1 <= N:
				dp[i+r+1] -= s
			else:
				ans += s
				ans %= mod
print(ans)



### FIXED CODE ###

import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

mod = 998244353

N, K = rl()
lr = []
for i in range(K):
	l, r = rl()
	lr.append((l,r))
lr.sort()

dp = [0] * (N+1)
dp[1] = 1
dp[2] = -1

ans = 0
s = 0
flags = [1] * K
for i in range(1, N+1):
	s += dp[i]
	s %= mod
	for k in range(K):
		if flags[k] == 0:
			break
		l, r = lr[k]
		if i+l <= N:
			dp[i+l] += s
			if i+r+1 <= N:
				dp[i+r+1] -= s
			else:
				ans += s
				ans %= mod
				break
		else:
			flags[k] = 0
			break
print(ans)
### BUGGY CODE ###

s = input()
t = input()

def LCS(X,Y):
    XL = len(X)
    YL = len(Y)
    dp = [[0 for j in range(YL+1)] for i in range(XL+1)]
    for i in range(XL):
        for j in range(YL):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    # 以下復元
    idx = dp[XL][YL]-1
    S = [0 for i in range(idx+1)]
    i,j = XL,YL
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i -= 1
            j -= 1
            S[idx] = X[i]
            idx -= 1
    return S

print(''.join(LCS(s,t)))


### FIXED CODE ###

s = input()
t = input()

def LCS(X,Y):
    XL = len(X)
    YL = len(Y)
    dp = [[0 for j in range(YL+1)] for i in range(XL+1)]
    for i in range(XL):
        for j in range(YL):
            if X[i] == Y[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
    # 以下復元
    idx = dp[XL][YL]-1
    S = [0 for i in range(idx+1)]
    i,j = XL,YL
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            i -= 1
            j -= 1
            S[idx] = X[i]
            idx -= 1
    return S

print(''.join(LCS(s,t)))
### BUGGY CODE ###

#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1


c = [''.join(sorted(a)) for _ in range(n)]
d = {string: a.count(string) for string in a}
#print(sum2)

sum1=0
for i in b.values():
  sum1+=i*(i-1)//2
print(sum1)







### FIXED CODE ###

#python3
n = int(input())
s = [str(input()) for _ in range(n)]
sep = ''
dic = dict()
for string in s:
  tmp = sep.join(sorted(string))
  if tmp in dic:
    dic[tmp] += 1 
  else :
    dic[tmp] = 1
ans = 0
for i in dic.values(): 
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [ [0 for _ in range(len_t+1)] for _ in range(len_s+1) ]

for i in range(len_s):
        for j in range(len_t):
                if s[i] == t[j]:
                    dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j]+1 )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i+1][j] )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j+1] )

i = len_s
j = len_t
str = ''

while i > 0 and j > 0:
        if dp[i-1][j] == dp[i][j]:
            i -= 1
        elif dp[i][j-1] == dp[i][j]:
            j -= 1
        else:
            str += s[i-1]
            i -= 1
            j -= 1
            
print(str[::-1])

### FIXED CODE ###

s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [ [0 for _ in range(len_t+1)] for _ in range(len_s+1) ]

for i in range(len_s):
        for j in range(len_t):
                if s[i] == t[j]:
                    dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j]+1 )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i+1][j] )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j+1] )

i = len_s
j = len_t
str = ''

while i > 0 and j > 0:
        if dp[i-1][j] == dp[i][j]:
            i -= 1
        elif dp[i][j-1] == dp[i][j]:
            j -= 1
        else:
            str += s[i-1]
            i -= 1
            j -= 1
            
print(str[::-1])
### BUGGY CODE ###

# import bisect
# from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    from heapq import heappush, heappop

    # 長点数V、直接移動先とコストを記したリストg、スタート地点rをとって、
    # rからiに行くまでの最低コストがdist[i]であることを意味するリストdistを返す関数
    def dijkstra(V, g, r):

        dist = [INF] * V
        queue = [(0, r)]  # queueの要素(c,v)は、コストcで直接vに行けることを意味する
        dist[r] = 0  # スタート地点rにはコスト0で行ける

        while queue:
            c, v = heappop(queue)
            if dist[v] < c:  # すでに記録されているコストの方が小さいので更新不要
                continue
            for cost, t in g[v]:
                if dist[v] + cost < dist[t]:
                    dist[t] = dist[v] + cost
                    heappush(queue, (dist[t], t))

        return dist

    N=int(input())
    V, E= N,N-1
    g = [[] for i in range(V)]

    for i in range(E):
        s, t, d = map(int, input().split())
        s,t,d=s-1,t-1,d
        g[s].append((d, t))
        g[t].append((d, s))# g[s]の要素(cost,t)はsからコストcostでtに直接行けることを意味する

    INF = 10 ** 20

    Q,K=map(int,input().split())
    for j in range(Q):
        x,y=map(int,input().split())
        print(dijkstra(V,g,x-1)[K-1]+dijkstra(V,g,K-1)[y-1])



resolve()

### FIXED CODE ###

import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        Edge[a-1].append((b-1, c))
        Edge[b-1].append((a-1, c))
    Q, K = map(int, input().split())
    q = deque()
    Dist = [-1] * N
    q.append((K-1, K-1, 0))
    while q:
        nowN, preN, nD = q.popleft()
        if Dist[nowN] == -1:
            Dist[nowN] = nD
            for e, add in Edge[nowN]:
                if e != preN: q.append((e, nowN, nD + add))
    Ans = [None] * Q
    for i in range(Q):
        x, y = map(int, input().split())
        Ans[i] = str(Dist[x-1] + Dist[y-1])
    print("\n".join(Ans))

    return 0

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

n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(len(p)):
    if p[i] <= min(p[:i+1]):
        ans += 1
        
print(ans)


### FIXED CODE ###

n = int(input())
ps = list(map(int, input().split()))
m = ps[0]
ans = 0
for p in ps:
    m = min(p, m)
    if p <= m:
        ans += 1        
print(ans)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9+7
#main code here!
    n=I()
    lis=[I() for i in range(n)]
    
    class SegmentTree:#非再帰(こちらの方が速い) #1-indexed
        # 初期化処理
        # f : SegmentTreeにのせるモノイド
        # default : fに対する単位元
        def __init__(self, size, f=lambda x,y : max(x,y), default=-inf):
            self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
            self.default = default
            self.dat = [default]*(self.size*2) # 要素を単位元で初期化
            self.f = f
    
        def update(self, i, x):
            i += self.size
            self.dat[i] = x
            while i > 0:
                i >>= 1
                self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
    
        def query(self, l, r):
            l += self.size
            r += self.size
            lres, rres = self.default, self.default
            while l < r:
                if l & 1:
                    lres = self.f(lres, self.dat[l])
                    l += 1
    
                if r & 1:
                    r -= 1
                    rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
                l >>= 1
                r >>= 1
            res = self.f(lres, rres)
            return res
    #Seg=SegmentTree(n,lambda x,y : max(x,y),-inf)
    Seg=SegmentTree(n)
    for i in range(n):
        Seg.update(i,lis[i])
    for i in range(n):
        Seg.update(i,-inf)
        print(Seg.query(0,n))
        Seg.update(i,lis[i])
    
    
                
                
if __name__=="__main__":
    main()



### FIXED CODE ###

import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
nums=[]
for i in range(n):
    nums.append(int(input()))
nms=sorted(nums,reverse=True)
for i in range(n):
    if nums[i]==nms[0]:
        print(nms[1])
    else:
        print(nms[0])
### BUGGY CODE ###

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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while q:
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h <= 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)


### FIXED CODE ###

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

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)
### BUGGY CODE ###

N = int(input())

a = []
for i in range(N):
    a.append(int(input()))
print(max(a[1:]))
for i in range(1,N-1):
    a_max = max(a[:i])
    n_a_max = max(a[i+1:])
    if(a_max>=n_a_max):
        print(a_max)
    else:
        print(n_a_max)
print(max(a[:N-1]))
    

### FIXED CODE ###

import numpy as np

N = int(input())

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

if(N==1):
    print(a[0])
else:
    a_max = 0
    n_a_max = 0
    all_max = max(a)
    max_arg = np.argmax(a)

    if(max_arg!=0):
        a_max = max(a[:max_arg])
    if(max_arg!=N-1):
        n_a_max = max(a[max_arg+1:])

    if(a_max>=n_a_max):
        next_max = a_max
    else:
        next_max = n_a_max

    for i in range(N):
        if a[i]==all_max:
            print(next_max)
        else:
            print(all_max)
### BUGGY CODE ###

import sys
N = int(input())
words = []
cnts = []
for i in range(N):
    S = input()
    if S not in words:
        words.append(S)
        cnts.append(1)
    else:
        cnts[words.index(S)] += 1
max_words = []
for j in range(len(words)):
    if cnts[j] == max(cnts):
        max_words.append(words[j])
max_words = sorted(max_words)
for a in max_words:
    print(a)

### FIXED CODE ###

from collections import Counter
N = int(input())
S =[input() for i in range(N)]
cnts = Counter(S)
mx = 0
for v in cnts.values():
    mx = max(mx, v)
    
max_words = [k for k, v in cnts.items() if v == mx]
max_words = sorted(max_words)
print(*max_words, sep ="\n")
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n)]
    dp[0] = 0

    for i in range(n):
        a = min(k+1, n-i)
        for j in range(1, a):
            num = dp[i]+abs(h[i]-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf')]*n
    dp[0] = 0
    for i in range(n):
        a = h[i]
        for j in range(1, min(k+1, n-i)):
            num = dp[i]+abs(a-h[i+j])
            if num < dp[i+j]:
                dp[i+j] = num
    print(dp[-1])

main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!

A, B, K = map(int, input().split())
s = [_ for _ in range(A, B + 1)]
s_len = len(s)

if K * 2 >= s_len:
    for i in s: print(i)
else:
    for j in range(K): 
        print(s[j])
    for k in range(s_len - K, s_len): 
        print(s[k])

### FIXED CODE ###

# coding: utf-8
# Your code here!

A, B, K = map(int, input().split())
a1 = [_ for _ in range(A, min(A + K, B + 1))]
a2 = [_ for _ in range(max(A, B - K + 1), B + 1)]
s = sorted(set(a1 + a2))

for i in s: print(i)
### BUGGY CODE ###

n = int(input())
s = input()

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        p = 0
        for k in range(min(j-i,n-1-j+1)):
            if s[i+k] == s[j+k]:
                p += 1
                
            else:
                break
        ans = max(ans,p)

print(ans)

### FIXED CODE ###

n = int(input())
s = input()

check_list = [ [ 0 for i in range(n) ] for i in range(n) ]


ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        if check_list[i][j] == 0:
            p = 0
            for k in range(min(j-i,n-1-j+1)):
                if s[i+k] == s[j+k]:
                    p += 1
                else:
                    break
            for k in range(1,p):
                check_list[i+k][j+k] = p - k
        ans = max(ans,p)

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

def digit(N,n):#nは正の整数、N進法での桁数、許容は１０＾１０００
    if n<N:
        return 1
    else:
        return 1+digit(N,n//N)

def Nbasenumber(N,m):#N>1,mは正の整数、N進法表記、出力は数、許容はN＾１０００
    if  m<N:
        return m
    else:
        k=digit(N,m)#digitとの併用を忘れないこと
        i=m//(N**(k-1))
        return i*(10**(k-1))+Nbasenumber(N,m%(N**(k-1)))

def digitsum(n):#nは正の整数、各位の和、許容は１０＾１０００
    if n<10:
        return n
    else:
        m=n//10
        return n%10+digitsum(m)

def main():
    N=int(input())
    A=[0]*N
    shougen=[[] for i in range(0,N)]
    for i in range(0,N):
        A[i]=int(input())
        for j in range(0,A[i]):
            a,b=map(int,input().split())
            shougen[i].append([a,b])
    m=0
    for i in range(0,2**N):
        flag=0
        check=[]
        x=str(Nbasenumber(2,i))
        for j in range(0,N-len(x)):
            x='0'+x#正直者の仮定
        for j in range(0,N):
            if x[j]=='1':
                check.extend(shougen[j])#証言の収集
        for j in range(0,N):
            if ([j+1,0] in check) or ([j+1,1] in check):
                if [j+1,0] in check:
                    if j==0:
                        data='0'
                    else:
                        data=data+'0'
                if [j+1,1] in check:
                    if j==0:
                        data='1'
                    else:
                        data=data+'1'

            else:
                if j==0:
                    data='A'
                else:
                    data=data+'A'#証言から得られる正直者リスト
        for j in range(0,N):
            if data[j]!='A':
                if data[j]!=x[j]:
                    flag=1
        if len(data)!=N:
            flag=1
        if flag==0:
            test=digitsum(int(x))
            if test>m:
                m=test

    print(m)

if __name__ == '__main__':
    main()

### FIXED CODE ###

N=int(input())
shougen=[(0,0) for i in range(0,N)]
for i in range(0,N):
    A=int(input())
    honest=0
    unkind=0
    for j in range(0,A):
        x,y=map(int,input().split())
        if y==0:
            unkind+=2**(x-1)
        else:
            honest+=2**(x-1)
    shougen[i]=(honest,unkind)

ans=0
for i in range(0,2**N):
    honest=i
    unkind=2**N-1-i
    check=True
    test=0
    for j in range(0,N):
        if (i>>j)&1 ==1:
            test+=1
            x,y=shougen[j]
            if (honest-x)^x!=honest or (unkind-y)^y!=unkind:
                check=False
    if check:
        if test>ans:
            ans=test

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

N=int(input())
s=list(map(int,input().split()))
t=list(set(s))
ans=0
for i in range(len(t)):
    u=s.count(t[i])-t[i]
    if u<0:
        ans+=s.count(t[i])
    if u>0:
        ans+=u
print(ans)   

### FIXED CODE ###

N=int(input())
s,ans={},0
for i in list(map(int,input().split())):
    s[i]=s.get(i,0)+1
for c,v in s.items():
    if c<v:
        ans+=v-c
    if c>v:
        ans+=v
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]==j+1 and a[j]==i+1:
      cnt+=1
    else:
      cnt=cnt
print(cnt)
      


### FIXED CODE ###

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

'''
                                    *             * * * * * * * *
                                    *             *
                                    *             *
                                    *             *
                                    *             *
                                    *             *
                                    *             *
                                    * * * * * * * * * * * * * * *
                                                  *             *
                                                  *             *
                                                  *             *
                                                  *             *
                                                  *             *
                                                  *             *
                                    * * * * * * * *             *

'''
import sys
sys.setrecursionlimit(10**9)
dp=[-1]*(10**5+2)
dp[0]=0
def frog2(arr,N,K):
    if N==0:
        return dp[0]
    if dp[N]!=-1:
       return dp[N]
    cnt=1000000000
    for i in range(N-1,max(N-K-1,-1),-1):
        cnt=min(cnt,frog2(arr,i,K)+abs(arr[N]-arr[i]))
    dp[N]=cnt
    #print(N,dp[N])
    return dp[N]
if __name__ == "__main__":
    N,K=map(int,input().split())
    h=[int(i) for i in input().split()][:N]
    frog2(h,N-1,K)
    #print(dp)
    print(dp[N-1])

### FIXED CODE ###

from sys import stdin
N,K=map(int,stdin.readline().split())
h=[int(i) for i in stdin.readline().split()][:N]
dp=[float('inf') for i 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]+abs(h[j]-h[i]))
    #print(dp)
print(dp[-1])
### BUGGY CODE ###

import numpy as np
def so(n):
    for i in range(3, int(np.sqrt(n)) + 1, 2):
        if n % i == 0:
            return False
    return True
A, B = map(int, input().split())
M = np.min([A, B])
n = 1
if (A % 2 == 0) and (B % 2 == 0):
    n = 2
for i in range(3, M, 2):
    if (A % i == 0) and (B % i == 0):
        if so(i):        
            n = n + 1
print(n)


### FIXED CODE ###

import numpy as np
def p(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
A, B = map(int, input().split())
M = np.min([A, B])
a = p(A)
b = p(B)
t = set(a) & set(b)
print(len(t) + 1)