Harryxun/stf_run huggingface dataset:
INF = 10**9

n, k = list(map(int, input().split(' ')))
hs = list(map(int, input().split(' ')))

dp = [INF] * (n + 10000 * k)
dp[0] = 0

for i in range(1, n):
    a = INF
    hsi = hs[i]
    for m in range(1, k + 1):
        j = i - m
        v = dp[j] + abs(hs[j] - hsi)
        if a > v:
            a = v
    dp[i] = a
print(dp[n - 1])


### FIXED CODE ###

n, k = list(map(int, input().split(' ')))

hs = list(map(int, input().split(' ')))

dp = [float('inf')] * (n + k + 1)
dp[0] = 0

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

print(dp[n - 1])
ans_list = []
def make_pieces(w, d, s):
    s %= (2 * w + 2 * d)
    while True:
        if w > s:
            return [s, d], [w - s, d]
        s -= w
        if d > s:
            return [w, s], [w, d - s]
        s -= d
        if w > s:
            return [w - s, d], [s, d]
        s -= w
        if d > s:
            return [w, s], [w, d - s]
        s -= d


while True:
    n, w, d = map(int, input().split())
    P = [[w, d]]
    if n == 0 and w == 0 and d == 0:
        break
    for i in range(n):
        p, s = map(int, input().split())
        new_pieces = make_pieces(P[p - 1][0], P[p - 1][1], s)
        #print(new_pieces)
        if new_pieces[0][0] * new_pieces[0][1] < new_pieces[1][0] * new_pieces[1][1]:
            P = P[:p - 1] + [new_pieces[0]] + [new_pieces[1]] + P[p:]
        else:
            P = P[:p - 1] + [new_pieces[1]] + [new_pieces[0]] + P[p:]
        #print(P)

    S_list = []
    for i in P:
        S_list.append(i[0] * i[1])

    S_list.sort()
    ans_list.append(S_list)

for i in range(len(ans_list)):
    I = ans_list[i]
    for j in range(len(I)):
        J = I[j]
        if i == len(ans_list) - 1 and j == len(I) - 1:
            print(J, end = "")
        else:
            print(J, end = " ")
    print()


### FIXED CODE ###

ans_list = []
def make_pieces(w, d, s):
    if w == 0 and d == 0:
        print(w, d, s)
    s %= (2 * w + 2 * d)
    while True:
        if w > s:
            return [s, d], [w - s, d]
        s -= w
        if d > s:
            return [w, s], [w, d - s]
        s -= d
        if w > s:
            return [w - s, d], [s, d]
        s -= w
        if d > s:
            return [w, s], [w, d - s]
        s -= d


while True:
    n, w, d = map(int, input().split())
    P = [[w, d]]
    if n == 0 and w == 0 and d == 0:
        break
    for i in range(n):
        p, s = map(int, input().split())
        new_pieces = make_pieces(P[p - 1][0], P[p - 1][1], s)
        #print(new_pieces)
        if new_pieces[0][0] * new_pieces[0][1] < new_pieces[1][0] * new_pieces[1][1]:
            P = P[:p - 1] + P[p:] + [new_pieces[0]] + [new_pieces[1]]
        else:
            P = P[:p - 1] + P[p:] + [new_pieces[1]] + [new_pieces[0]]
        #print(P)

    S_list = []
    for i in P:
        S_list.append(i[0] * i[1])

    S_list.sort()
    ans_list.append(S_list)

for i in range(len(ans_list)):
    I = ans_list[i]
    for j in range(len(I)):
        J = I[j]
        if j == len(I) - 1:
            print(J, end = "")
        else:
            print(J, end=" ")
    print()
a, b = mao(int,input().split())
if a <= b:
  print(a)
else:
  print(a-1)

### FIXED CODE ###

a, b = map(int,input().split())
if a <= b:
  print(a)
else:
  print(a-1)
import math
A,B,H,M = map(int,input().split())
a = 30*H + 0.5*M
b = M*6
if abs(a-b) < 180:
    ab = abs(a-b)
