N=int(eval(input()))

S=eval(input())

l,r=[0]*N,[0]*N

for i in range(N-1):

    l[i+1]+=l[i]+(S[i]=='W')

for i in range(N-1,0,-1):

    r[i-1]+=r[i]+(S[i]=='E')

ans=3*10**5

for i in range(N):

    ans=min(ans,l[i]+r[i])

print(ans)

N=int(eval(input()))

S=eval(input())

ans=cur=S.count('E')

for c in S:

    cur+=-1 if c=='E' else 1

    ans=min(ans,cur)

print(ans)

N = int(eval(input()))
S = eval(input())
l, r = [0] * N, [0] * N
for i in range(N - 1):
    l[i + 1] += l[i] + (S[i] == "W")
for i in range(N - 1, 0, -1):
    r[i - 1] += r[i] + (S[i] == "E")
ans = 3 * 10**5
for i in range(N):
    ans = min(ans, l[i] + r[i])
print(ans)

N = int(eval(input()))
S = eval(input())
ans = cur = S.count("E")
for c in S:
    cur += -1 if c == "E" else 1
    ans = min(ans, cur)
print(ans)

-l, r = [0] * N, [0] * N -for i in range(N - 1): -    l[i + 1] += l[i] + (S[i] == "W") -for i in range(N - 1, 0, -1): -    r[i - 1] += r[i] + (S[i] == "E") -ans = 3 * 10**5 -for i in range(N): -    ans = min(ans, l[i] + r[i]) +ans = cur = S.count("E") +for c in S: +    cur += -1 if c == "E" else 1 +    ans = min(ans, cur)