n=int(eval(input()))

s=list(eval(input()))

cnt=s[1:].count("E")

e_cnt=[0]*(n+1)

w_cnt=[0]*(n+1)

e_cnt[0]=cnt

for i in range(n):

    w_cnt[i+1]=w_cnt[i]+(s[i]=="W")#Wの数を累積和でとる

for i in range(1,n):

    e_cnt[i]=e_cnt[i-1]-(s[i]=="E")#Eの数を累積和でとる

ans=float("inf")

for i in range(n):

    ans=min(ans,w_cnt[i]+e_cnt[i])

print(ans)

n=int(eval(input()))

s=list(eval(input()))

w_cnt=[0]*(n+1)

e_cnt=[0]*(n+1)

s.insert(0,"G")

for i in range(1,n+1):

    if s[i]=="W":

        w_cnt[i]=w_cnt[i-1]+1

    else:

        w_cnt[i]=w_cnt[i-1]

s.reverse()

s.pop(n)

s.insert(0,"G")

for i in range(1,n+1):

    if s[i]=="E":

        e_cnt[i]=e_cnt[i-1]+1

    else:

        e_cnt[i]=e_cnt[i-1]

ans=float("inf")

for i in range(n):

    temp=w_cnt[i]+e_cnt[n-1-i]

    if temp<=ans:

        ans=temp

print(ans)

n = int(eval(input()))
s = list(eval(input()))
cnt = s[1:].count("E")
e_cnt = [0] * (n + 1)
w_cnt = [0] * (n + 1)
e_cnt[0] = cnt
for i in range(n):
    w_cnt[i + 1] = w_cnt[i] + (s[i] == "W")  # Wの数を累積和でとる
for i in range(1, n):
    e_cnt[i] = e_cnt[i - 1] - (s[i] == "E")  # Eの数を累積和でとる
ans = float("inf")
for i in range(n):
    ans = min(ans, w_cnt[i] + e_cnt[i])
print(ans)

n = int(eval(input()))
s = list(eval(input()))
w_cnt = [0] * (n + 1)
e_cnt = [0] * (n + 1)
s.insert(0, "G")
for i in range(1, n + 1):
    if s[i] == "W":
        w_cnt[i] = w_cnt[i - 1] + 1
    else:
        w_cnt[i] = w_cnt[i - 1]
s.reverse()
s.pop(n)
s.insert(0, "G")
for i in range(1, n + 1):
    if s[i] == "E":
        e_cnt[i] = e_cnt[i - 1] + 1
    else:
        e_cnt[i] = e_cnt[i - 1]
ans = float("inf")
for i in range(n):
    temp = w_cnt[i] + e_cnt[n - 1 - i]
    if temp <= ans:
        ans = temp
print(ans)

-cnt = s[1:].count("E") +w_cnt = [0] * (n + 1) -w_cnt = [0] * (n + 1) -e_cnt[0] = cnt -for i in range(n): -    w_cnt[i + 1] = w_cnt[i] + (s[i] == "W")  # Wの数を累積和でとる -for i in range(1, n): -    e_cnt[i] = e_cnt[i - 1] - (s[i] == "E")  # Eの数を累積和でとる +s.insert(0, "G") +for i in range(1, n + 1): +    if s[i] == "W": +        w_cnt[i] = w_cnt[i - 1] + 1 +    else: +        w_cnt[i] = w_cnt[i - 1] +s.reverse() +s.pop(n) +s.insert(0, "G") +for i in range(1, n + 1): +    if s[i] == "E": +        e_cnt[i] = e_cnt[i - 1] + 1 +    else: +        e_cnt[i] = e_cnt[i - 1] -    ans = min(ans, w_cnt[i] + e_cnt[i]) +    temp = w_cnt[i] + e_cnt[n - 1 - i] +    if temp <= ans: +        ans = temp