else:
    ab = abs(360-a-b)
ab1 = round(math.cos(math.radians(ab)),20)
ans = round(math.sqrt(A**2 + B**2 - 2 * A* B*ab1),20)
print(round(ans,10)

### FIXED CODE ###

import math
A,B,H,M = map(int,input().split())
a = 30*H + 0.5*M
b = M*6
if abs(a-b) < 180:
    ab = abs(a-b)
else:
    ab = 360 - abs(a-b)
ab1 = round(math.cos(math.radians(ab)),20)
ans = round(math.sqrt(A**2 + B**2 - 2 * A* B*ab1),20)
print(round(ans,20))
from collections import defaultdict
from math import gcd

def main():
    n = int(input())
    mod = 1000000007
    zeroes = 0
    quad1 = defaultdict(int)
    quad2 = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        g = gcd(a, b)
        a //= g; b//= g

        if a == b == 0:
            zeroes += 1
            continue
        
        if b < 0:
            a, b = -a ,-b
        
        if a <= 0:
            a, b = b, -a
            quad1[(a,b)] += 0
            quad2[(a,b)] += 1
        else:
            quad1[(a,b)] += 1
            quad2[(a,b)] += 0

    ans = 1
    for k, v in quad1.items():
        now = 1
        now += pow(2, v, mod) -1
        now += pow(2, quad2[k], mod) -1
        ans = ans * now % mod
    
    ans += (zeroes - 1)
    print (ans % mod)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict
import math


def main():
    n = int(input())
    mod = 1000000007
    zeroes = 0
    counter1 = defaultdict(int)
    counter2 = defaultdict(int)
    for _ in range(n):
        x, y = [int(x) for x in input().split()]

        if x == y == 0:
            zeroes += 1
            continue

        denominator = math.gcd(x, y)
        x, y = x // denominator, y // denominator

        if y < 0:
            # quadrant III, IV -> I, II
            x, y = -x, -y

        if x <= 0:
            # round 90° from quadrant II to I
            x, y = y, -x
            counter2[(x, y)] += 1
            counter1[(x, y)] += 0
        else:
            counter1[(x, y)] += 1
            counter2[(x, y)] += 0

    ans = 1
    for k, v in counter1.items():
        now = 1
        now += pow(2, v, mod) - 1
        now += pow(2, counter2[k], mod) - 1
        ans = ans * now % mod
    ans += zeroes
    ans -= 1  # choose no fish
    return ans % mod


if __name__ == '__main__':
    print(main())
from collections import Counter

n = int(raw_input())
c = Counter(map(int, raw_input().split()))
s = 0
for k,v in c:
    if v < k:
        s += v
    else:
        s += v - k
print s


### FIXED CODE ###

from collections import Counter

n = int(raw_input())
c = Counter(map(int, raw_input().split()))
s = 0
for k,v in c.items():
    if v < k:
        s += v
    else:
        s += v - k
print s
import math
import sys

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

if s[0] != t[0]:
	print(-1)
	sys.exit()

GCD = math.gcd(n,m)

if GCD == 1:
	print(n*m)
	sys.exit()

LCM = n*m//GCD


s_k = LCM//m
t_k = LCM//n
for i in range(GCD):
	if s[i*s_k] != t[i*t_k]:
		print(-1)
		sys.exit()

print(LCM)

### FIXED CODE ###

import math
import sys

def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)


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

if s[0] != t[0]:
	print(-1)
	sys.exit()

GCD = gcd(n,m)

if GCD == 1:
	print(n*m)
	sys.exit()

LCM = n*m//GCD


s_k = LCM//m
t_k = LCM//n
for i in range(GCD):
	if s[i*s_k] != t[i*t_k]:
		print(-1)
		sys.exit()

print(LCM)
import math
n = int(input())
l = list(int(input()) for _ in range(n))
ans = l[0]
for i in range(1, n):
    ans = ans * l[i] // math.gcd(ans, l[i])

print(ans)

### FIXED CODE ###

