Harryxun/stf_run huggingface dataset:
h, w, a, b = map( int, input().split() )

SIZE = h+w+2
MOD = 10**9 + 7
MOD_Farmer = 10**9+5

fact = [0] * SIZE
inv = [0] * SIZE
fact_inv = [0] * SIZE

# prepare --------------------------------
inv[0] = 0
inv[1] = 1
fact[0] = fact[1] = 1
fact_inv[0] = fact_inv[1] = 1
for i in range( 2, SIZE ):
  fact[i] = fact[i-1] * i % MOD
  fact_inv[i] = ( (fact[i] **( 10**4 ) \
                 * fact[i] **( 10**5 ) \
                 * fact[i] ** 5      ) % MOD )\
                 % MOD
# ----------------------------------------
def comb( n, r ):
  if r >= 0 and n >= 0:
    return fact[n] * fact_inv[n-r] * fact_inv[r]
  else :
    return 0.0
# ----------------------------------------

ans = 0
for i in range( h-a ):
    ans += comb(i+b-1, b-1) * comb(h-i-1+w-b-1,w-b-1)
ans %= MOD
print( ans )

### FIXED CODE ###


a, b, c = map( int, input().split() )
 
if a == 5 and b == 5 and c == 7:
	print( "YES" )
elif a == 5 and b == 7 and c == 5:
  	print( "YES" )
elif a == 7 and b == 5 and c == 5:
  	print( "YES" )
else :
	print( "NO" )
import math

		x,y=[int(i) for i in input().split()]
	

### FIXED CODE ###

import math
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = int (math.log10(x + y) + 1)
		print(a)
alpha = input()
a = [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z]

if alpha in a:
  print('A')
else:
  print('a')

### FIXED CODE ###

alpha = input()
if alpha.isupper():
  print('A')
else:
  print('a')
n=int(input())
a=[int(i) for i in input().split()]
b=sorted(a)
m=int((n+1)//2)
s=0
for i in range(m):
  s+=b[2*i+1]
print(s)
  


### FIXED CODE ###

n=int(input())
a=int(input())
if n%500<=a:
  print("Yes")
else:
  print("No")
N = int(input())
H = list(map(int, input().split()))

cnt = 0
for i in range(1:N+1):
    if (max(H[0:i+1]) == H[i]):
        cnt += 1

print(cnt)


### FIXED CODE ###

A,B = map(int,input().split())
if A == B:
	print(A+B)
elif A < B:
    print(B*2-1)
else:
    print(A*2-1)
n = int(input())
dic = {}
for i in range(n):
  s = list(input()).sorted()
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)

### FIXED CODE ###

n = int(input())
dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1) // 2
print(ans)
in=input("")
print("ABC{}".format(in))

### FIXED CODE ###

x=input("")
print("ABC{}".format(x))
N = int(input())
L = list(map(int, input().split()))

for i in L:
  for k in L[1:]:
    if i<=k || i-1<=k:
      ans=yes
    else:
      ans=no
      
print(ans)

### FIXED CODE ###

N=int(input())
H=list(map(int, input().split()))
maxv=H[0]
ans="Yes"
for i in range(1, N):
  if maxv-H[i]>=2:
    ans="No"
    break
  maxv=max(maxv, H[i])
print(ans)
l = list(input())

for i in range(3):
  if list[i] == "7":
    print("Yes")
    exit()

print("No")

### FIXED CODE ###

l = list(input())
 
for i in range(3):
  if l[i] == "7":
    print("Yes")
    exit()
 
print("No")
N = int( input())
S = list( input())

intger2 = 0

for i in range(N):
  intger1 = 0
  str1 = list(set(S[i + 1:]))
  str2 = list(set(S[:i + 1]))
  l = len(str2)
  
  for j in range(l):
    if( str2[j] in str1):
      intger1 += 1
      
    else:
      continue
  
  if( intger2 <= intger1):
    intger2 = intger1
    
  else:
    continue
    
print(intger2)

### FIXED CODE ###

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

