Harryxun/stf_run huggingface dataset:
from heapq import heappop,heappush
n = int(input())
A = sorted(list(map(int,input().split())))
P = []
M = []
for a in A:
    if a>=0:
        P.append(a)
    else:
        M.append(a)

if A[-1]>=0 and A[0]<=0:
    print(sum(abs(a) for a in A))
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
elif A[0]>=0:
    print(sum(A)-min(A)*2)
    mm = heappop(P)
    pp = heappop(P)
    print(mm,pp)
    heappush(M,mm-pp)
    while len(P) != 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
else:
    print(sum(abs(a) for a in A)+max(A)*2)
    mm = M[-1]
    pp = M[-2]
    print(mm,pp)
    M = M[:-2]
    heappush(P,mm-pp)
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)

### FIXED CODE ###

from heapq import heappop,heappush
n = int(input())
A = sorted(list(map(int,input().split())))
P = []
M = []
if n == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    exit()
def move():
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
for a in A:
    if a>=0:
        P.append(a)
    else:
        M.append(a)

if A[-1]>=0 and A[0]<0:
    print(sum(abs(a) for a in A))
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
elif A[0]>=0:
    print(sum(A)-min(A)*2)
    mm = heappop(P)
    pp = heappop(P)
    print(mm,pp)
    heappush(M,mm-pp)
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
else:
    print(sum(abs(a) for a in A)+max(A)*2)
    mm = M[-1]
    pp = M[-2]
    print(mm,pp)
    M = M[:-2]
    heappush(P,mm-pp)
    while len(P)!= 1:
        mm = heappop(M)
        pp = heappop(P)
        print(mm,pp)
        heappush(M,mm-pp)
    while len(M) != 0:
        mm = heappop(M)
        pp = heappop(P)
        print(pp,mm)
        heappush(P,pp-mm)
import math
R = input 
return 2*R*math.pi

### FIXED CODE ###

import math
R = int(input())
a = 2*math.pi*R
print(a)
p=list(map(int,input().split()))
count=1
for item in p:
  if item==0:
    return count
  else:
    count+=1
    
  


### FIXED CODE ###

p=list(map(int,input().split()))
count=1
for item in p:
  if item==0:
    print(count)
  else:
    count+=1
    continue
N, D = map(int, input().split())
ans = 0
for i in range(n):
  x, y = map(int, input().split())
  if (x**2+y**2) <= D**2:
    ans +=1
  else:
    ans +=0

print(ans)

### FIXED CODE ###

n,d = map(int,input().split())
num = 0
for i in range(n):
  x,y = map(int,input().split())
  if (x**2 + y**2) <= d**2:
    num += 1
  else:
    num += 0
print(num)
a,b = int(input().split())

count = 0

if a > b :
  count += a
  a -= 1
else:
  count += b
  b -= 1
  
if a > b :
  count += a
  a -= 1
else:
  count += b
  b -= 1
  
print(count)
  

### FIXED CODE ###

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

count = 0

if a > b :
  count += a
  a -= 1
else:
  count += b
  b -= 1

if a > b :
  count += a
  a -= 1
else:
  count += b
  b -= 1
  
print(count)
abc171c
n=int(input())
s=''
while n:
 n-=1
 s+=chr(n%26+97)
 n//=26
print(s[::-1])


### FIXED CODE ###

#abc171c
n=int(input())
s=''
while n:
 n-=1
 s+=chr(n%26+97)
 n//=26
print(s[::-1])
tep = input()
if tep>=30:
  print('Yes')
else :
  print('No')

### FIXED CODE ###

temp = input()
temp = int(temp)
if temp<-40 or temp>40:
    print('Out')    
elif temp >=30: 
    print('Yes')
else:
    print('No')
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