import fractions
N = int(input())
T = list(int(input()) for _ in range(N))
ans = T[0]
for i in range(1, N):
    ans = ans * T[i] // fractions.gcd(ans, T[i])
print(ans)
XKD=list(input().split(' '))
X=int(XKD[0])
K=int(XKD[1])
D=int(XKD[2])
AX=abs(X)

if AX>K*D:
    print(AX-K*D)
else:
    K2=AX//D
    if (K-K2)%2==0:
        P=AX-K2*D
    else:
        P=abs(AX-(K2+1)*D)
print(P)

### FIXED CODE ###

XKD=list(input().split(' '))
X=int(XKD[0])
K=int(XKD[1])
D=int(XKD[2])
AX=abs(X)

if AX>K*D:
    print(AX-K*D)
else:
    K2=AX//D
    if (K-K2)%2==0:
        P=AX-K2*D
        print(P)
    else:
        P=abs(AX-(K2+1)*D)
        print(P)
import math
n=int(input())
li = [int(input()) for i in range(n)]
li.sort()

a=math.gcd(li[0],li[1])
b=li[0]*li[1]/a
c=a

for i in range(n-2):
  a=math.gcd(li[i+2],a)
  b=li[i+2]*c/a
  c=a

b=int(b)

print(b)

### FIXED CODE ###

a=int(input())
li = [int(input()) for i in range(a)]
li.sort()

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


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

ans=li[0]
for i in range(a-1):
  if ans<=li[i+1]:
    ans=lcm(ans,li[i+1])
  else:
    ans=lcm(li[i+1],ans)

print(int(ans))
n,k=map(int,input().split())
List=list(map(int,input().split()))


li = []

for i in range(n):
    count=0
    for j in range(n):
        if List[i]>List[j]:
            count += 1
    li.append(count)
print(str(sum(li))+"li")


count2=0

for i in range(1,n):
    for j in range(i+1,n+1):
        #print(i,j)
        if int(List[i-1]) > int(List[j-1]):
            count2 += 1
    #print(str(count2)+"count2")


for m in range(k,0,-1):
    counted=count2+count2*(m-1)




ans = counted % 1000000007
print(ans)

### FIXED CODE ###

m,d=map(int,input().split())
count = 0

if d >= 22:

    for mm in range(1,m+1,1):
        
        for dd in range (22,d+1):
            dd = str(dd)
            d10 = int(dd[0])
            d1 = int(dd[1])
            
            if d1>=2 and mm == d1*d10 :
                count +=1
print(count)
N=int(input())

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

x=[]
y=[]

for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(i+1,N):
        a=x[i]-x[j]
        b=y[i]-y[j]
        if a<=0 and b>=0:
            a=-a
            b=-b
        elif a<=0 and b<=0:
            a=-a
            b=-b
        #l1.append(str(a)+"_"+str(b))
        l1.append([a,b])
v=set(l1)
c=[]
for i in v:
    c.append(l1.count(i))
#c = collections.Counter(l1)      
#values, counts = zip(*c.most_common())    
print(N-max(c))


        


### FIXED CODE ###

N=int(input())

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

x=[]
y=[]

for X,Y in XY:
    x.append(X)
    y.append(Y)
    
l1=[]
c=0
for i in range(N):
    for j in range(N):
        if i==j:
            continue;
        a=x[i]-x[j]
        b=y[i]-y[j]
        """
        if a<=0 and b>=0:
            a=-a
            b=-b
        elif a<=0 and b<=0:
            a=-a
            b=-b
        """
        l1.append(str(a)+"_"+str(b))
        #l1.append([a,b])
v=set(l1)
c=[]
for i in v:
    c.append(l1.count(i))
#c = collections.Counter(l1)      
#values, counts = zip(*c.most_common()) 
if c==[]:
    print(1)   
else:
    print(N-max(c))
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
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)

    return divisors