C1 = A + B
C.append(C1)

C2 = A - B
C.append(C2)

C3 = A * B
C.append(C3)

C = sorted(C)

print(C[2])
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    cnt = 0
    c_sum = [0]
    s = set()
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        now = p[now]
        cnt += 1
        if now in s:
            break
    if k <= cnt:
        ans = max(ans, max(c_sum[1: cnt + 1]))
    else:
        temp = c_sum[-1]
        q = k // cnt
        temp *= q
        q = k - q*cnt
        temp += max(c_sum[1:q + 1])
        ans = max(ans, temp, max(c_sum[1:]))
print(ans)




    

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = [int(x) for x in input().split()]

ans = -float('inf')
for i in range(n):
    now = i
    c_sum = [0]
    s = set()
    cnt = 0
    while True:
        s.add(now)
        c_sum.append(c_sum[-1] + c[now])
        cnt += 1
        now = p[now]
        if now in s:
            break
    c_sum = c_sum[1:]
    if k < cnt:
        ans = max(ans, max(c_sum[: k]))
    else:
        score = c_sum[-1]
        count = k // cnt
        k_ = k - count*cnt
        score *= count
        score_2 = score - c_sum[-1]
        score_2 += max(c_sum)
        if k_ > 0:
            score += max(0, max(c_sum[:k_]))
        ans = max(ans, score, max(c_sum), score_2)
print(ans)
#include<bits/stdc++.h>
using namespace std;
strint s1, s2;
int leng;
int main()
{
    cin >> s1;
    for(int i = s1.size() - 1; i >= 0; i--)
        s2[leng++] = s1[i];
    for(int i = 0; i < leng; i++)
    {
        if(s1[i]=='b') s2[i]='d;
        else if (s1[i] == 'd') s2[i] = 'b';
        else if (s1[i] == 'p') s2[i] = 'q';
        else if (s1[i] == 'q') s2[i] = 'p';
    }
    if(!strcmp(s1,s2)) puts("Yes");
    else puts("No");
    return 0;
}

### FIXED CODE ###

mp={'b':'d','d':'b','p':'q','q':'p'};a=list(input());b=list(a[::-1]);b=[mp[x] for x in b];print("Yes" if a==b else "No");
s=input()
s.sort()
if s=='abc':
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s=input()
s=''.join(sorted(s))
if s=='abc':
  print('Yes')
else:
  print('No')
i = input()
s = str(i)
l = len(s)

while num < l+1
ptint("num=" + int(s[-num]))


### FIXED CODE ###

n = input()
cur = 0

for x in n:
    cur += int(x)

if cur % 9 == 0:
    print("Yes")
else:
    print("No")
s=list(input())
q=int(input())
rev=0
for i in range(q):
    t=list(input().split())
    if t[0]=="1":
        rev=rev+1
    else:
        if t[1]=="1":
            if rev%2==0:
                s.appendleft(t[2])
            else:
                s.append(t[2])
        else:
            if rev%2==0:
                s.append(t[2])
            else:
                s.appendleft(t[2])
if rev%2==0:
    print("".join(s))
else:
    s.reverse()
    print("".join(s))



### FIXED CODE ###

from collections import deque
s=deque(list(input()))
q=int(input())
rev=0
for i in range(q):
    t=list(input().split())
    if t[0]=="1":
        rev=rev+1
    else:
        if t[1]=="1":
            if rev%2==0:
                s.appendleft(t[2])
            else:
                s.append(t[2])
        else:
            if rev%2==0:
                s.append(t[2])
            else:
                s.appendleft(t[2])
if rev%2==0:
    print("".join(s))
else:
    s.reverse()
    print("".join(s))
in = input()
key = "keyence"
for i in range(len(in)):
  for j in range(i, len(in)):
    if (in[i:j] == key):
      print("YES")
      exit
print("NO")


### FIXED CODE ###

a = input()
key = "keyence"
for i in range(len(a)):
  for j in range(i, len(a)):
    if (a[:i] + a[j:] == key):
      print("YES")
      exit(0)