sumls =[0]*(N+1)
for i in range (N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        sumls[i+1] = sumls[i] + 1
    else:
        sumls[i+1] = sumls[i]

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sum(sumls[r-1]-sumls[l-1])
    print(ans)






### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

N,Q = [int(x) for x in input().split()]
S = list(input())
lrlist =[]
for _ in range(Q):
    l,r = [int(x) for x in input().split()]
    lrlist.append((l,r))

sumls =[0]*(N+1)
for i in range (N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        sumls[i+1] = sumls[i] + 1
    else:
        sumls[i+1] = sumls[i]

for _ in range (Q):
    l = lrlist[_][0]
    r = lrlist[_][1]
    ans = sumls[r-1]-sumls[l-1]
    print(ans)
H,W = map(int, input().split())
A = [input() for _ in range(H)]
HMANY = [ [10**9] * W for _ in range(H)]


def dfs(h,w,A,HMANY, num):
    if not ( 0<= h < H and 0 <= w < W) : 
        return
    if HMANY[h][w] > num:
        HMANY[h][w] = num        
        if 0 <= h-1 :
            dfs(h-1,w,A,HMANY,num+1 )
        if h+1 < H:
            dfs(h+1,w,A,HMANY,num+1 )
        if w+1 < W:
            dfs(h,w+1,A,HMANY,num+1 )
        if 0<=w-1:
            dfs(h,w-1,A,HMANY,num+1 )

for h in range(H):
    for w in range(W):
        # if HMANY[h][w] == 10**9:
            if A[h][w] == "#":
                dfs(h,w, A,HMANY, 0)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, HMANY[h][w])
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque
from heapq import heappush, heappop
def solve():
    H,W = map(int, input().split())
    A = [ list(input()) for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]

    
    
    # q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                HMANY[h][w] = 0
    for w in range(W):
        for h in range(H-1):
            if HMANY[h][w]+1 < HMANY[h+1][w]:
                HMANY[h+1][w] = HMANY[h][w] + 1
        for h in range(H-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h-1][w]:
                HMANY[h-1][w] = HMANY[h][w] + 1
    
    for h in range(H):
        for w in range(W-1):
            if HMANY[h][w]+1 < HMANY[h][w+1]:
                HMANY[h][w+1] = HMANY[h][w] + 1
        for w in range(W-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h][w-1]:
                HMANY[h][w-1] = HMANY[h][w] + 1        
    #             q.append((h,w))
    #             A[h][w] = "."
    # ans = 0
    # while q:
    #     nextQ = deque()
    #     for h,w in q:
    #         A[h][w] = "#"
    #         if h+1 <H and A[h+1][w] == ".":
    #             nextQ.append( (h+1,w))
    #         if w+1 <W and A[h][w+1] == ".":
    #             nextQ.append((h,w+1))
    #         if 0<=h-1 and A[h-1][w] == ".":
    #             nextQ.append((h-1,w))
    #         if 0<=w-1 and A[h][w-1] == ".":
    #             nextQ.append((h,w-1))        
    #     ans += 1
    #     q = nextQ
        # num,h,w = q.popleft()        
        # if HMANY[h][w] > num and A[h][w] == ".":
        #     HMANY[h][w] = num
        #     A[h][w] = "#"
        #     if h+1 <H and A[h+1][w] == ".":
        #         q.append( (num+1,h+1,w))
        #     if w+1 <W and A[h][w+1] == ".":
        #         q.append((num+1,h,w+1))
        #     if 0<=h-1 and A[h-1][w] == ".":
        #         q.append((num+1,h-1,w))
        #     if 0<=w-1 and A[h][w-1] == ".":
        #         q.append((num+1,h,w-1))

    ans = 0
    for h in range(H):
        ans = max(ans, max(HMANY[h]))
    # print(ans-1)
    print(ans)

if __name__ == "__main__":
    solve()
Matches = {num: c for num, c in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 5, 5, 4, 5, 6, 3, 7, 6])}


def solve(N, M, As):
    dp = [-1 for _ in range(N + 1)]
    dp[0] = 0
    As = sorted(As, reverse=True)
    for i in range(N + 1):
        for a in As:
            c = Matches[a]
            if dp[i - c] == -1:
                continue
            if 0 <= i - c:
                dp[i] = max(dp[i],
                            dp[i - c] * 10 + a)
    return dp[N]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, M, As))


### FIXED CODE ###

Matches = {num: c for num, c in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 5, 5, 4, 5, 6, 3, 7, 6])}


def solve(N, M, As):
    dp = [-1 for _ in range(N + 1)]
    dp[0] = 0
    for a in sorted(As, reverse=True):
        c = Matches[a]
        for i in range(N - c + 1):
            if dp[i] == -1:
                continue
            dp[i + c] = max(dp[i+c],
                            dp[i] * 10 + a)
    return dp[N]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, M, As))