def solve():
    N = II()
    A = LI()

    cost = {}
    for a in A:
        if cost.get(a, -1) == -1:
            cost[a] = 1
        else:
            cost[a] = 0

    A = sorted(A)

    memo = {}
    ans = 0
    for a in A:
        divs = make_divisors(a)
        for d in divs:
            if memo.get(d, -1) != -1:
                break
        else:
            ans += cost[a]
        memo[a] = 1
    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = X
    if P == []:
        print(ans)
        return

    #
    # P = [i for i in range(1, 99)]
    # N = 100
    # X = 50

    mn = INF
    for i in range(X-110, X+110):
        # if i == X: continue
        if i not in P:
            if mn > abs(X - i):
                mn = abs(X - i)
                ans = i
            # print(i, abs(X - i), ans)
    print(ans)

if __name__ == '__main__':
    solve()
import sys
N, X = map(int, input().split())
BLU = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
B, L, U = map(list, zip(*BLU))
C = [(u-l)*b for b, l, u in BLU]
D = [(X*u - c, u, c, l) for u, c, l in zip(U, C, L)]
D.sort(reverse = True)
SL = sum(l*b for l, b in zip(L, B))
SS = 0
for i, (d, _, _, _) in enumerate(D):
    SS += d
    if SS >= SL:
        break