print("NO")
X,Y = input().split()
X,Y = int(X),int(Y)

def d(r,n,p):#r^n mod p
    if(n==0):
        return 1
    
    elif(n%2==0):
        d_ = d(r,n//2,p)
        return (d_**2)%p
    
    else:
        d_ = d(r,(n-1),p)
        return (d_*r)%p
    
def fac(n,p):#n! mod p
    mul = 1
    for i in range(1,n+1):
        mul = (mul*i)%p
        
def r_fact_p(r,p):#(r!)^(p-2)
    mul = 1
    for i in range(1,r+1): #i^(p-2)
        mul = (mul*d(i,p-2,p))%p
        
    return mul

def C(n,r):
    return (d(r,n,p)*r_fact_p(r,p))%p



if((X-2*Y)%3 !=0 or (2*X-Y)%3 != 0):
    print(0)
    
else:
    a = (-X+2*Y)//3
    b = (2*X-Y)//3
    
    if(a<0 or b<0):
        print(0)
    else:
        
    print(C(a+b,b))

### FIXED CODE ###

p = 10 ** 9 + 7
 
def mod_inverse(a, p):
    mod = 1
    p_bin = bin(p-2)
    for i in range(len(p_bin) - 1, 1, -1):
        if i == len(p_bin) - 1:
            mul = a
            mul %= p
            mod *= (mul ** int(p_bin[i]))
            mod %= p
        else:
            mul = mul ** 2
            mul %= p
            mod *= (mul ** int(p_bin[i]))
            mod %= p
    return mod
 
def combination(n, k, p):
    a = 1
    for i in range(n, n - k, -1):
        a *= i
        a %= p
    b = 1
    for i in range(k):
        b *= (i + 1)
        b %= p
    return (a * mod_inverse(b, p)) % p

X,Y = input().split()
X,Y = int(X),int(Y)

if((X-2*Y)%3 !=0 or (2*X-Y)%3 != 0):
    print(0)
    
else:
    a = (-X+2*Y)//3
    b = (2*X-Y)//3
    if(a<0 or b<0):
        print(0)
    else:
        
        print(combination(a+b,b,p))
def ok(m,e):
    for z in range(m+1):
        if z**3 > e: return False
        for y in range(m-z+1):
            x = m-z-y
            if x + y**2 + z**3 == e: return True
    return False

while True:
    E = int(input())
    if E == 0: break
    m = 1
    while not ok(m,E):
        m += 1
    print(m)

### FIXED CODE ###

import math
while True:
    E = int(input())
    if E == 0: break
    ans = 10**10
    z = 0
    while z**3 <= E:
        y = int(math.sqrt(E - z**3))
        x = E - z**3 - y**2
        ans = min(x+y+z, ans)
        z += 1
    print(ans)
N = int(input())
L = map(int, input().split())
sort(L)
sum = 0
for i in range(0,len(L),2):
	sum += L[i]
print(sum)

### FIXED CODE ###

N = int(input())
L = [int(x) for x in input().split()]
list.sort(L)
sum = 0
for i in range(0,len(L),2):
	sum += L[i]
print(sum)
def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    _N, K = [int(x) for x in input().strip().split()]
    V = deque([int(x) for x in input().strip().split()])
    max_ans = sum([v for v in V if v > 0])

    def dfs(ans, q, V, k):
        # print(k, q, V)
        ans = max(ans, sum(q))
        if ans == max_ans:
            print(ans)
            eixt()
        if k == K:
            return ans
        if q:
            t = heapq.heappop(q)
            V.appendleft(t)
            ans = max(ans, dfs(ans, q[:], V, k+1))
            V.popleft()
            V.append(t)
            ans = max(ans, dfs(ans, q, V, k+1))
            V.pop()
            heapq.heappush(q, t)
        if V:
            q_l = q[:]
            q_r = q[:]
            t = V.popleft()
            heapq.heappush(q_l, t)
            ans = max(ans, dfs(ans, q_l[:], V, k+1))
            V.appendleft(t)
            t = V.pop()
            heapq.heappush(q_r, t)
            ans = max(ans, dfs(ans, q_r[:], V, k+1))
            V.append(t)
            
        return ans
    print(dfs(-float('inf'), [], V, 0))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    V = [int(x) for x in input().strip().split()]
    ans = -float('inf')
    for l in range(min(N, K)+1):
        for r in range(min(N, K)-l+1):
            vt = sorted(V[:l] + V[N-r:])
            c = 0
            i = 0
            for i in range(len(vt)):
                if c == (K-l-r):
                    break
                if vt[i] < 0:
                    vt[i] = 0
                    c += 1
                else:
                    break
            ans = max(ans, sum(vt))

    print(ans)

if __name__ == '__main__':
    main()
n,k = map(int,input().split())
s = list(input())
R = []
L = []
flag = 1 #1...R 0...L
lf = 1
rf = 1
if s[0]=="L":
    flag = 0
    lf = 0
if s[-1]=="L":
    rf = 0
count = 1
for i in range(n):
    if i==n-1:
        if flag==1:
            R.append(count*(-1))
            break
        else:
            L.append(count*(-1))
            break
    if s[i]==s[i+1]:
        count += 1
    elif flag==1:
        R.append(count*(-1))
        flag = 0
        count = 1
    else:
        L.append(count*(-1))
        flag = 1
        count = 1

import heapq
ans = 0
if s.count("R")>s.count("L"):
    ans += sum(R)*(-1)-len(R)
    copy_L = [x for x in L]
    heapq.heapify(L)
    for i in range(k):
        x = heapq.heappop(L)
        if lf==0 and x==copy_L[0] and copy_L.count(x)==1:
            ans += x*(-1)
        elif rf==0 and x==copy_L[-1] and copy_L.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) +1