import sys
args = sys.stdin.readlines():
n, m = map(int, args[0].split(' '))
gates = []
for gate in args[1:]:
  l, r = map(int, gate.split(' '))
  gates.append((l, r))
  
ids = gates[0]
for gate in gates[1:]:
  l, r = gate
  ids = [x for x in ids in range(l, r+1)]
  
print(len(ids))

### FIXED CODE ###

import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)
n = int(input())
li1 = list(map(int,inpout().split()))
li2 = []
count = 0
for i in range(n):
    li2.append(i+1)
for i in range(n):
    if li1[i] != li2[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

n = int(input())
li1 = list(map(int,input().split()))
li2 = []
count = 0
for i in range(n):
    li2.append(i+1)
for i in range(n):
    if li1[i] != li2[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")
def solve(a, m): 
    if len(a) == 0:
        if m == 0:
            return True
        else:
            return False
    else:
        if solve(a[1:], m - a[0]):
            return True
        else:
            return solve(a[1:], m)

n = int(input())
tmp = input().split()
a = []
for i in range(n):
    a.append(int(tmp[i]))
q = int(input())
tmp = input().split()
m = []
for i in range(q):
    m.append(int(tmp[i]))

for i in range(q):
    if solve(a, m[i]):
        print("yes")
    else:
        print("no")



### FIXED CODE ###

def solve(a, m, sumA):
    if m < 0 or m > sumA:
        return False
    if m == 0:
        return True
    if len(a) == 0:
        return False
    return solve(a[1:], m - a[0], sumA) or solve(a[1:], m, sumA)

n = int(input())
tmp = input().split()
a = []
for i in range(n):
    a.append(int(tmp[i]))
q = int(input())
tmp = input().split()
m = []
for i in range(q):
    m.append(int(tmp[i]))

sumA = sum(a)

for i in range(q):
    if solve(a, m[i], sumA):
        print("yes")
    else:
        print("no")
print('Odd' if eval(input().replace("",'*')%2) else 'Even')

### FIXED CODE ###

print('Odd' if eval(input().replace(" ",'*'))%2 else 'Even')
swap_count = 0


def main():
  num = int(input())
  elements = []
  for i in range(0, num):
    elements.append(int(input()))

  # Get intervals
  interval = 1
  intervals = [interval]
  while True:
    interval = int_f(interval)
    if interval > num:
      break
    intervals.insert(0, interval)

  for interval in intervals:
    insertion_sort(elements, num, interval)

  print(len(intervals))
  print(' '.join([str(interval) for interval in intervals]))
  print(swap_count)
  for val in elements:
    print(val)


def int_f(x):
  return 2.25 * x + 1


def insertion_sort(elements, num, interval=1):
  global swap_count

  i = interval
  while i < num:
    j = i
    while interval <= j:
      if elements[j - interval] <= elements[j]:
        break

      elements[j - interval], elements[j] = elements[j], elements[j - interval]
      swap_count += 1
      j -= interval
    i += 1


if __name__ == '__main__':
  main()

### FIXED CODE ###

import math


swap_count = 0


def main():
  num = int(input())
  elements = []
  for i in range(0, num):
    elements.append(int(input()))

  # Get intervals
  interval = 1
  intervals = [interval]
  while True:
    interval = int_f(interval)
    if interval > num:
      break
    intervals.insert(0, math.ceil(interval))

  for interval in intervals:
    insertion_sort(elements, num, interval)

  print(len(intervals))
  print(' '.join([str(interval) for interval in intervals]))
  print(swap_count)
  for val in elements:
    print(val)


def int_f(x):
  return 2.25 * x + 1


def insertion_sort(elements, num, interval=1):
  global swap_count

  i = interval
  while i < num:
    j = i
    while interval <= j:
      if elements[j - interval] <= elements[j]:
        break

      elements[j - interval], elements[j] = elements[j], elements[j - interval]
      swap_count += 1
      j -= interval
    i += 1


if __name__ == '__main__':
  main()
a = raw_input() . split()

S = a[0] * a[1]
O = 2 * (a[0] + a[1])

print S
print O

### FIXED CODE ###

a , b= map(int,raw_input(). split())
S = a * b
O = 2 * a + 2 * b

print str(S) + ' ' +  str(O)
tmp = input()
N = int(tmp.split()[0])
M = int(tmp.split()[1])
A = []
B = []
for i in range(N):
	tmp = input()
	A[i] = int(tmp.split()[0])
	B[i] = int(tmp.split()[1])

minv = 100000000000
cnt=0
total=0
while cnt < M:
	mini = N
	for i in range(N):
		if minv > A[i]:
			minv = A[i]
			mini = i
	cnt += B[mini]
	total = A[mini]*B[mini]
	A[mini] = 1000000000000
total -= minv*(cnt-M)
print(total)

### FIXED CODE ###

tmp = input()
N = int(tmp.split()[0])
M = int(tmp.split()[1])
AB = []
for i in range(N):
	tmp = input()
	AB.append([int(tmp.split()[0]),int(tmp.split()[1])])

AB.sort()

cnt=0
total=0
i = 0
while cnt < M:
	cnt += AB[i][1]
	total += AB[i][0]*AB[i][1]
	i+=1
total -=  AB[i-1][0]*(cnt-M)
print(total)
# import sys
sys.setrecursionlimit(30000)
x,y = map(int, input().split())

dp = [[-1]*(x+1) for i in range(y+1)]
# dp[1][2]=1
# dp[2][1]=1
# dp[1][1]=0
# dp[1][0]=0
# dp[0][1]=0

def f(x,y):
    if (x,y)==(1,2):
        dp[y][x]=1
        return 1
    elif (x,y)==(2,1):
        dp[y][x]=1
        return 1
    elif (x,y)==(1,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(0,1):
        dp[y][x]=0
        return 0
    elif (x,y)==(1,0):
        dp[y][x]=0
        return 0
    else:
        if dp[y][x]==-1:
            dp[y][x]=f(x-1,y-2)+f(x-2,y-1)
        return dp[y][x]

print(dp[y][x]%(10**9+7))


### FIXED CODE ###

# import math
# from operator import mul
# from functools import reduce
x,y = map(int, input().split())
n = (x+y)//3
r = (2*x-y)//3
mod = 10**9+7
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if (x+y)%3!=0:
    print(0)
elif 2*x-y<0:
    print(0)
elif -x+2*y<0:
    print(0)
else:
    # print((math.factorial((x+y)//3)//(math.factorial((2*x-y)//3)*math.factorial((2*y-x)//3)))%mod)
    # print(combinations_count(n,r)%mod)
    print(cmb(n,r,mod))
import sys
rline = sys.stdin.readline

N = int(rline())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, rline().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
to_k = [0] * N


def dfs(node, parent, dist):
    to_k[node] = dist
    
    for child, d in graph[node]:
        if child != parent:
            dfs(child, node, dist + d)


def solve():
    Q, K = map(int, rline().split())
    K -= 1
    dfs(K, -1, 0)
    for _ in range(Q):
        x, y = map(lambda z: int(z) - 1, rline().split())
        print(to_k[x] + to_k[y])


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
rline = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(rline())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, rline().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
to_k = [0] * N


def dfs(node, parent, dist):
    to_k[node] = dist
    
    for child, d in graph[node]:
        if child != parent:
            dfs(child, node, dist + d)


def solve():
    Q, K = map(int, rline().split())
    K -= 1
    dfs(K, -1, 0)
    for _ in range(Q):
        x, y = map(lambda z: int(z) - 1, rline().split())
        print(to_k[x] + to_k[y])


if __name__ == '__main__':
    solve()
n = int(input())
l = list(n)
if l[0] == 9 or l[1] == 9:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n = input()
l = list(n)
if l[0] == "9" or l[1] == "9":
    print("Yes")
else:
    print("No")
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math


#N,K=map(int,input().split())
N=int(input())
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]


def segfunc(x,y):
    return (x|y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,b):
    k += num-1
    if seg[k].pop()==b:
        return()
    seg[k].add(b)
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele =set()

#num:n以上の最小の2のべき乗
n=N
num =2**(n-1).bit_length()
seg=[set() for i in range(2*num)]

for i in range(N):
    update(i,S[i])

for type,i,c in Query:

    if type=="1":
        update(int(i)-1,c)
    else:
        print(len(query(int(i)-1,int(c))))
    #print(seg)


### FIXED CODE ###

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math


#N,K=map(int,input().split())
N=int(input())
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]

def segfunc(x,y):
    return (x|y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=seg[2*i+1]|seg[2*i+2]

def update(k,b):
    k += num-1
    if seg[k]=={b}:
        return ()
    seg[k] = {b}
    while k:
        k = (k-1)>>1
        seg[k] = seg[k*2+1]|seg[k*2+2]

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=set()
    while q-p>1:
        if p&1 == 0:
            res = res|seg[p]
        if q&1 == 1:
            res = res|seg[q]
            q -= 1
        p = p>>1
        q = (q-1)>>1
    if p == q:
        res = res|seg[p]
    else:
        res = res|seg[p]|seg[q]
    return res

#num:n以上の最小の2のべき乗
n=N
num =2**(n-1).bit_length()
seg=[set()] * (2*num)

for i in range(N):
    seg[i+num-1]={ord(S[i])}
for k in range(num-2,-1,-1):
    seg[k] = seg[k*2+1]|seg[k*2+2]
for type, i, c in Query:
    if type=="1":
        update(int(i)-1,ord(c))
    else:
        print(len(query(int(i)-1,int(c))))
    #print(seg)
N = int(input())
S, T  = input().split()

S_list = list(S)
T_list = list(T)
U_list = []
for i in range(N):
    U_list.append(S_list[i])
    U_list.append(T_list[i])

U = ''.join(U_list)
print(U_list)

### FIXED CODE ###

l1 = [1,2,3]
l2 = [int(input()) for i in range(2)]
ans = list(set(l1) - set(l2))
print(ans[0])
import sys
n,k = list(map(int,sys.stdin.readline().split()))
arr = list(map(int,sys.stdin.readline().split()))

dp = [sys.maxsize 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(arr[i]-arr[j]))
sys.stdout.write(str(dp[-1]+'\n'))

### FIXED CODE ###

import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

dp = [sys.maxsize 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(arr[i]-arr[j]))
print(dp[-1])
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)

### FIXED CODE ###

from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)
while True:
    x = input()
    if x == 0:
        break
    sum = 0
    while x != 0:
        sum += x%10
        x = x//10

    print(sum)