SSb = SS - d
lans = i*X
m = 10**10
for _, u, c, l in D[i:]:
    m = min(m, -(-(c + SL - SSb)//u), -((SSb - SL)//l))
lans += m

ans = (i+1) * X
m = 0
for _, u, _, _ in D[:i+1]:
    m = max(m, -(-(SS - SL))//u)
print(min(lans, ans - m))

### FIXED CODE ###

N, A, B, C, D =  map(int, input().split())
S = input()
S = [False] + [s == '.' for s in S] + [False]
def check(s, t):
    i = s
    for _ in range(s, t+1):
        if i + 1 == t or i + 2 == t:
            return True
        if S[i+2]:
            i += 2
            continue
        if S[i+1]:
            i += 1
            continue
        return False

def checki(s, t):
    for i in range(s, t+1):
        if S[i-1] and S[i] and S[i+1]:
            return True
    return False



if A < B < D < C:
    if not check(B, D) or not check(A, C):
        print('No')
    elif checki(B, D):
        print('Yes')
    else:
        print('No')
else:
    if check(A, C) and check(B, D):
        print('Yes')
    else:
        print('No')
import sys
s=reverse(input())
l=list(["maerd","remaerd","esare","resare"]
for i in range len(s):
  ok=0
  for j in range l:
    if s[i:len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")


### FIXED CODE ###

import sys
s=input()
s=s[::-1]
l=list(["maerd","remaerd","esare","resare"])
i=0
while i < len(s):
  ok=0
  for j in l:
    if s[i:i+len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")
def main(n, s):
    a = set(s)

    if len(a) == 3:
        print('Three')
    elif len(a) == 4:
        print('Four')


if __name__ == "__main__":
    n = int(input())
    s = list(map(int, input().split()))

    main(n, s)


### FIXED CODE ###

def main(n, s):
    a = set(s)

    if len(a) == 3:
        print('Three')
    elif len(a) == 4:
        print('Four')


if __name__ == "__main__":
    n = int(input())
    s = list(input().split())

    main(n, s)
while True:
    h,w=map(int, input().split())
    if h==w== 0:break
    if h%2==1:
        print('#.'*(w/2) + '\n')
    else:
        print('.#'*(w/2) + '\n')

### FIXED CODE ###

while 1:
    h,w = map(int, input().split())
    if h==w==0:break
    for y in range(h):
        for x in range(w):
            if (x+y)%2==0:print('#',end='')
            if (x+y)%2==1: print('.',end='')
        print()
    print()
S = int(input())

if S >= 3600:
    h = S / 3600
    m = S % 3600 / 60
    s = m % 60 / 60

else
    if S >= 60:
        h = 0
        m = S / 60
        s = m % 60 / 60
    else
        h = 0
        m = 0
        s = S

### FIXED CODE ###

S = int(input())

h = S//3600
m = S%3600//60
s = S%3600%60

print(h,m,s,sep=":")
def LCS(s, t):
    res = ''
    m, n = len(s), len(t)

    def rec(cur, i, j):
        nonlocal res, s, t, m, n
        if i == m or j == n:
            res = max(''.join(cur), res, key=len)
            return

        if s[i] == t[j]:
            cur.append(s[i])
            rec(cur, i+1, j+1)
            cur.pop()
        else:
            rec(cur, i+1, j)
            rec(cur, i, j+1)

    rec([], 0, 0)

    return res


if __name__ == '__main__':

    s = input()
    t = input()

    print(LCS(s, t))

### FIXED CODE ###

s = input()
t = input()
n, m = len(s), len(t)
dp = [[0]*(m+1) for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

i, j = n, m

ans = []

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

print("".join(reversed(ans)))
import heapq
n = int(input())
A = [int(input()) for _ in range(n)]

lerge1, lerge2  = sorted(A)[-2:]
for i in range(n):
    if a[i]==m1:
        pritn(m2)
    else:
        print(m1)



### FIXED CODE ###

n = int(input())
A = [int(input()) for _ in range(n)]

m2, m1  = sorted(A)[-2:]
for i in range(n):
    if A[i]==m1:
        print(m2)
    else:
        print(m1)
a,b=map(int, input().split())
print(a*a-b)

### FIXED CODE ###

a=int(input())
b=int(input())
print((a*a)-b)
S = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
    

### FIXED CODE ###

S = input()
if S[2] == S[3] and S[4] == S[5]:
    print("Yes")
else:
    print("No")
A = input('A=: ')
B = input('B=: ')

length = int(A) - 2 * int(B)
if length < 0:
    print(0)
else:
    print(length)

### FIXED CODE ###

A,B=input().split()
length = int(A) - 2 * int(B)
if length < 0:
    print(0)
else:
    print(length)
H, W, n = map(int, input().split())
obst = []
for _ in range(n):
	x, y = map(int, input().split())
	if x >= y:
		obst.append([x-1, y-1, x-y])

bothered = [1000000] * (H+1)

for i in range(len(obst)):
	h, w, gap = obst[i][0], obst[i][1], obst[i][2]
	bothered[gap+1] = min(bothered[gap+1], h+1)

obst.sort(key=lambda x: x[0])

for i in range(len(obst)):
	h, w, gap = obst[i][0], obst[i][1], obst[i][2]
	if gap == 0:
		continue
	if h < bothered[gap]:
		print(h)
		break

else:
	print(H)

### FIXED CODE ###

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

ok, ng = n, 0
while ok-ng > 1:
	x = (ok+ng)//2
	#d = defaultdict(int)
	d = dict()
	last = 0
	valid = True
	if x == 1:
		for i in range(n-1):
			if a[i] >= a[i+1]:
				valid = False
				break
		if valid:
			ok = x
		else:
			ng = x
		continue

	for i in range(n-1):
		dels = []
		if a[i] < a[i+1]:
			last = a[i+1]
			continue

		j = a[i+1]
		for k in d.keys():
			if j < k:
				dels.append(k)

		while j > 0:
			if j in d and d[j] == x-1:
				#d[j] = 0
				dels.append(j)
				j -= 1
			else:
				break

		if j in d:
			d[j] += 1
		else:
			d[j] = 1

		for k in dels:
			del d[k]

		if 0 in d:
			valid = False
			break
		last = j

	if valid:
		ok = x
	else:
		ng = x
print(ok)
a = str(input())

if a.islower()==True:
    print(a)
else:
    print(A)

### FIXED CODE ###

a = str(input())

if a.islower()==True:
    print('a')
else:
    print('A')
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
dfs(1)
for i in range(1,n+1):
    if y[1]%2==0:
        print(0)
    else:
        print(1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def dfs(s):
    visited[s]=1
    for v in adj[s]:
        if v not in visited:
            if (s,v) in we:
                y[v]=y[s]+we[(s,v)]
            elif (v,s) in we:
                y[v]=y[s]+we[(v,s)]
            dfs(v)
n=int(input())
adj={}
we={}
visited={}
y=[0]*(n+1)
for q in range(n-1):
    a,b,w=map(int,input().split())
    if a not in adj:
        adj[a]=[b]
    else:
        adj[a].append(b)
    if b not in adj:
        adj[b]=[a]
    else:
        adj[b].append(a)
    we[(a,b)]=w
if n>1:
	dfs(1)
for i in range(1,n+1):
    if y[i]%2==0:
        print(0)
    else:
        print(1)
dat =list(input().split())

for i in dat:
   i = int(i)

dat.sort()
dat.reverse()

asum = 0
bsum = 0

for i in range(len(dat)):
#	if i%2==0:
#		asum = asum + dat[i]
#	else:
#		bsum = bsum + dat[i]
		
print(0)

### FIXED CODE ###

n = int(input())
dat = list(input().split())

dat = list(map(int,dat))

dat.sort(reverse=True)

asum = 0
bsum = 0

for i in range(n):
	if i % 2 == 0:
		asum = asum + dat[i]
	else:
		bsum = bsum + dat[i]
		
print(asum-bsum)
ions

S = input()
Q = int(input())

rev = False
deque = collections.deque()
for c in S:
    deque.append(c)
for _ in range(Q):
    read = input()
    if read == '1':
        rev = not rev
    else:
        _, f, c = read.split()
        if not rev:
            if f == '1':
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == '1':
                deque.append(c)
            else:
                deque.appendleft(c)

ret = ''.join(deque if not rev else reversed(deque))
print(ret)


### FIXED CODE ###



import collections

S = input()
Q = int(input())

rev = False
deque = collections.deque()
for c in S:
    deque.append(c)
for _ in range(Q):
    read = input()
    if read == '1':
        rev = not rev
    else:
        _, f, c = read.split()
        if not rev:
            if f == '1':
                deque.appendleft(c)
            else:
                deque.append(c)
        else:
            if f == '1':
                deque.append(c)
            else:
                deque.appendleft(c)

ret = ''.join(deque if not rev else reversed(deque))
print(ret)
A, B = int(input())
print(A * B )

### FIXED CODE ###

a,b = map(int, input().split())
print(a*b)
# E
from heapq import heappush, heappop
import numpy as np

N, K, Q = map(int, input().split())
A = list(map(int, input().split()))

A_args = np.argsort(A)

nodeid = np.ones(N).astype("int32")
canput = np.ones(N)
nodeid_dict = dict()
nodeid_dict[1] = [0, N]

# initial output
res = A[A_args[Q-1]] - A[A_args[0]]

ind_del = 0

for i in range(N):
    
    nid = A_args[i]
    
    # update nodeid
    ndid = nodeid[nid]
    nodeid[nid] = 0
    left, right = nodeid_dict[ndid]
    nodeid[(nid+1):right] = i+2
    nodeid_dict[nid] = [left, nid]
    nodeid_dict[i+2] = [nid+1, right]

    # update canput
    canput[nid] = 0
    
    canput[left:nid] = 0
    h = []
    for j in range(left, nid):
        heappush(h, (-A[j], j))
    while len(h) >= K:
        _, j = heappop(h)
        canput[j] = 1
    
    canput[(nid+1):right] = 0
    h = []
    for j in range(nid+1, right):
        heappush(h, (-A[j], j))
    while len(h) >= K:
        _, j = heappop(h)
        canput[j] = 1
    
    # break
    if canput.sum() <= Q:
        break
        
    # calculate
    q = 0
    qmin = 10**9
    qmax = 1
    for i in range(N):
        if canput[A_args[i]] == 1:
            q += 1
            qmin = min(A[A_args[i]], qmin)
            qmax = max(A[A_args[i]], qmax)
            if q == Q:
                r = qmax - qmin
                break
    res = min(res, r)
print(res)

### FIXED CODE ###

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


res = 0
for i in range(1, N):
    if S[i] == "E":
        res += 1
res_min = res
for i in range(1, N):
    if S[i-1] == "W":
        res += 1
    if S[i] == "E":
        res -= 1
    res_min = min(res, res_min)
print(res_min)