Harryxun/stf_run huggingface dataset:
import copy
import math
# N=int(input())
# a = list(map(int,input().split()))

# N=3
# a = [7,6,8]

# N = 40
# a = np.array([4,8,6,12]*(N//4), dtype=np.int)

N=10
a = [56,58,82,46,67,36,98,68,24,46]

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

# 一番近い大きい側の2の累乗の数が，segtreeの葉の数になる．
N_ADJUST = 2**int(math.ceil(math.log2(N)))
# segtreeのサイズはN_ADJUSTを葉とする木のノード数．
ST_SIZE = N_ADJUST*2-1
# binopに合わせて単位元として決める．maxならINT_MAX(問題文の制限)
INT_IDENTITY = 0
li = [INT_IDENTITY]*ST_SIZE
# li_initは，葉の配列．
# 節点kが [l,r) にbinopという演算で結びついている．
def init_segtree(li, k, l, r, binop, li_init):
    if r-l==1:
        li[k] = INT_IDENTITY if l >= len(li_init) else li_init[l]
    elif r-l>1:
        k_l, k_r = k*2+1, k*2+2
        init_segtree(li, k_l, l, (l+r)//2, binop, li_init)
        init_segtree(li, k_r, (l+r)//2, r, binop, li_init)
        li[k] = binop(li[k_l],li[k_r])

init_segtree(li,0,0,N_ADJUST,gcd,a)

# print(li)

# 下からupdateする．
def update_segtree(li,k,binop):
    if k > 0:
        k_l, k_r = ((k-1)//2)*2+1, ((k-1)//2)*2+2
        li[(k-1)//2] = binop(li[k_l],li[k_r])
        update_segtree(li,k//2,binop)

val = []
l2 = copy.deepcopy(li)
for i in range(N_ADJUST-1,N_ADJUST+N-1):
    l2[i] = 0
    update_segtree(l2,i,gcd)
    print(i, l2)
    val.append(l2[0])
    l2[i] = li[i]
    update_segtree(l2,i,gcd)

print(max(val))

### FIXED CODE ###

# @profile
def main():
    import math

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

    # N=5
    # a = [12,15,18,36,42]

    # N = 10**5
    # a = [1]*N

    # N=11
    # a = [56,58,82,46,67,36,98,68,24,46,52]

    #a,bの最大公約数
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a

    # 一番近い大きい側の2の累乗の数が，segtreeの葉の数になる．
    N_ADJUST = 2**int(math.ceil(math.log(N)/math.log(2)))
    # segtreeのサイズはN_ADJUSTを葉とする木のノード数．
    ST_SIZE = N_ADJUST*2-1
    # binopに合わせて単位元として決める．maxならINT_MAX(問題文の制限)
    INT_IDENTITY = 0
    li = [INT_IDENTITY]*ST_SIZE
    # li_initは，葉の配列．
    # 節点kが [l,r) にbinopという演算で結びついている．
    def init_segtree(li, k, l, r, binop, li_init):
        if r-l==1:
            li[k] = INT_IDENTITY if l >= len(li_init) else li_init[l]
        elif r-l>1:
            k_l, k_r = k*2+1, k*2+2
            init_segtree(li, k_l, l, (l+r)//2, binop, li_init)
            init_segtree(li, k_r, (l+r)//2, r, binop, li_init)
            li[k] = binop(li[k_l],li[k_r])

    init_segtree(li,0,0,N_ADJUST,gcd,a)

    # print(li)
    # 下からupdateする．
    def update_segtree(li,k,binop):
        if k > 0:
            k_2 = (k-1)//2
            k_l = k_2*2+1
            k_r = k_l+1
            li[k_2] = binop(li[k_l],li[k_r])
            update_segtree(li,k_2,binop)

    val = []
    for i in range(N_ADJUST-1,N_ADJUST+N-1):
        tmp = li[i]
        li[i] = 0
        update_segtree(li,i,gcd)
        # print(i, li)
        val.append(li[0])
        li[i] = tmp
        update_segtree(li,i,gcd)

    print(max(val))

main()
x = int(print())

print(x**3)

### FIXED CODE ###

x = int(input())
print(x**3)
import sys

sys.setrecursionlimit(10 ** 6)

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def paint_col(adj, cols, i, col):
    cols[i] = col

    for child in adj[i]:
        if cols[child] == 0:
            paint_col(adj, cols, child, col)

def solve():
    n, m = map(int, input().split())
    adj = [[] for i in range(n)]

    for i in range(m):
        s, t = map(int, sys.stdin.readline().split())
        adj[s].append(t)
        adj[t].append(s)

    cols = [0] * n
    col = 1

    for i in range(n):
        if cols[i] == 0:
            paint_col(adj, cols, i, col)
            col += 1

    # debug(cols, locals())

    q = int(input())

    for i in range(q):
        s, t = map(int, sys.stdin.readline().split())

        if cols[s] == cols[t]:
            print('yes')
        else:
            print('no')

    pass

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def paint_col(adj, cols, i, col):
    nxt = [i]

    while nxt:
        u = nxt[-1]
        try:
            v = next(adj[u])
            if cols[v] == 0:
                cols[v] = col
                nxt.append(v)
        except StopIteration:
            nxt.pop()
            cols[u] = col

def solve():
    n, m = map(int, sys.stdin.readline().split())
    adj = [[] for i in range(n)]

    for i in range(m):
        s, t = map(int, sys.stdin.readline().split())
        adj[s].append(t)
        adj[t].append(s)

    cols = [0] * n
    col = 1
    adj = list(map(iter, adj))

    for i in range(n):
        if cols[i] == 0:
            paint_col(adj, cols, i, col)
            col += 1

    # debug(cols, locals())

    q = int(sys.stdin.readline())

    for i in range(q):
        s, t = map(int, sys.stdin.readline().split())

        if cols[s] == cols[t]:
            ans = 'yes'
        else:
            ans = 'no'

        print(ans)

if __name__ == '__main__':
    solve()
H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append(list(input()))

res = True

for i in range(1, W-1):
    for j in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            print('No')
            exit()
print('Yes')


### FIXED CODE ###

H, W = map(int, input().split())
graph = []
for _ in range(H):
    graph.append(list(input()))

res = True

for j in range(1, W-1):
    for i in range(1, H-1):
        if graph[i][j] == '#' and graph[i + 1][j] == '.' and graph[i - 1][j] == '.' and graph[i][j + 1] == '.' and graph[i][j - 1] == '.':
            print('No')
            exit()
print('Yes')
a, b, c, d = map(int, input().split())

t_hp = a
a_hp = c
while a_hp > 0 or t_hp > 0:
	a_hp -= b
	t_hp -= d
	if a_hp <= 0:
      print("Yes")
      exit()
    elif t_hp <= 0:
      print("No")
      exit()

### FIXED CODE ###

a, b, c, d = map(int, input().split())

t_hp = a
a_hp = c
while a_hp > 0 or t_hp > 0:
    a_hp -= b
    t_hp -= d
    if a_hp <= 0:
         print("Yes")
         exit()
    elif t_hp <= 0:
         print("No")
         exit()
from collections import defaultdict

s = list(input())
x, y = list(map(int, input().split()))

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			X.append(l)
			judge = "y"
		else:
			judge == "y"
			Y.append(l)
			judge = "x"
		l =0

if judge == "x":
	X.append(l)
else:
	Y.append(l)


dx = defaultdict(int)
dx[X[0]] = 1
X.remove(X[0])
for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] >= 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D

dy = defaultdict(int)
dy[Y[0]] = 1
dy[-Y[0]] = 1
Y.remove(Y[0])
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] >= 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

from collections import defaultdict

s = list(input())
x, y = list(map(int, input().split()))

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			if l != 0:
				X.append(l)
			judge = "y"
		else:
			if l != 0:
				Y.append(l)
			judge = "x"
		l = 0

if judge == "x":
	if l != 0:
		X.append(l)
else:
	if l != 0:
		Y.append(l)

jj = "bad"
if len(s) >= 2:
	if s[0] == "T":
		jj = "good"


dx = defaultdict(int)
if X != []:
	if jj == "good":
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])
else:
	dx[0] = 1

for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D


dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
else:
	dy[0] = 1

for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")
a, b = map(input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")
import math

mod = 1000000007
N = int(input())
S = input()
cnt_L = 0
cnt = 1
newS = ''
if S.count('B') != N:
  cnt = 0
else:
  for i,s in enumerate(S):
    if i%2 == 0:
      s='W' if s=='B' else 'B'
    newS += s
    if s=='W':
      cnt_L += 1
    else:
      cnt = cnt * cnt_L
      cnt_L -= 1
print((cnt*math.factorial(N))%mod)

### FIXED CODE ###

M,D = map(int,input().split())
months = range(1,M+1)
days = range(10,D+1)
cnt = 0
for month in months:
  for day in days:
    day = str(day)
    if (int(day[0])>1)&(int(day[1])>1):
      if (int(day[0])*int(day[1]))==month:
        cnt += 1

print(cnt)
#import sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
maxa=max(a)

#print(a)
ans=0
if n==1:
  ans=1
else:
  for i in range(1,maxa+1):
    cnt=0
    for j in range(len(a)):
      if a[j]==i or a[j]==i-1 or a[j]==i+1:
        cnt+=1
      if ans <= cnt:
        ans = cnt

print(ans)



### FIXED CODE ###

x, t= (int(i) for i in input().split())
print(x-t if x > t else 0)
import math
import sys
n, m = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

print(combinations_count(n, 2) + combinations_count(m, 2))

### FIXED CODE ###

import math
import sys
n, m = map(int, input().split())

def combinations_count(n, r):
    C = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return C

if n <= 1 and m >= 2:
    print(combinations_count(m, 2))
    sys.exit()
elif n >= 2 and m <= 1:
    print(combinations_count(n, 2))
    sys.exit()
elif n == m == 1:
    print(0)
    sys.exit()
elif n == m == 0:
    print(0)
    sys.exit()
else:
    print(combinations_count(n, 2) + combinations_count(m, 2))
N = int(input())
A = list(map(int,input().split()))
ans = 1

if 0 in A:
  print(1)
  exit
  
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    print(-1)
     exit()
    
print(ans)


### FIXED CODE ###

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

if 0 in A:
  ans = 0
  N = 0
  
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    ans = -1
    break
    
print(ans)
N = input()

if N[-1] == 7 or N[-2] == 7 or N[-3] == 7:
    print(Yes)
else:
    print(No)

### FIXED CODE ###

N = input()

if N[-1] == "7" or N[-2] == "7" or N[-3] == "7":
    print("Yes")
else:
    print("No")
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, X, Y = [int(x) for x in input().strip().split()]
G = np.zeros((N, N), dtype=int)
for k in range(N):
    for k2 in range(k+1, N):
        G[k, k2] = min(k2 - k, G[min(k, X-1), max(k, X-1)]+1+abs(k2 - (Y - 1)))

for k in range(1, N):
    print(sum(sum(G == k)))


### FIXED CODE ###

import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, X, Y = [int(x) for x in input().strip().split()]
D = defaultdict(int)
for k in range(1, N):
    for k2 in range(k+1, N+1):
        D[min(k2 - k, abs(X-k) + 1 + abs(Y-k2), abs(Y-k) + 1 + abs(X-k2))] += 1

for k in range(1, N):
    print(D[k])
n = int(input())
A = list(map(int,input().split()))

def main(i):
  a = A.count(i)
  b = A.pop(0)
  print(a)


for i in range(1,n+1):
  main(i)

### FIXED CODE ###

from collections import Counter
n = int(input())
A = list(map(int,input().split()))

mycounter = Counter(A)

for i in range(1,n+1):
  print(mycounter[i])
import numpy as np
N, K = map(int, input().split())
n = N
while 1:
	a = np.minumum(n, np.abs(n - K))
	if a == n:
		break
print(a)

### FIXED CODE ###

import numpy as np
N, K = map(int, input().split())
a = N % K
b = K - a
print(min([a, b]))
import sys
for line in sys.stdin:
    a,b = line.split()
    a,b = int(a),int(b)
    print '%d %d %.8f' %(a/b, a%b, 1.0*a/b)

### FIXED CODE ###

a, b = map(int, raw_input().split())
print '%d %d %.12f' %(a/b, a%b, 1.0*a/b)
n,m = map(int,input().split())

a = [0]*n
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 1 for c in x)):
        if any(c%2 == 1 for c in x):
            return 0
        x /= 2
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x/gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
    
    
    


### FIXED CODE ###

n,m = map(int,input().split())

a = [1]*n
#print(a)
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 0 for c in x)):
        x = [s//2 for s in x]
        if any(c%2 == 1 for c in x) and any(c%2 == 0 for c in x):
            return 0
        
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x//gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
s = input()
for i in range(len(s)-1):
  if s[i+1] != 'B':
    ans += s[i]
    
print(ans)


### FIXED CODE ###

s = input()
output_s = ""

for i in s:
  if i == "B" and len( output_s) != 0:
    output_s = output_s[0:len( output_s)-1]
  elif i != "B":
    output_s += i
  
print(output_s)
import numpy as np
a=np.array([[0]*10]*12)
n=int(input())
for i in range(n):
    b,f,r,v=map(int,input().split())
    a[ 3*b-4+f, r-1 ] = v
for i in range(12):
    if i > 0 and i%3==0:
        print('#'*20)
    print(*a[i,])

### FIXED CODE ###

towers = [
    [[0 for i in range(10)] for j in range(3)] for k in range(4)
]
floor = 3
 
n = int(input())
for i in range(n):
    b,f,r,v = list(map(int,input().split()))
    towers[b-1][f-1][r-1] += v
 
for b in towers:
    for f in b:
        for r in f:
            print(' ' + str(r), end='')
        print('')
    if floor:
        print('#'*20)
        floor -= 1
N = input()
 
for n in range(N):
    data = map(float,raw_input().split( ))
    slopes = []
    for i in range(2):
        _x1 = data.pop(0)
        _y1 = data.pop(0)
        _x2 = data.pop(0)
        _y2 = data.pop(0)
         
        if _x1 != _x2:
            slopes.append((_y1 - _y2)/(_x1 - _x2))
     
    if len(slopes) == 0:
        print("YES")
    elif len(slopes) == 1:
        print("NO")
    elif abs(slopes[0] - slopes[1]) < 1e-10:
        print("YES")
    else:
        print("NO")

### FIXED CODE ###

N = input()
 
for n in range(N):
    data = map(float,raw_input().split( ))
    slopes = []
    for i in range(2):
        _x1 = data.pop(0)
        _y1 = data.pop(0)
        _x2 = data.pop(0)
        _y2 = data.pop(0)
         
        if _x1 != _x2:
            slopes.append((_y1 - _y2)/(_x1 - _x2))
     
    if len(slopes) == 0:
        print "YES"
    elif len(slopes) == 1:
        print "NO"
    elif abs(slopes[0] - slopes[1]) < 1e-10:
        print "YES"
    else:
        print "NO"
H,W,A,B=map(int,input().split())
def kaijo(a):
    x=1
    for i in range(a):
       x=x*(i+1)
    return x
def con(a,b):
    x=kaijo(a)
    y=kaijo(b)
    z=kaijo(a-b)
    res = x/y/z
    return res

def calc(x,y):
    res = con(x+y-2,x-1)
    return res

all = calc(H,W)
for i in range(B):
    x=i+1
    k = calc(x,H-A)*calc(A,W-x)
    all=all-k
print(int(all))

### FIXED CODE ###

H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
 
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
 
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod
 
 
def comb(x, y):
    return X[x] * Y[y] * Y[x - y] % mod
 
 
ans = 0
for i in range(B, min(B + H - A, W)):
    ans += comb(H - A + B - 1, i) * comb(W + A - B - 1, W - i - 1)
    ans %= mod
print(ans)
(n, k) = [int(s) for s in input().split()]

data = [[0 for i in range(k)] for j in range(n)]

for i in range(0, k):
    d = int(input())
    a = [int(s) for s in input().split()]

    for m in a:
        data[m - 1][d - 1] = 1

dd = []

for d in data:
    dd.append(sum(d))

ans = 0

for ddd in dd:
    if ddd == 0:
        ans += 1

print(ans)



### FIXED CODE ###

(n, k) = [int(s) for s in input().split()]

data = [[0 for i in range(k)] for j in range(n)]

for i in range(0, k):
    d = int(input())
    a = [int(s) for s in input().split()]

    for m in a:
        data[m - 1][i] = 1

dd = []

for d in data:
    dd.append(sum(d))

ans = 0

for ddd in dd:
    if ddd == 0:
        ans += 1

print(ans)
import sys
import collections

n = int(input())
a = sorted([int(i) for i in input().split()])
# print(a)
top = a.pop(-1)

nega = sorted([i for i in a if i < 0])
posi = sorted([i for i in a if i > 0])
#print(nega,posi)

if len(nega) == 0:
    nega.append(posi.pop(0))

process = []

for _ in range(len(posi)):
    x = nega.pop(0)
    y = posi.pop(0)
    nega.append(x - y)
    process.append([x, y])
x = top
y = nega.pop(0)
process.append([x, y])
x -= y
for _ in range(len(nega)):
    y = nega.pop(0)
    process.append([x, y])
    x -= y
ans = x

print(ans)
for i in range(len(process)):
    print('{} {}'.format(process[i][0], process[i][1]))


### FIXED CODE ###

import sys
import collections

n = int(input())
a = sorted([int(i) for i in input().split()])
# print(a)
top = a.pop(-1)

nega = sorted([i for i in a if i < 0])
posi = sorted([i for i in a if i >= 0])
#print(nega,posi)

if len(nega) == 0:
    nega.append(posi.pop(0))

process = []

for _ in range(len(posi)):
    x = nega.pop(0)
    y = posi.pop(0)
    nega.append(x - y)
    process.append([x, y])
x = top
y = nega.pop(0)
process.append([x, y])
x -= y
for _ in range(len(nega)):
    y = nega.pop(0)
    process.append([x, y])
    x -= y
ans = x

print(ans)
for i in range(len(process)):
    print('{} {}'.format(process[i][0], process[i][1]))
n,m  = map(int,input().split())
z = list(map(int,input().split()))


ok = [1]
if m == 1:
    print(z[0]-n)
    exit()

for i in range(1,z[1]-z[0]):
    ans = True
    for j in range(len(z)):
        if abs(z[j]-m)%i != 0:
            ans = False
    if ans :
        ok.append(i)
print(ok[-1])


### FIXED CODE ###

from fractions import gcd

n,x  = map(int,input().split())
z = list(map(int,input().split()))



ans = abs(z[0] - x)
for i in range(1, n):
    ans = gcd(ans, abs(x - z[i]))
print(ans)
L=input()
x=L/6
y=L/6
z=L/6
print(x*y*z)

### FIXED CODE ###

L=int(input())
x=L/3
y=L/3
z=L/3
print(x*y*z)
N = int(input())
A = [int(i) for i in input().split()]
sort.A
dif = A[N-1]-A[0]
print(dif)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
A.sort()
dif = A[N-1]-A[0]
print(dif)
# -*- coding: utf-8 -*-

def main():
    N=int(input())  #数値入力 「N」だけの入力のとき
    H=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
    D=list()
    ans = 0
    cnt = 0
    for ind, i in enumerate(H[:-1]): #初めから最後から2番目の要素まで
        if i>=H[ind+1]:
            cnt += 1
            if ind == N-2:
                D.append(cnt)
        else:
            D.append(cnt)
            cnt = 0
    #print("D")
    #print(D)

    print(max(D))

if __name__ == '__main__':
    main()

### FIXED CODE ###

N = int(input())
H = [int(x) for x in input().split()]
ans = 0
cnt = 0
for ind,i in enumerate(H[:-1]):
    if(i>=H[ind+1]):
        cnt += 1
    else:
        cnt = 0
    ans = max(ans,cnt)
print(ans)
a = int(input())
b = int(input())

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
n = int(input())
p = list(map(int,input().split()))
q = sort(p)
for i in range(1,n):
    if p[i]  != q[i]:
        a += 1
if a  <= 2:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
a = 0
for i in range(n):
    if int(p[i])  != int(q[i]):
        a += 1
if a  <= 2:
    print('YES')
else:
    print('NO')
while True:
	#player_nun = int(input())
	player_nun = 4
	if player_nun == 0:
		break
	
	#?????????????????????
	whole_data = []
	for i in (0, player_nun):
		#dat = input().split()
		#p_data = []
		#p_data.append(dat[0])
		for x in dat[1:]:
			p_data.append(int(x))
			whole_data.append(p_data)
			
	#???????????????????????????????????????
	xel = {}
	for i in whole_data:
		for x in i[2:]:
			if x in xel:
				xel[x] += 1
			else:
				xel[x] = 1
	
	#??????????????????????????¢?????????
	score = {}
	for y in xel.keys():
		score[y] = 5 - xel[y]	
	#????????¢??¨????????????????????????????????????
	result = []
	for i in whole_data:
		player_score = []
		player_score.append(i[0])
		player_score.append(0)
		for x in i[2:]:
			player_score[1] += score[x]
		result.append(player_score)
	
	#?????????????????????????¬?????????????????±???????	
	min_score = min(x[1] for x in result)
	winners = []
	for x in result:
		if x[1] == min_score:
			winners.append(x[0])
	print(str(min_score) + " " + sorted(winners)[0])

### FIXED CODE ###

while True:
	player_nun = int(input())
	if player_nun == 0:
		break
	
	#?????????????????????
	whole_data = []
	for i in range(0, player_nun):
		dat = input().split()
		p_data = []
		p_data.append(dat[0])
		for x in dat[1:]:
			p_data.append(int(x))
		whole_data.append(p_data)
	
	#???????????????????????????????????????
	xel = {}
	for i in whole_data:
		for x in i[2:]:
			if x in xel:
				xel[x] += 1
			else:
				xel[x] = 1
	
	#??????????????????????????¢?????????
	score = {}
	for y in xel.keys():
		score[y] = player_nun + 1 - xel[y]	
	#????????¢??¨????????????????????????????????????
	result = []
	for i in whole_data:
		player_score = []
		player_score.append(i[0])
		player_score.append(0)
		for x in i[2:]:
			player_score[1] += score[x]
		result.append(player_score)
	
	#?????????????????????????¬?????????????????±???????	
	min_score = min(x[1] for x in result)
	winners = []
	for x in result:
		if x[1] == min_score:
			winners.append(x[0])
	print(str(min_score) + " " + sorted(winners)[0])
	
	#??£??????????????????????????????
# -*- coding: utf-8 -*-
 
N, K = map(int, input().split())
 
h = list(map(int, input().split()))
 
dp = [0]
 
for n in range(1, N):
    temp = float("inf")
    for k in range(1,K+1):
        if n-k < 0:
            continue
        temp = min(temp, dp[-1-k] + abs(h[n]-h[n-k]))
    dp.append(temp)
#print(dp)
print(dp[N-1])

### FIXED CODE ###

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

import numpy as np

N, K = map(int, input().split())
 
h = np.array(list(map(int, input().split())))
 
dp = np.zeros(N)
 
for n in range(1, N):
    k = min(K, n)
    temp = np.min(dp[n-k:n] + np.abs(h[n]-h[n-k:n]))
    dp[n] = temp
print(int(dp[-1]))