else:
    ans += sum(L)*(-1)-len(L)
    copy_R = [x for x in R]
    heapq.heapify(R)
    for i in range(k):
        x = heapq.heappop(R)
        if lf==1 and x==copy_R[0] and copy_R.count(x)==1:
            ans += x*(-1)
        elif rf==1 and x==copy_R[-1] and copy_R.count(x)==1:
            ans += x*(-1)
        else:
            ans += x*(-1) + 1 

print(ans)

### FIXED CODE ###

n,k = [int(x) for x in input().split()]
s = input()
count = 1
for i in range(n-1):
    if s[i]!=s[i+1]:
        count += 1
print(n-max(1,count-2*k))
from sys import stdin
n, k=[int(x) for x in stdin.readlint().rstrip().split()]
if n%k == 1:
  print(1)
else:
  print(0)

### FIXED CODE ###

from sys import stdin
n, k=[int(x) for x in stdin.readline().rstrip().split()]
if n%k >= 1:
  print(1)
else:
  print(0)
def main():
    K = int(input())
    if K%2 == 0:
        return -1

    amari_sum = 0
    i = 1
    amari = 7 % K
    amari_sum += amari
    if amari == 0:
        return i

    while True:
        i += 1
        if
        amari = (amari*10) % K
        amari_sum += amari
        if amari_sum % K == 0:
            return i
        else:
            amari_sum %= K

print(main())


### FIXED CODE ###

def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while (ans <= K):
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1

    return -1


print(main())
S = str(input())
ans = 'Good'
for i in range(2):
  if S[i] == S[i+1]:
    ans = 'Bad'
Print(ans)

### FIXED CODE ###

S = str(input())
ans = 'Good'
for i in range(3):
    if S[i] == S[i+1]:
        ans = 'Bad'
print(ans)
a,b,c = int(input())
print(min(a*b,c))

### FIXED CODE ###

import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a,b,c = MAP()
print(min(a*b,c))
import numpy as np
N = int(input())
K = int(input())
win = [0]
win = np.array(win)
point = 0
for i in range(1,N+1):
  for j in range(1,K):
    if  i**j >= K:
      win[i] = (1/N)*{(1/2)**j}
      i += 1
    else:
      j += 1