### FIXED CODE ###

while True:
    x = int(input())
    if x == 0:
        break
    sum = 0
    while x != 0:
        sum += x%10
        x = x//10

    print(sum)
print(input()**2)

### FIXED CODE ###

s = int(input())

print(s*s)
A, B, C, X = map(int, input().split())

count = 0
for a in range(A+1):
  for b in range(B+1):
     for c in range(C+1):
        if a+b+c= X:
          count += 1

print(count)

### FIXED CODE ###

a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)
x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x==0:
    if y < 0:
        print(1-y)
    else:
        print(y)
elif x > 0:
    if abs(y) < x:
        print(1+y+x)
    else:
        if y > 0:
            print(y-x)
        else:
            print(y-x)+1
else:
    if abs(y) <x:
        print(y-x)
    else:
        if y >=0:
            print(y-x)
        else:
            print(2+x-y)
            

### FIXED CODE ###

x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x==0:
    if y < 0:
        print(1+abs(y))
    else:
        print(abs(y))
elif x > 0:
    if abs(y) < x:
        if y == 0:
            print(1+y+x)
        elif y>0:
            print(abs(abs(y)-abs(x))+2)
        else:
            print(y+x+1)
    else:
        if y > 0:
            print(y-x)
        else:
            print(abs(y)-x+1)
else:
    if abs(y) <abs(x):
        if y >0 :
            print(1+abs(abs(x)-abs(y)))
        elif y==0:
            print(abs(x))
        else:
            print(abs(-x+y))
    else:
        if y >0:
            print(1+y+x)
        else:
            print(2+x-y)
def main():
  n = int(input())
  print(n * (n-1) // 2)
 

main()

### FIXED CODE ###

a = input()
b = input()
score = 0

for i in range(3):
  if a[i] == b[i]:
    score+=1

print(score)
# list に入力を格納
list = list(int, input().split())
# 小さい順に並び替え
list.sort()

if list[0] == 5 and list[1] == 5 and list[7] == 7:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

# list に入力を格納
list = list(map(int, input().split()))
# 小さい順に並び替え
list.sort()

if list[0] == 5 and list[1] == 5 and list[2] == 7:
    print('YES')
else:
    print('NO')