Harryxun/stf_run huggingface dataset:
def main(money):
  a  = money % 1000
  if a != 0:
    change = 1000 - a
    return change
  elif a = 0:
    change = 0
    return change

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 20:25:04 2020

@author: KevinLU
"""
money = int(input())

a  = money % 1000
if a > 0:
    change = 1000 - a
else:
    change = 0
print(change)
n,k=int(input().split())
l=list(map(int,input()))
l1 = sorted(l, reverse=True)
s=0
for i in range(k):
    s+=l1[i]
print(s)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
l1 = sorted(l, reverse=True)
s=0
for i in range(k):
    s+=l1[i]
print(s)
import math

n = int(input())
a = [int(i) for i in input().split()]

b = [a[i]-(i+1) for i in range(n)]

s = sum(b)
N = len(b)
mean = math.floor(s / N)
meanb = mean+1

t = sum([abs(b[i]-mean) for i in b])
u = sum([abs(b[i]-meanb) for i in b])

print(min(t,u))

### FIXED CODE ###

import math
import statistics

n = int(input())
a = [int(i) for i in input().split()]

b = [a[i]-(i+1) for i in range(n)]
median = statistics.median(b)

med1 = math.floor(median)
med2 = med1+1

t = sum([abs(i-med1) for i in b])
u = sum([abs(i-med2) for i in b])

print(min(t,u))
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

Q = int(input())
cnt = 0
m = []
M = []
import heapq
heapq.heapify(m)
heapq.heapify(M)
sum_m = 0
sum_M = 0
B = 0
cnt = 0
for i in range(Q):
    #print(m, M)
    q = str(input())
    if q != '2':
        _, a, b = map(int, q.split())
        B += b
        cnt += 1
        if len(m) != 0 and len(M) != 0:
            x1 = heapq.heappop(m)*(-1)
            x2 = heapq.heappop(M)
            sum_m -= x1
            sum_M -= x2
            if a <= x2:
                heapq.heappush(m, a*(-1))
                heapq.heappush(m, x1*(-1))
                sum_m += a+x1
                heapq.heappush(M, x2)
                sum_M += x2
            else:
                heapq.heappush(M, a)
                sum_M += a
                heapq.heappush(m, x1*(-1))
                heapq.heappush(M, x2*(-1))
                sum_m += x1+x2
        elif len(m) != 0 and len(M) == 0:
            x1 = heapq.heappop(m)*(-1)
            sum_m -= x1
            if a <= x1:
                heapq.heappush(m, a*(-1))
                sum_m += a
                heapq.heappush(M, x1)
                sum_M += x1
            else:
                heapq.heappush(M, a)
                sum_M += a
                heapq.heappush(m, x1*(-1))
                sum_m += x1
        else:
            heapq.heappush(m, a*(-1))
            sum_m += a
    else:
        if cnt == 0:
            print(0, 0)
        else:
            m_ = len(m)
            M_ = len(M)
            x = heapq.heappop(m)*(-1)
            min_ = sum_M - sum_m + m_*x - M_*x + B
            #print(sum_M, sum_m, B)
            print(x, min_)
            heapq.heappush(m, x*(-1))

### FIXED CODE ###

import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

q = int(input())

import heapq
L = []
R = []
heapq.heapify(L)
heapq.heapify(R)

B = 0

for i in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a, b = query[1], query[2]
        B += b
        heapq.heappush(L, -a)
        heapq.heappush(R, a)
        if -L[0] > R[0]:
            l = -heapq.heappop(L)
            r = heapq.heappop(R)
            B += l-r
            heapq.heappush(L, -r)
            heapq.heappush(R, l)
    else:
        print(-L[0], B)
s=list();[[[s.append(eval('{2}{1}{0}'.format(s.pop(),i,s.pop()))if(i in'+-*/')else i)for i in input().split(' ')]and print(s.pop())]for x in __import__('itertools').count()]

### FIXED CODE ###

exec("try:s=list();[[[s.append(eval('{2}{1}{0}'.format(s.pop(),i,s.pop()))if(i in'+-*/')else i)for i in input().split(' ')]and print(s.pop())]for x in __import__('itertools').count()]\nexcept:pass")
import math
T_total = ( math.ceil( N / X )*T )

print (T_total)

### FIXED CODE ###

NXT = [int(i) for i in input().split(' ')]
import math
T_total = ( math.ceil( NXT[0]/ NXT[1] )*NXT[2] )

print (T_total)
print("YNeos"[1-int(bin(2375063778094260874239)[-int(input())])::2])

### FIXED CODE ###

n=int(input())
for i in range(1,10):
    if 1<=n//i<10 and (n//i)*i==n:
        print("Yes")
        break
else:
    print("No")
s=input()
result=""
count=0
l=len(s)
for i in range(l):
  if i==0 and s[i]="A":
    result="WA"
    break
  elif i==1 and ord(s[1])<97 
    result="WA"
    break
  elif i==l-1 and ord(s[l-1])<97:
    result="WA"
    break
  else:
    if ord(s[i])<97:
      count+=1
    if count>1 or s[i]!="C":
      result="WA"
      break
if result!="WA"
  result="AC"
print(result)

### FIXED CODE ###

rate=int(input())
result=""
if rate<1200:
  result="ABC"
elif rate<2800:
  result="ARC"
else:
  result="AGC"
print(result)
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
a.append(n+1)
seq = [a[0]]

for i in range(m):
    d = a[i+1] - a[i] - 1
    if d == 0:
        print(0)
        sys.exit()
    seq.append(d)

memo = [-1] * 10**5
def fib(i):
    if i == 0: return 0
    elif i == 1: return 1
    elif memo[i] != -1: return memo[i]
    else:
        memo[i] = fib(i-1) + fib(i-2)
        return memo[i]

ans = 1
for s in seq:
    ans *= fib(s)
print(ans % 1000000007)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
a.append(n+1)
seq = [a[0]]

for i in range(m):
    d = a[i+1] - a[i] - 1
    if d == 0:
        print(0)
        sys.exit()
    seq.append(d)

memo = [-1] * (10**5 + 7)
def fib(i):
    if i == 0: return 0
    elif i == 1: return 1
    elif memo[i] != -1: return memo[i]
    else:
        memo[i] = fib(i-1) + fib(i-2)
        return memo[i]

ans = 1
for s in seq:
    ans *= fib(s)
print(ans % 1000000007)
L, R = map(int, input().split())

i = max(R - R%2019, L)
mod_i = 2019//(i%2019)
j = max(R - R%mod_i, L+1)

print(i*j%2019)


### FIXED CODE ###

L, R = map(int, input().split())

ans = 2019
for a in range(L, min(L+2019, R)+1):
    for b in range(L, min(L+2019, R)+1):
        if a == b:
            continue
        ans = min(a*b%2019, ans)
        if ans == 0:
            print(0)
            exit()
print(ans)
a=str(input())
if a='Sunny'
	print('Cloudy')
elif a='Cloudy'
	print('Rainy')
else a='Rainy'
	print('Sunny')

### FIXED CODE ###

a = input()
b = 'Sunny'
c = 'Cloudy'
d = 'Rainy'
if a == b:
 print(c)
if a == c:
 print(d)
if a == d:
 print(b)
a, b = map(int, input().split())
print((a+b) % 24 )

### FIXED CODE ###

a, b = map(int, input().split())
print((a+b) % 24 )
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,T = [int(x) for x in input().split]
cost = []
for _ in range(n):
    c,t = [int(x) for x in input().split]
    if t <= T:
        cost.append(c)

if cost == True:
    print(min(cost))
else:
    print("TLE")

### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,T = [int(x) for x in input().split()]
cost = []
for _ in range(N):
    c,t = [int(x) for x in input().split()]
    if t <= T:
        cost.append(c)

if cost:
    print(min(cost))
else:
    print("TLE")
Masu = []
def access(x,y):
    if x < 0 or y < 0:
        return
    Masu[y][x] += 1

for i in range(10):
    Masu.append([0,0,0,0,0,0,0,0,0,0])
kosu = 0
komax = 0
while True:
    try:
        
        x,y,s = map(int,input().split(","))
        if s == 1:
            for j in range(3):
                access(y +1 - j,x)
            access(y,x - 1)
            access(y,x + 1)

        elif s == 2:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
        elif s == 3:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
            access(y - 2,x)
            access(y + 2,x)
            access(y,x + 2)
            access(y,x - 2)
               
    except EOFError:
        for i in range(10):
            kosu += Masu[i].count(0)
        for j in range(10):
            if komax < max(Masu[j]):
                komax = max(Masu[j])
        print(kosu)
        print(komax)
        break

### FIXED CODE ###

Masu = []
def access(x,y):
    if x < 0 or y < 0 or x > 9 or y > 9:
        return
    Masu[y][x] += 1

for i in range(10):
    Masu.append([0,0,0,0,0,0,0,0,0,0])
kosu = 0
komax = 0
while True:
    try:
        
        x,y,s = map(int,input().split(","))
        if s == 1:
            for j in range(3):
                access(y +1 - j,x)
            access(y,x - 1)
            access(y,x + 1)

        elif s == 2:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
        elif s == 3:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
            access(y - 2,x)
            access(y + 2,x)
            access(y,x + 2)
            access(y,x - 2)
               
    except (EOFError,ValueError):
        for i in range(10):
            kosu += Masu[i].count(0)
        for j in range(10):
            if komax < max(Masu[j]):
                komax = max(Masu[j])
        print(kosu)
        print(komax)
        break
# -*- coding utf-8 -*-
X = int(input())
a = []
for i in range(11):
  a.append(j ** i for j in range(j ** i < 1000) if X > j**i)
b = []
for i in range(11;32):
  b.append(i ** 2 if X > i ** 2)
L = a+b
print(sum(L))

### FIXED CODE ###

# -*- coding; utd-8 -*-
X = int(input())
import math
a = [math.pow(i,j) for j in range(2,11) for i in range(1,32) if math.pow(i,j)<=X]
print(int(max(a)))
n = int(input())
ans = ''
alf = ['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' ]
order = 0
def func(m):
    return 26 * (26**m-1) / 25
# print(func(12))
for i in range(11, 0, -1):
    if n > func(i):
        n = int(n-func(i)+0.5)
        order = i
        break
for i in range(order, 0, -1):
    m = int(n//(26**i) + 0.5)
    # print(n)
    # print(m)
    n %= 26**i
    ans += alf[m]
ans += alf[n-1]
print(ans)


### FIXED CODE ###

n = int(input())
ans = ''
alf = ['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' ]
order = 0
def func(m):
    return int(26 * (26**m-1) / 25 + 0.5)
# print(func(12))
for i in range(11, 0, -1):
    if n > func(i):
        n = n-func(i)
        order = i
        break
for i in range(order, 0, -1):
    if n % 26**i == 0:
        m = n//(26**i) - 1
        n -= m * 26 ** i
        ans += alf[m]
    # print(n)
    # print(m)
    else:
        m = n // 26**i
        n %= 26**i
        ans += alf[m]
ans += alf[n-1]
print(ans)
r =int(imput())
print(6.28*r)

### FIXED CODE ###

r =int(input())
print(6.28*r)
def lsum(x):
    return A[x[0]] + B[x[1]] + C[x[2]]

def nextlist():
    global lx
    idx = 0
    m = lsum(lx[0])
    for i in range(len(lx)):
        s = lsum(lx[i])
        if m < s:
            m = s
            idx = i
    p = lx.pop(idx)
    wa.append(lsum(p))
    if p[0] > 0:
        if not [p[0]-1, p[1], p[2]] in lx:
            lx.append([p[0]-1, p[1], p[2]])
    if p[1] > 0:
        if not [p[0], p[1]-1, p[2]] in lx:
            lx.append([p[0], p[1]-1, p[2]])
    if p[2] > 0:
        if not [p[0], p[1], p[2]-1] in lx:
            lx.append([p[0], p[1], p[2]-1])

l1 = list(map(int, input().split(" ")))

X,Y,Z,K = l1[0],l1[1],l1[2],l1[3]
A = sorted(list(map(int, input().split(" "))))
B = sorted(list(map(int, input().split(" "))))
C = sorted(list(map(int, input().split(" "))))

wa = []
lx = [[X-1,Y-1,Z-1]]

for i in range(K):
    nextlist()

for l in wa:
    print(l)


### FIXED CODE ###

def lsum(x):
    return A[x[0]] + B[x[1]] + C[x[2]]

def nextlist():
    global lx
    idx = 0
    m = lsum(lx[0])
    for i in range(len(lx)):
        s = lsum(lx[i])
        if m < s:
            m = s
            idx = i
    p = lx.pop(idx)
    wa.append(lsum(p))
    if p[0] > 0:
        if not [p[0]-1, p[1], p[2]] in lx:
            lx.append([p[0]-1, p[1], p[2]])
    if p[1] > 0:
        if not [p[0], p[1]-1, p[2]] in lx:
            lx.append([p[0], p[1]-1, p[2]])
    if p[2] > 0:
        if not [p[0], p[1], p[2]-1] in lx:
            lx.append([p[0], p[1], p[2]-1])

l1 = list(map(int, input().split(" ")))

X,Y,Z,K = l1[0],l1[1],l1[2],l1[3]
A = sorted(list(map(int, input().split(" "))))
B = sorted(list(map(int, input().split(" "))))
C = sorted(list(map(int, input().split(" "))))

wa = []
lx = [[X-1,Y-1,Z-1]]

for i in range(K):
    nextlist()

for l in wa:
    print(l)
Sd=input()
T=input()
 
i=len(Sd)-len(T)
j=0
ans=[]
flag=False
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

### FIXED CODE ###

Sd=input()
T=input()


i=len(Sd)-len(T)
j=0
ans=[]
flag=False
while(1):
    if i<0:
        #print('not find')
        break
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            ans.append((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
            i-=j+1
            j=0
            flag=True
            continue
        j+=1
        i+=1
    else:
        i-=j+1
        j=0

if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')
def func_rfindr(str, start):
    return str.rfind('R')

def func_lfindw(str, start):
    return str.find('W', start)

def func_replace(target, pos, str):
    ret = ""
    if pos != 0:
        ret = target[0:pos]
    ret = ret + str
    if len(target) - 1 != pos:
        ret = ret + target[pos + 1:]
    return ret

N = int(input())
C = input()
ans = 0

posrr = func_rfindr(C)
poslw = func_lfindw(C)

while poslw != -1 and posrr != -1 and posrr > poslw:
    C = func_replace(C, posrr, "W")
    C = func_replace(C, poslw, "R")
    ans = ans + 1
    posrr = func_rfindr(C, posrr)
    poslw = func_lfindw(C, poslw)

print(ans)

### FIXED CODE ###

def func_rfindr(str):
    return str.rfind('R')

def func_lfindw(str):
    return str.find('W')

def func_replace(target, pos, str):
    ret = ""
    if pos != 0:
        ret = target[0:pos]
    ret = ret + str
    if len(target) - 1 != pos:
        ret = ret + target[pos + 1:]
    return ret

N = int(input())
C = input()
ans = 0

posrr = func_rfindr(C)
poslw = func_lfindw(C)

while poslw != -1 and posrr != -1 and posrr > poslw:
    #C = func_replace(C, posrr, "W")
    #C = func_replace(C, poslw, "R")
    C = C[poslw + 1:posrr]
    ans = ans + 1
    posrr = func_rfindr(C)
    poslw = func_lfindw(C)

print(ans)
from collections import deque
s=input()
q=int(input())
ans_str=deque([s])
cnt=0
for _ in range(q):
    Q=list(input().split())
    if Q[0]=='1':
        cnt=1 if cnt==0 else 0

    else:
        if Q[1]=='1':
            if cnt==0:
                ans_str.appendleft(Q[-1])
            else:
                ans_str.append(Q[-1][::-1])

        else:
            if cnt==0:
                ans_str.append(Q[-1])
            else:
                ans_str.appendleft(Q[-1][::-1])
    print(ans_str,cnt,Q)

ans=list(ans_str) if cnt==0 else list(ans_str)[::-1]
print(*ans,sep='')

### FIXED CODE ###

from collections import deque
s=input()
q=int(input())
ans_str=deque(s)
cnt=0
for _ in range(q):
    Q=list(input().split())
    if Q[0]=='1':
        cnt=1 if cnt==0 else 0

    else:
        if Q[1]=='1':
            if cnt==0 or len(ans_str)==1:
                ans_str.appendleft(Q[-1])
            else:
                ans_str.append(Q[-1])

        else:
            if cnt==0 or len(ans_str)==1:
                ans_str.append(Q[-1])
            else:
                ans_str.appendleft(Q[-1])
    #print(ans_str,cnt,Q)

ans=list(ans_str) if cnt==0 else list(ans_str)[::-1]
print(*ans,sep='')
import copy
s = list(input())
def make1d(n):
    return [copy.deepcopy(1) for i in range(0,n)]
t = make1d(26)
for i in range(0, len(s)):
    t[ord(s[i]) - 97] = t[ord(s[i]) - 97] * (-1)
u = 1
for i in range(0, len(s)):
    u = u * t[i]
if u == 1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import copy
s = list(input())
def make1d(n):
    return [copy.deepcopy(1) for i in range(0,n)]
t = make1d(26)
for i in range(0, len(s)):
    t[ord(s[i]) - 97] = t[ord(s[i]) - 97] * (-1)
u = 0
for i in range(0, len(t)):
    u = u + t[i]
if u == 26:
    print('Yes')
else:
    print('No')
N = int(input())
S = str(input())
 
__DEBUG__ = False
 
def main():
    count = 0    
    for i in range(N-2):
        if __DEBUG__: print(f"checking {S[i]} at index: {i}")
        if S[i] == 'A':
            if S[i+1] == 'B' and S[i+2] == 'C':
                count += 1
                # continue
    return count
 
    
if __name__ == '__main__':
  print(main())
    


### FIXED CODE ###

N = int(input())
S = str(input())
 


count = 0    
for i in range(N-2):
  if S[i] == 'A':
    if S[i+1] == 'B' and S[i+2] == 'C':
      count += 1
    
print(count)
n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp = "".join(sorted(tmp))
  s.append(tmp)
 
a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
 
# print("s:", s)
ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

### FIXED CODE ###

alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
for _ in range(n):
    s = str(input())
    freqency = [0 for _ in alphabet]
    for __ in s:
        freqency[alphabet.index(__)] += 1
    freq = "".join([str(___) for ___ in freqency])
    if freq not in res:
        res[freq] = 1
    else:
        res[freq] += 1

ans = 0
for value in res.values():
    ans += ((value-1)*value)/2
  
print(int(ans))
a, b = map(int, input().split())
ans = a*b if a<=9 ans b<=9 else -1
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
ans = a*b if 1 <= a <= 9 and 1 <= b <= 9 else -1
print(ans)
def solve(c,h,w,count):
	if 0 <= h < H and 0 <= w < W:
		if type(A[h][w]) is not int and c == A[h][w]:
			A[h][w] = count
			for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]:
				solve(c,h+dh,w+dw,count)
while 1:
	H,W = map(int,raw_input().split())
	if H == W == 0:break
	A = [list(raw_input()) for i in range(H)]
	count = 0
	for h in range(H):
		for w in range(W):
			if type(A[h][w]) is not int:
				solve(A[h][w],h ,w,count)
				count += 1
	print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)
def solve(h,w,count,c):
    if 0 <= h < H and 0 <= w < W and A[h][w] == c:
        A[h][w] = count
        for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
            solve(h+dh,w+dw,count,c)
while 1:
    H,W = map(int,raw_input().split())
    if H == W == 0: break
    A = [list(raw_input()) for _ in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if type(A[h][w]) is not int:
                solve(h,w,count,A[h][w])
                count += 1
    print count
N =int(input())
X = list(map(int,input().split()))
c = 100000000
for i in range(1,101):
  t=0
  for j in X:
    t += (j-i)**2

  if t=<c:
    t=c
print(c)


### FIXED CODE ###

N=int(input())
X= list(map(int,input().split()))
cnt = 1000000
for j in range(100):
    t = 0
    for i in X:
        t += (i-(j+1))**2
    if t <= cnt:
        cnt = t
print(cnt)
N, M = [int(x) for x in input().split()]
links = [tuple(map(int, input().split())) for _ in range(M)]
S, T = [int(x) for x in input().split()]

d = {}
for x, y in links:
    if x in d:
        d[x][0].add(y)
    else:
        d[x] = [set([y]), False]

def next_node(start):
    history = set()
    for s in start:
        if s in d:
            history |= d[s][0]
    return history

history = {S}
s = 1
while True:
    for _ in range(3):
        history = next_node(history)
    if T in history:
        print(s)
        break
    for h in tuple(history):
        if d[h][1]:
            history.remove(h)
        else:
            d[h][1] = True
    if len(history) == 0:
        print(-1)
        break
    s += 1
    

### FIXED CODE ###

N, M = [int(x) for x in input().split()]
links = [tuple(map(int, input().split())) for _ in range(M)]
S, T = [int(x) for x in input().split()]

d = {}
for x, y in links:
    if x in d:
        d[x][0].add(y)
    else:
        d[x] = [{y}, False]

def next_node(start):
    history = set()
    for s in start:
        if s in d:
            history |= d[s][0]
    return history

history = {S}
s = 1
while True:
    for _ in range(3):
        history = next_node(history)
    if T in history:
        print(s)
        break
    for h in tuple(history):
        if h not in d or d[h][1]:
            history.remove(h)
        else:
            d[h][1] = True
    if len(history) == 0:
        print(-1)
        break
    s += 1
# 写経

n = int(input())
s = input()


cnt = s[1:].count("E")
ans = cnt
for i in range(1, n):
    if s[i-1] == "W":
        cnt_e += 1
    if s[i] == "E":
        cnt_e -= 1
    ans = min(ans, cnt)


print(ans)


### FIXED CODE ###

# 写経

n = int(input())
s = input()


cnt = s[1:].count("E")
ans = cnt
for i in range(1, n):
    if s[i-1] == "W":
        cnt += 1
    if s[i] == "E":
        cnt -= 1
    ans = min(ans, cnt)


print(ans)
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np

N = int(input())
dst = np.array([[int(x) for x in input().split(" ")] for z in range(N)])
prev_dst = np.array([0] * 3)

for n in range(N):
    t,x,y = map(int, input().split(" "))
    a = (prev_dst[0] - t) - (np.abs(prev_dst[1]-x) + np.abs(prev_dst[2]-y))
    if a >= 0 and a % 2 == 0:
        prev_dst = [t,x,y]
    else:
        print("No")
        exit(0)

print("Yes")



### FIXED CODE ###

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

import numpy as np

N = int(input())
prev_dst = [0,0,0]

for n in range(N):
    t, x, y = map(int, input().split(" "))
    a = (t - prev_dst[0]) - (np.abs(prev_dst[1]-x) + np.abs(prev_dst[2]-y))
    if a >= 0 and a % 2 == 0:
        prev_dst = [t, x, y]
    else:
        print("No")
        exit(0)

print("Yes")
l=map(int(),input.split())
c=l[0]*l[1]
if c%2==1:
  print('Odd')
else:
  print('Even')

### FIXED CODE ###

a, b=(int(i) for i in input().split())
c=a*b
if c%2==1:
  print('Odd')
else:
  print('Even')
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
    A = A - 1
elif U == T:
    B = B -1
print(A, B)

### FIXED CODE ###

S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
    A = A - 1
elif U == T:
    B = B -1
print(A, B)
S=list(input())
K=int(input())
#基本は文字列一単位内でひっくり返す×単位数ですが、文字列が一つの場合と文字列の両端が同じ場合を考慮してね。
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)
S=list(input())
K=int(input())
P=0
if len(S)==1:
	P=K//2
else:
	for G in range(1,len(S)):
		B=S[G-1]
		if S[G] in B:
			S[G]='O'
			P+=1
		else:
			continue
	P=P*K
	if S[0]==S[len(S)-1]:
		P+=K-1
print(P)

### FIXED CODE ###

S=list(input())
K=int(input())
SS=S*2
F=S[0]
if len(S)==1:
	P=int(K//2)
elif S==[F]*len(S):
	P=int((len(S))*K//2)
else:
	for G in range(1,len(S)):
		if S[G-1]==S[G]:
			S[G]="O"
		else:
			continue
	A=S.count("O")
	for J in range(1,len(SS)):
		if SS[J-1]==SS[J]:
			SS[J]="O"
		else:
			continue
	B=SS.count("O")
	P=A+(B-A)*(K-1)
print(P)
n = int(input())
*a, = sorted(map(int, input().split()))

m = a[0]
while any(map(lambda x: x%m, a)):
    a = sorted([m] + list(map(lambda x: x-m, a[1:])))
    m = a[0]

print(m)


### FIXED CODE ###

from functools import reduce
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
print(reduce(gcd, a))