ans = sum(win)
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
  j = 0
  point = i
  while point < K:
    point *= 2
    j += 1
  ans += (1/N)*(0.5**j)
print(ans)
from sys import stdin
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])

    return arr


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    X = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    X_fac = factorization(X)
    X_fac = list(set(sum(X_fac,[])))
    flag = False
    for fac in X_fac:
        A = math.ceil(fac/2)
        while True:
            B = A-fac
            if X == A**5-B**5:
                s = f'{A} {B}'
                flag == True
                break
            else:
                if A**5-B**5>X:
                    break
            A += 1
        if flag:
            break
    if flag==False:
        for fac in X_fac:
            A = math.ceil(fac/2)
            while True:
                B = A-fac
                if X == A**5-B**5:
                    s = f'{A} {B}'
                    flag == True
                    break
                else:
                    if A**5-B**5>X:
                        break
                A -= 1
            if flag:
                break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(s)


### FIXED CODE ###

from sys import stdin
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])

    return arr


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    X = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    X_fac = make_divisors(X)
    flag = False
    for fac in X_fac:
        A = math.ceil(fac/2)
        while True:
            B = A-fac
            if X == A**5-B**5:
                s = f'{A} {B}'
                flag == True
                break
            else:
                if A**5-B**5>X:
                    break
            A += 1
        if flag:
            break
    if flag==False:
        for fac in X_fac:
            A = math.ceil(fac/2)
            while True:
                B = A-fac
                if X == A**5-B**5:
                    s = f'{A} {B}'
                    flag == True
                    break
                else:
                    if A**5-B**5>X:
                        break
                A -= 1
            if flag:
                break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(s)
#ライブラリの読み込み
import math

#入力値の格納
x = int(input())

