n = int(eval(input()))

s = eval(input())



w, e = 0, 0

cumsum = []

for i in range(n):

    if s[i] == "W":

        w += 1

        cumsum.append([w, e])

    else:

        e += 1

        cumsum.append([w, e])



ans = 10 ** 6

for i in range(n):

    if s[i] == "W":

        r = cumsum[-1][1] - cumsum[i][1]

        l = cumsum[i][0] - 1

        ans = min(ans, r+l)

    elif s[i] == "E":

        r = cumsum[-1][1] - cumsum[i][1]

        l = cumsum[i][0]

        ans = min(ans, r+l)



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

s = eval(input())



sum_e = s.count("E")

sum_w = s.count("W")



cnt_e, cnt_w = 0, 0



ans = 10 ** 6

for x in s:

    if x == "E":

        cnt_e += 1

        ans = min(ans, cnt_w + (sum_e - cnt_e))

    if x == "W":

        ans = min(ans, cnt_w + (sum_e - cnt_e))

        cnt_w += 1



print(ans)
n = int(eval(input()))
s = eval(input())
w, e = 0, 0
cumsum = []
for i in range(n):
    if s[i] == "W":
        w += 1
        cumsum.append([w, e])
    else:
        e += 1
        cumsum.append([w, e])
ans = 10**6
for i in range(n):
    if s[i] == "W":
        r = cumsum[-1][1] - cumsum[i][1]
        l = cumsum[i][0] - 1
        ans = min(ans, r + l)
    elif s[i] == "E":
        r = cumsum[-1][1] - cumsum[i][1]
        l = cumsum[i][0]
        ans = min(ans, r + l)
print(ans)

n = int(eval(input()))
s = eval(input())
sum_e = s.count("E")
sum_w = s.count("W")
cnt_e, cnt_w = 0, 0
ans = 10**6
for x in s:
    if x == "E":
        cnt_e += 1
        ans = min(ans, cnt_w + (sum_e - cnt_e))
    if x == "W":
        ans = min(ans, cnt_w + (sum_e - cnt_e))
        cnt_w += 1
print(ans)

-w, e = 0, 0 -cumsum = [] -for i in range(n): -    if s[i] == "W": -        w += 1 -        cumsum.append([w, e]) -    else: -        e += 1 -        cumsum.append([w, e]) +sum_e = s.count("E") +sum_w = s.count("W") +cnt_e, cnt_w = 0, 0 -for i in range(n): -    if s[i] == "W": -        r = cumsum[-1][1] - cumsum[i][1] -        l = cumsum[i][0] - 1 -        ans = min(ans, r + l) -    elif s[i] == "E": -        r = cumsum[-1][1] - cumsum[i][1] -        l = cumsum[i][0] -        ans = min(ans, r + l) +for x in s: +    if x == "E": +        cnt_e += 1 +        ans = min(ans, cnt_w + (sum_e - cnt_e)) +    if x == "W": +        ans = min(ans, cnt_w + (sum_e - cnt_e)) +        cnt_w += 1