peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=[]
for i in c:
    d.append(abs(b-i))
print(gcd_list(d))
# Judge status: Accepted
s = int(input())
ear = {s}
ans = 1
while True:
    ans += 1
    if s % 2 == 0:
        s //= 2
    else:
        s = 3 * s + 1
    if s in ear:
        print(ans)
        break
    ear.add(s)
# Judge status: Wrong Answer
print("ARC" if input()=="ABC" else "ARC")
# Judge status: Accepted
N, A, B = map(int, input().split())
L = 0

for i in range(N+1):
    T = (i//10000) + ((i//1000)%10) + ((i//100)%10) + ((i//10)%10) + (i%10)
    if (A<=T) and (T<=B):
        L += i

print(L)
# Judge status: Accepted
n, k = map(int, input().split())
p = input()
x = p.split()
l = [int(s) for s in x]
shukei = 0

def shukei_def():
    global shukei
    if n == len(l):
        for i in range(k):
            shukei += min(l)
            l.remove(min(l))
        else:
            return

shukei_def()

print(shukei)
# Judge status: Accepted
x,y,z = map(int,input().split())

print(z//x*y)
# Judge status: Accepted
l,r,d=map(int,input().split())

ans = 0
for i in range(l,r+1):
    if i % d == 0:
        ans += 1

print(ans)
# Judge status: Wrong Answer
a,b=input().split()
a=int(a)
b=int(b)
print((b-a)*(b-a-1)/2-b)
# Judge status: Accepted
n=int(input())
ans=10**12
for i in range(1,int(n**0.5+1)):
    if (n/i)%1==0:
        ans=min(ans,((n/i)-1)+(i-1))
print(int(ans))
# Judge status: Accepted
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
ans1 = 0
ans2 = 0
for i in range(n):
    if i % 2 == 0:
        ans1 += a[i]
    else:
        ans2 += a[i]
print(ans1-ans2)
# Judge status: Accepted
w=list(input())
w.sort()

ans=0
while w:
    count=1
    check=w.pop()
    while check in w:
        count+=1
        w.pop()
    if count%2==1:
        ans+=1
        
if ans==0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
if n % 2 == 0:
  a = l[::-2]+ l[0::2]
else:
  a = l[::-2]+ l[1::2]
print(*a)
# Judge status: Accepted
# coding: utf-8
# Your code here!
cost=list(map(int,input().split()))

for i in range(4):
    cost[i]/=2**(i-2)
    if i!=3:
        cost[i]=int(cost[i])
    
N=int(input())

if min(cost)==cost[3]:
    temp=int(cost[3]*2)
    print(((N//2)*temp+(N%2)*min(cost[:3])))
else:
    print((min(cost)*N))
# Judge status: Accepted
# 21   import sympyが最速だが、Atcoderには無い
import math
x = int(input())

#エラトステネスの篩
n = [i for i in range(2,int(math.sqrt(x))+1)]

for i in n:
    for j in n:
        if j % i == 0 and j/i !=1:
            n.remove(j)
            
while x > 0:
    for i in n:
        if x % i == 0:
            break
    else:
        print(x)
        break
    x+=1
# Judge status: Wrong Answer
a,b,c=map(int,input().split())

if a%2==b%2 and b%2==c%2:
    pass
else:
    a+=(a%2==b%2 and a%2==c%2)
    b+=(b%2==a%2 and b%2==c%2)
    c+=(c%2==a%2 and c%2==b%2)
x=sorted([a,b,c])
print((x[2]-x[1])//2+(x[2]-x[0])//2+1)
# Judge status: Wrong Answer
n=int(input())
print(int(0.5*n*(n-1)))
# Judge status: Accepted
N=int(input())
ans=0
for i in range(1,N+1):
    m=N//i
    ans+=m*i*(m+1)//2
print(ans)
# Judge status: Wrong Answer
N, M = map(int, input().split())

pref = [[] for _ in range(N+1)]
for i in range(M):
    pp, yy = map(int, input().split())
    pref[pp].append((yy, i))

names = ['']*(M+1)
for i in range(N):
    pref[i].sort()

for i in range(1, N+1):
    prefname = '{:06d}'.format(i)
    for k in range(len(pref[i])):
        _, id = pref[i][k]
        cityname = '{:06d}'.format(k+1)
        names[id] = prefname + cityname

for id in range(M):
    print(names[id])
# Judge status: Accepted
S = input()[::-1]

res = 0
tmp = [0] * 2019
tmp[0] = 1
sum_of_digits = 0
d = 1

for c in S:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    tmp[sum_of_digits] += 1

for t in tmp:
    res += (t * (t - 1)) // 2

print(res)
# Judge status: Accepted
N = int(input())
total = list(str(N))
ntotal = 0
for i in range(len(total)):
  ntotal += int(total[i])
#print(ntotal,ntotal % 9)
if ntotal % 9 == 0 or ntotal == 0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))+[X]
y=list(map(int,input().split()))+[Y]
if max(x)<min(y):
    print("No War")
else:
    print("War")
# Judge status: Accepted
Q, H, S, D = map(int, input().split())
N =int(input())

p = min([Q*4,H*2,S])

p1 = p*N
p2 = D*(N//2) + p*(N%2)
print(min([p1,p2]))
# Judge status: Accepted
a,b = map(int,input().split())
if a == b:
    print('Draw')
else:
    if a == 1:
        print('Alice')
    elif b == 1:
        print('Bob')
    elif a > b:
        print('Alice')
    else:
        print('Bob')
# Judge status: Accepted
from collections import defaultdict

d = defaultdict(lambda : 0)

n = int(input())
for _ in range(n):
    item = input()
    d[item] += 1

items = sorted(d.items(), key=lambda x: (x[1], x[0]), reverse=True)
c = items[0][1]
l = []
for k, v in items:
    if v < c:
        break
    l.append(k)
if len(l) == 1:
    print(l[0])
else:
    print('\n'.join(l[::-1]))
# Judge status: Accepted
# -*- coding: utf-8 -*-

n = int(input())
a = []
b = []
b2 = []
c = []
count = 0
max = 0

for i in range(n):
    x,y = list(map(int,input().split()))
    a.append([x,y,x+y])

a.sort(key=lambda x: x[2])

for i in a:
    if max != 0 and i[0]-i[1] < max:
        count += 1
    else:
        max = i[2]
    
print(n - count)
# Judge status: Accepted
#@ ABC139 B
A,B = list(map(int, input().split()))

pul = 1
cnt = 0
while pul < B:
    pul += A-1
    cnt += 1
    
print(cnt)
# Judge status: Accepted
N=int(input())
S=list(map(int,input().split()))
s=list(set(S))
s.sort()
x=len(s)
Z=0
for i in range(x-1):
  a=s[i]
  A=S.count(a)
  for j in range(x-i-1):
    b=s[i+1+j]
    B=S.count(b)
    t=[i for i in S if i>b and i<a+b]
    T=len(t)
    Z+=A*B*T
print(Z)
# Judge status: Wrong Answer
x,y = map(int,input().split())

list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]

if x in list1:
    if y in list1:
        print('Yes')
elif x in list2:
    if y in list2:
        print('Yes')
else:
    print('No')
# Judge status: Accepted
s=input()
ans=float("inf")
for i in range(len(s)-2):
    ans=min(ans,abs(753-int(s[i]+s[i+1]+s[i+2])))
print(ans)
# Judge status: Wrong Answer
n,thevailladadu = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
m = n

i=0
ans=0
while (n>0):
    a = n%10
    #print(a)
    while a in d:
        a=(a+1)%10
    ans+=(a*(10**i))
    n//=10
    i+=1
    
if ans<m:
    j=1
    while j in d:
        j+=1
    ans+=(j*(10**i))
    
print(ans)
# Judge status: Accepted
n=int(input())
h=list(map(int,input().split()))
ans=0
cnt=0
for i ,j in zip(h,h[1:]):
  if i>=j:
    cnt+=1
  else:
    ans=max(ans,cnt)
    cnt=0
ans=max(ans,cnt)
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())
if a == 1 and b == 1:
    print('Draw')

elif a == 1 and (2 <= b and b <= 13):
    print('Alice')

elif b == 1 and (2 <= a and a <= 13):
    print('Bob')

elif a > b:
    print('Alice')

elif b > a:
    print('Bob')

elif a == b:
    print('Draw')
# Judge status: Accepted
def main():
    x = int(input())
    for i in range(200):
        for j in range(-200, 200):
            if i**5-j**5==x:
                print(i, j)
                return
 
 
if __name__ == "__main__":
    main()
# Judge status: Accepted
n=int(input())
d=list(map(int,input().split()))

d.sort()
large=d[int(n/2)]
small=d[int(n/2)-1]
print(large-small)
# Judge status: Accepted
n = int(input())
sp = [0]*n
z = [0]*n
for i in range(n):
    sp[i]    = input().split() + [i+1]
    sp[i][1] = int(sp[i][1])
    z[i]     = sp[i][0]
a = sp
a.sort(key=lambda val : val[0])
import collections
c = collections.Counter(z)

i = 0
while i < n:
    b = c[a[i][0]]
    d = a[i:i+b][:]
    d.sort(key= lambda val : val[1],reverse=True)
    for j in range(b):
        print(d[j][2])
    i += b
# Judge status: Accepted
a, b, c, k = list(map(int, input().split()))
if k <= a:
	s = k * 1
elif k <= (a+b):
	s = a * 1
else:
	s = (a * 1) + ((k-(a+b)) * (-1))
print(s)
# Judge status: Wrong Answer
a,b = map(int, input().split())

s =input()

intlist = ["0","1","2","3","4","5","6","7","8","9"]

for i in range(a):
    if s[i] in intlist:
        pass
    else:
        print("No")
        exit()

if s[a] != "-":
    print("No")
    exit()
    
for j in range(a+1,a+1+b):
    if s[i] in intlist:
        pass
    else:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
n=int(input())
alist=[]
blist=[]
for i in range(n):
    a,b=map(int,input().split())
    alist.append(a)
    blist.append(b)
alist.sort()
blist.sort()
if n%2==1:
    num1=-1*(n//-2)-1
    print(blist[num1]-alist[num1]+1)
else:
    num1=n//2-1
    num2=num1+1
    print((blist[num2]+blist[num1])-(alist[num2]+alist[num1])+1)
# Judge status: Wrong Answer
import itertools
n,m = map(int,input().split())
card = [list(map(int,input().split())) for c in range(m)]
ans = 0
tmp = []
if m == 1:
    print(max(card[0]))
else:
    for c in card:
      c = [i for i in range(c[0],c[-1]+1)]
      tmp.append(c)

    tmp = list(itertools.chain.from_iterable(tmp))
    tmp = [x for x in set(tmp) if tmp.count(x) >= m]

    print(len(tmp))
# Judge status: Accepted
a=input()
print(a[0]+("B" if a[1] == "R" else "R")+a[2])
# Judge status: Wrong Answer
import math

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

if b > a:
    N = int(b/x) - math.ceil(a/x) + 1

    print(int(N))
else:
    print(0)
# Judge status: Wrong Answer
s = list(map(lambda x: ord(x) - ord('a'), list(input())))

ans = ["-1", "-1"]
# print(s)
if len(s) == 2:
    if set(s) == 1:
        print(1, 2)
    else:
        print(" ".join(ans))
        exit()

for i in range(len(s) - 2):
    # print(len(set(s[i:i+3])))
    if len(set(s[i:i+3])) <= 2:
        # print(s[i:i+3])
        ans = [str(i+1), str(i+3)]
        break

print(" ".join(ans))
# Judge status: Wrong Answer
from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>=1:
    mid=(left+right)/2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
print(ceil(mid))
# Judge status: Wrong Answer
a, b, c, k = map(int, input().split())
    
if(k-a<=0):
    print(1*a)
elif(k-a-b<=0):
    print(1*a - 0*b)
else :
    print(1*a+0*b-1*(k-a-b))
# Judge status: Accepted
s=list(input())
a=0
for i in range(len(s)//2):
    if s[i]!=s[len(s)-1-i]:
        a+=1
print(a)
# Judge status: Accepted
n = int(input())
c = 0
x = []
while True:
    c+=1
    if n in x:
        print(c)
        break
    x.append(n)
    if n%2 == 0:
        n = n//2
    else:
        n = 3*n+1
# Judge status: Wrong Answer
n, a, b = map(int, input().split())

if b-a < 0 or n == 1:
    print(0)
elif a == b:
    print(1)
else:
    print((b-a)*(n-2)+1)
# Judge status: Accepted
n, m = map(int, input().split())
print('Yes' if n==m else'No')
# Judge status: Wrong Answer
def tapdance(s):
    for i in range(len(s)):
        if i % 2 == 0:
            if s[i] != 'L':
                return 'No'
        else:
            if s[i] != 'R':
                return 'No'
    return 'Yes'
s = input()
print(tapdance(s))
# Judge status: Accepted
O = input()
E = input()

if len(O)==len(E):
  for i in range(len(O)):
    print(O[i]+E[i], end="")
else:
  for i in range(len(E)):
    print(O[i]+E[i], end="")
  print(O[-1])
# Judge status: Accepted
#!/usr/bin/env python3

N, K, S = map(int, input().split())
if S < 10**9:
    Ret = [S]*K + [S+1]* (N-K)
else:
    Ret = [S]*K + [1]* (N-K)
print(*Ret)
# Judge status: Wrong Answer
N, A, B = map(int, input().split())

if A > B:
    print(0)
elif N == 1 and A != B:
    print(0)
elif N == 1 and A == B:
    print(1)
elif N == 2 and A != B:
    print(1)
print(1000)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
    ans += min(A[i],B[i])+min(A[i+1],B[i]-min(A[i],B[i]))
print(ans)
# Judge status: Wrong Answer
a,b,k = map(int,input().split())

l=[]
for i in range(1,101):
    if a%i == 0 and b%i == 0:
        l.append(i)

print(l[k-1])
# Judge status: Wrong Answer
import sys
import math

n,m=map(int,input().split())
mod=10**9+7
if abs(n-m)>1:
	print("0")
elif (n==m):
	val=math.factorial(n)
	print((val*4)%mod)
else:
	valn=math.factorial(n)
	valm=math.factorial(m)
	print((valn*valm)%mod)
# Judge status: Accepted
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  at,bt=map(int,input().split())
  a[i]=at
  b[i]=bt
temp=0
for i in range(n):
  a[n-1-i]=a[n-1-i]+temp
  if a[n-1-i]%b[n-1-i]!=0:
    temp=temp+b[n-1-i]-a[n-1-i]%b[n-1-i]
print(temp)
# Judge status: Accepted
import copy
N = int(input())
numbers = [int(i) for i in input().split()]
copy_num = sorted(copy.deepcopy(numbers))

mid = N // 2
mid_num = copy_num[mid]

for i in range(N):
    if numbers[i] >= mid_num:
        print(copy_num[mid-1])
    else :
        print(mid_num)
# Judge status: Accepted
N = int(input())
p = list(map(int,input().split()))
cnt = 0
h = [p[i] == i + 1 for i in range(N)]
i = 1
while(i < N):
    if h[i] and h[i - 1]:
        cnt += 1
        i += 1
    i += 1
ans = sum(h) - cnt
print(ans)
# Judge status: Accepted
n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
t = a[0]
ans = 1
if t == 2:
	print(ans)
else:
	while True:
		t = a[t-1]
		ans += 1
		if t == 2:
			print(ans)
			break
		if ans > n:
			print('-1')
			break
# Judge status: Accepted
K = int(input())
S = input()
if len(S) <= K:
	print(S)
else:
	print(S[:K] + "...")
# Judge status: Accepted
a,b=input().split()
a=int(a)
b=int(b[:-3]+b[-2:])
#b=int(float(b)*100)
print(int(a*b//100))
# Judge status: Accepted
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())

    ac = [False] * N
    wa = [0] * N
    for _ in range(M):
        it = iter(input().split())
        p = int(next(it)) - 1
        s = next(it)
        if s == 'AC':
            ac[p] = True
        else:
            if not ac[p]:
                wa[p] += 1
    print(ac.count(True), sum(w for p, w in enumerate(wa) if ac[p]))


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))

cnt = 0
increased = False

for i in range(n):
    if increased:
        increased = False

    elif p[i] == i+1:
        cnt += 1
        increased = True

print(cnt)
# Judge status: Wrong Answer
import math
from functools import reduce

k = int(input())
sum = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for i in range(0, k):
  for j in range(0, k):
    for k in range(0, k):
      sum += gcd(i, j, k)

print(sum)
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
cnt=0

if A==B==C:
  cnt=-1
else:
  while A%2==0 and B%2==0 and C%2==0:
    s=A//2
    t=B//2
    u=C//2
    A=t+u
    B=u+s
    C=s+t
    cnt +=1
    
print(cnt)
# Judge status: Accepted
from math import ceil


def main():
    length = int(input())
    sequence = [0 for _ in range(length)]
    target = [0 for _ in range(length)]
    for i in range(length):
        a, b = map(int, input().split())
        sequence[i] = a
        target[i] = b
    answer = 0
    cumulative_push = 0
    for i in range(-1, -length - 1, -1):
        sequence[i] += cumulative_push
        now_push = ceil(sequence[i] / target[i]) * target[i] - sequence[i]
        cumulative_push += now_push
        answer += now_push
    print(answer)


if __name__ == '__main__':
    main()
# Judge status: Accepted
N, M = map(int, input().split())

s = []
c = []

for i in range(M):
    s_e, c_e = map(int, input().split())
    s.append(s_e)
    c.append(c_e)

ans = -1

for i in range(1000):
    str_i = str(i)
    len_str_i = len(str_i)
    if len_str_i != N:
        continue
    else:
        for k in range(M):
            if str_i[s[k]-1] != str(c[k]):
                break
        else:
            ans = i
            break

print(ans)
# Judge status: Accepted
n = int(input())
l = list()
for i in range(n):
    l.append(list(map(int, input().split())))

l.sort(key = lambda x:x[1])

t = 0
for i in range(n):
    t += l[i][0]
    if t > l[i][1]:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
n = int(input())
ans = 0
for i in range(1, n + 1, 2):
    divisor = 0
    for j in range(1, i + 1, 2):
        if i % j == 0:
            divisor += 1
    if divisor == 8:
        ans += 1
print(ans)
# Judge status: Wrong Answer
print('ARC' if input()=='ABC' else 'ARC')
# Judge status: Accepted
from collections import defaultdict
b = defaultdict(int)
r = defaultdict(int)

n = int(input())
for i in range(n):
  b[input()]+=1
m = int(input())
for i in range(m):
  r[input()]+=1
  
ans = 0
for k, v in b.items():
  ans = max(ans, v - r[k])
for k, v in r.items():
  ans = max(ans, b[k] - v)
print(ans)
# Judge status: Accepted
a,b = map(int,input().split())
print(a * (a-1) // 2 + b * (b-1) //2)
# Judge status: Accepted
h = int(input())
w = int(input())
n = int(input())

a = max([h, w])

ans = n // a
if n % a > 0:
    ans += 1

print(ans)
# Judge status: Accepted
s = input()
a = list(map(str, range(1, 10)))
b = list(map(str, range(0, 3)))
mm = 0
ba = 0
for i in [0, 2]:
    if s[i] == "0" and s[i+1] in a:
        mm += 1
        ba = i
    elif s[i] == "1" and s[i+1] in b:
        mm += 1
        ba = i
if mm == 0:
    print("NA")
elif mm == 1 and ba == 0:
    print("MMYY")
elif mm == 1 and ba == 2:
    print("YYMM")
elif mm == 2:
    print("AMBIGUOUS")
# Judge status: Wrong Answer
S = str(input())
ans = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i in range(7):
    if S == 'SUN':
        print(0)
    elif S == ans[i]:
        print(7-i)
# Judge status: Accepted
import math
N, K = map(int, input().split())
print(int(math.log(N, K))+1)
# Judge status: Wrong Answer
n,q=map(int,input().split())
s=input()
b=[0]*n
for i in range(1,n):
  b[i]=b[i-1]
  if s[i-1:i]=="AC": b[i]+=1
for i in range(q):
  l,r=map(int,input().split())
  print(b[r-1]-b[l-1])
# Judge status: Accepted
#template
def inputlist(): return [int(k) for k in input().split()]
#template
X,Y = inputlist()
if X % Y == 0:
    print(-1)
else:
    print(X)
# Judge status: Accepted
#!/usr/bin/env python3
r,g,b = map(int,input().split())

print("YES" if ((r*100)+(g*10)+b) % 4 == 0 else "NO")
# Judge status: Accepted
n = int(input())
li = [(list(map(int,input().split()))) for _ in range(n-1)]

for i in range(n-1):
    tm = 0 #時刻を表す
    for j in range(i,n-1):
        if tm < li[j][1]: #開通していない
            tm = li[j][1]
        elif tm%li[j][2] != 0: #発車していない
            tm += li[j][2]-(tm%li[j][2])
        else:
            pass

        tm += li[j][0]

    print(tm)
print(0)
# Judge status: Wrong Answer
print(sum(i for i in range(int(input()))if i%3!=0 and i%5!=0))
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())

res = set()
def dfs(x, s):
  global res
  res.add(int("".join(s)))
  if x == 10: return
  for i in range(3):
    if (int(s[-1]) + i - 1) in range(10):
      y = s + [str(int(s[-1]) + i - 1)]
      dfs(x + 1, y)
for i in range(1, 10): dfs(1, [str(i)])
res = sorted(res)
print(res[N - 1])
# Judge status: Accepted
if __name__=="__main__":
    s = input()

    t = ""
    for i in range(len(s)):
        t += "x"

    print(t)
# Judge status: Wrong Answer
import math
n = int(input())
root = int(math.sqrt(n))
ans = 0
flag = 0
for i in range(root, 10**6+1):
    if n % i == 0:
        flag = 1
        print('i='.format(i))
        ans = int((n/i)) + i - 2
        break
if flag==1: pass
else: # nが素数
  ans = n + 1 - 2
print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in a:
    ans *= i
    if ans > 10**18:
        print('-1')
        exit()
print(ans)
# Judge status: Accepted
N, M = map(int, input().split())
vote = list(map(int, input().split()))

lis = sorted(vote, reverse=True)

if lis[M-1] < 1/(4*M) * sum(lis):
    print('No')
else:
    print('Yes')
# Judge status: Accepted
a, b = input().split()
a = int(a)
b = int(b.replace('.', ''))

print(a * b // 100)
# Judge status: Accepted
N, A, B = map(int, input().split())
sum_ = A * (N // (A+B))
mod = N % (A+B)
print(sum_ + (A if mod >= A else mod))
# Judge status: Accepted
N, M = [int(n) for n in input().split()]
X = sorted([int(n) for n in input().split()])
if N>=M:
    print(0)
else:
    dx = []
    for j in range(M-1):
        dx.append(X[j+1]-X[j])
    ans = sorted(dx, reverse=True)
    print(sum(ans[N-1:]))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
cnt = [0 for i in range(60)]
mod = 10 ** 9 + 7

for i in A:
    tmp = format(i, '060b')
    for j in range(60):
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

for i in range(60):
    ans += (lst[i] * cnt[i] * (N -cnt[i])) % mod

print(ans)
# Judge status: Wrong Answer
n,k,q=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  if k-q+a.count(i+1)>0:
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
n, m = map(int, input().split())

if n==m:
    print('Yes')
elif n!=m:
    print('No')
# Judge status: Accepted
n = int(input())
A = sorted(map(int, input().split()), reverse = True)

x = 0; y = 0
count = 0
i = 0
while i < n - 1:
    if A[i] == A[i + 1]:
        if count == 0:
            x = A[i]
        else:
            y = A[i]
        count += 1
        i += 2
    else:
        i += 1
    if count == 2:
        break

print(x * y)
# Judge status: Wrong Answer
a , b , c, d= map ( int, input ().split())
if a-c <= d or a-b <= d:
    print("Yes")
elif b-c <= d:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
P, Q, R = map(int, input().split())

print(min(P + Q, Q + R, P + R))
# Judge status: Accepted
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	lis = ["Sunny", "Cloudy", "Rainy"]
	s = input()
	print(lis[lis.index(s) - 2])


if __name__=='__main__':
	main()
# Judge status: Wrong Answer
a,b=map(int,input().split())
c=a-b

if a <= b:
    print(c+1)
else:
    print(c)
# Judge status: Accepted
n, m = map(int,input().split())
for i in range(m):
  print(i + 1, 2*m - i + (n%2==0 and 2*(m - i) - 1 >= n//2))
# Judge status: Accepted
a,b,c = (int(x) for x in input().split())

if a==b==c:
    print("1")
elif a==b or a==c or b==c:
    print("2")
else:
    print("3")
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())
flg = True
for i in range(2 * max(A, C) + 1):
    if i % 2 == 0:
        C -= B
        print('C: ', C)
        if C <= 0:
            flg = False
            print('Yes')
    else:
        A -= D
        if A <= 0:
            flg = False
            print('No')
    if not flg:
        break
# Judge status: Accepted
def main():
    n, k = map(int, input().split())
    As = list(map(int, input().split()))

    ans = (n-2) // (k-1) + 1
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted

a, b, k = map(int, input().split())
mini = min(a, b)

count = 0
for i in range(mini,0,-1):
    if(a % i ==0 and b % i == 0):
        count += 1
    if(count == k):
        print(i)
        break
# Judge status: Wrong Answer
def resolve():
	n = int(input())
	s = input()
	sum_e = [0]*(n+1)
	sum_w = [0]*(n+1)
	for i in range(n):
		ev = 1 if s[i] == 'E' else 0
		wv = 1 if s[i] == 'W' else 0
		sum_e[i+1] = sum_e[i] + ev
		sum_w[i+1] = sum_w[i] + wv
	ans = float('inf')
	for i in range(1, n):
		v = sum_w[i-1] + (sum_e[-1] - sum_e[i])
		ans = min(ans, v)
	print(ans)
resolve()