#得点の計算
score = int((x // 500 * 1000) + (x % 500 // 5 * 5))

#表示
print(score)

### FIXED CODE ###

#ライブラリの読み込み
import math

#入力値の格納
n,k = map(int, input().split())

#n進数への変換定義
def convert(x,y):
    if int(x/y):
        return convert(int(x/y),y) + str(x%y)
    return str(x%y)

#n進数へ変換し長さを算出
text = len(convert(n,k))

#結果を表示
print(text)
n, k = map(int, input().split())
As = list(map(int, input().split()))
maps = {}

for i, a in enumerate(As):
    maps[i] = a - 1

probs = [0] * n
p = 0  # 現在位置
target = 0  # はじめて2回出現する場所
h = 0  # ターゲットの初回出現時のワープ回数
t = 0  # ターゲットの2回目の出現時のワープ回数

if (map(0) == 0):
    print(1)
    exit

# はじめて2回出現する場所(target)と、その時点でのワープ回数を取得
for i in range(n):
    probs[p] += 1
    if (probs[p] == 2):
        target = p
        t = i
        break
    p = maps[p]

# 初回出現位置を取得(めんどうくさいのでもう一回回した。)
p = 0
for i in range(n):
    if (p == target):
        h = i
        break
    p = maps[p]

s = t - h  # 周期
d = (k - h) % s  # targetに到着後にワープすべき回数

# 実際に必要な回数だけワープ
p = 0
for i in range(h + d):
    p = maps[p]

print(p + 1)


### FIXED CODE ###

n, k = map(int, input().split())
As = list(map(int, input().split()))
maps = {}

for i, a in enumerate(As):
    maps[i] = a - 1

probs = [0] * n
p = 0  # 現在位置
target = 0  # はじめて2回出現する場所
h = 0  # ターゲットの初回出現時のワープ回数
t = 0  # ターゲットの2回目の出現時のワープ回数

# はじめて2回出現する場所(target)と、その時点でのワープ回数を取得
for i in range(n + 1):
    probs[p] += 1
    if (probs[p] == 2):
        target = p
        t = i
        break
    p = maps[p]

# 初回出現位置を取得(めんどうくさいのでもう一回回した。)
p = 0
for i in range(n):
    if (p == target):
        h = i
        break
    p = maps[p]

s = t - h  # 周期
if (k <= h):
    p = 0
    for i in range(k):
        p = maps[p]
    print(p + 1)
    exit()

d = (k - h) % s  # targetに到着後にワープすべき回数

# 実際に必要な回数だけワープ
p = 0
for i in range(h + d):
    p = maps[p]

print(p + 1)
def t_check(a,b,c):
    if a + b > c:
        if b + c > a:
            if a + c > b: return True
    return False

def f_check(a_, b_, c_):
    tmp = []
    tmp.append(a_)
    tmp.append(b_)
    tmp.append(c_)
    sqrts = []
    for i in range(3):
        sqrts.append(tmp[i]**2)
    m = max(sqrts)
    s = sum(sqrts)

    if m == (s - m): return(0)
    if m > (s - m): return(2)
    if m < (s - m): return(1)
    
counter=[0,0,0]
    
while(1):
    input_f = input()

    t = input_f.split("\n").split()
    fn, sn, tn = int(t[0]),int(t[1]),int(t[2])
    if t_check(fn,sn,tn):
        counter[f_check(fn,sn,tn)] += 1
    else: break
    
print(sum(counter),counter[0], counter[1], counter[2])


### FIXED CODE ###

def t_check(a,b,c):
    if a + b > c:
        if b + c > a:
            if a + c > b: return True
    return False

def f_check(a_, b_, c_):
    tmp = []
    tmp.append(a_)
    tmp.append(b_)
    tmp.append(c_)
    sqrts = []
    for i in range(3):
        sqrts.append(tmp[i]**2)
    m = max(sqrts)
    s = sum(sqrts)

    if m == (s - m): return(0)
    if m > (s - m): return(2)
    if m < (s - m): return(1)
    
counter=[0,0,0]
    
while(1):
    input_f = input()

    t = input_f.split()
    fn, sn, tn = int(t[0]),int(t[1]),int(t[2])
    if t_check(fn,sn,tn):
        counter[f_check(fn,sn,tn)] += 1
    else: break
    
print(sum(counter),counter[0], counter[1], counter[2])
import numpy as np
import sys
input = sys.stdin.readline


def get_primes(a=10**6):
    table = np.ones(a+1)
    table[:2] = False
    for i in range(2, a):
        table[i+i::i] = False
    primes = np.where(table==True)[0]
    return primes


def main():
    n = int(input())
    A = np.array(input().split(), dtype=np.int64)
    primes = get_primes(A.max())

    if A.max() == 1:
        print("pairwise coprime")

    fact_counts = (A.reshape([1, -1]) % primes.reshape([-1, 1])) == 0
    print(1)
    return
    if count == 1:
        print("pairwise coprime")
    elif count != n:
        print("setwise coprime")
    else:
        print("not coprime")


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))

    counts = [0] * (10**6 + 1)
    for a in A:
        counts[a] += 1

    ans = 1
    for i in range(2, 10**6+1):
        co_primes = 0
        for j in range(i, 10**6+1, i):
            co_primes += counts[j]
        if ans < co_primes:
            ans = co_primes

    if ans == 1:
        print("pairwise coprime")
    elif ans < n:
        print("setwise coprime")
    else:
        print("not coprime")


if __name__ == "__main__":
    main()
n,k=map(int,input().split())
li=list(map(int,input().split()))
val=int(pow(10,9))
dp=[val]*(n+1)
dp[1]=0


for i in range(1,n+1):
  for j in range(1,k+1):
    if i-j>=1:
      dp[i]=min(dp[i],dp[i-j]+abs(li[i-1]-li[i-j-1]))


     

    
print(dp[n])

  


### FIXED CODE ###

n=int(input())
li=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=dp[1]+abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min((dp[i-1]+abs(li[i]-li[i-1])),dp[i-2]+abs(li[i]-li[i-2]))
print(dp[n-1])