N = int(eval(input()))

S = eval(input())



E = [0]*(N)

W = [0]*(N)



# 反対方向の人を数え上げ

for i in range(N):

  if S[i] == "E":

    E[i] = 1

  else:

    W[i] = 1

    

# リーダーより前を累積和していく

for i in range(1, N):

  W[i] += W[i-1]

  E[i] += E[i-1]



ans = float("inf")  

for i in range(N):

  sm = 0

  if 0 < i:

    sm += W[i-1]

  sm += E[N-1] - E[i]

  ans = min(ans, sm)

    

print(ans)    
N = int(eval(input()))

S = eval(input())



pos = 0

minpos = 0

mini = 0



for i in range(N):

  if S[i] == "W":

    pos += 1

  else:

    pos -= 1

  if pos < minpos:

    minpos = pos

    mini = i



s1 = S[0:mini].count("W")

s2 = S[mini+1:N].count("E")

print((s1+s2))
N = int(eval(input()))
S = eval(input())
E = [0] * (N)
W = [0] * (N)
# 反対方向の人を数え上げ
for i in range(N):
    if S[i] == "E":
        E[i] = 1
    else:
        W[i] = 1
# リーダーより前を累積和していく
for i in range(1, N):
    W[i] += W[i - 1]
    E[i] += E[i - 1]
ans = float("inf")
for i in range(N):
    sm = 0
    if 0 < i:
        sm += W[i - 1]
    sm += E[N - 1] - E[i]
    ans = min(ans, sm)
print(ans)

N = int(eval(input()))
S = eval(input())
pos = 0
minpos = 0
mini = 0
for i in range(N):
    if S[i] == "W":
        pos += 1
    else:
        pos -= 1
    if pos < minpos:
        minpos = pos
        mini = i
s1 = S[0:mini].count("W")
s2 = S[mini + 1 : N].count("E")
print((s1 + s2))

-E = [0] * (N) -W = [0] * (N) -# 反対方向の人を数え上げ +pos = 0 +minpos = 0 +mini = 0 -    if S[i] == "E": -        E[i] = 1 +    if S[i] == "W": +        pos += 1 -        W[i] = 1 -# リーダーより前を累積和していく -for i in range(1, N): -    W[i] += W[i - 1] -    E[i] += E[i - 1] -ans = float("inf") -for i in range(N): -    sm = 0 -    if 0 < i: -        sm += W[i - 1] -    sm += E[N - 1] - E[i] -    ans = min(ans, sm) -print(ans) +        pos -= 1 +    if pos < minpos: +        minpos = pos +        mini = i +s1 = S[0:mini].count("W") +s2 = S[mini + 1 : N].count("E") +print((s1 + s2))