n = int(eval(input()))

s = eval(input())



W_csum = [0] * n

E_csum = [0] * n

if s[0] == 'W':

    W_csum[0] = 1

else:

    E_csum[0] = 1

for i in range(1,n):

    if s[i] == 'W':

        W_csum[i] = W_csum[i-1] + 1

        E_csum[i] = E_csum[i-1]

    else:

        W_csum[i] = W_csum[i-1]

        E_csum[i] = E_csum[i-1] + 1



W_csum_r = [0] * n

E_csum_r = [0] * n

if s[-1] == 'W':

    W_csum_r[0] = 1

else:

    E_csum_r[0] = 1

for i,j in enumerate(list(range(n-2,-1,-1)),1):

    if s[j] == 'W':

        W_csum_r[i] = W_csum_r[i-1] + 1

        E_csum_r[i] = E_csum_r[i-1]

    else:

        W_csum_r[i] = W_csum_r[i-1]

        E_csum_r[i] = E_csum_r[i-1] + 1



W_csum_r.reverse()

E_csum_r.reverse()



ans = float('inf')

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

    num = 0

    if s[i] == 'W':

        num += E_csum_r[i+1]

        num += W_csum[i-1]

    else:

        num += E_csum_r[i+1]

        num += W_csum[i-1]

    if num < ans:

        ans = num



if ans > E_csum_r[1]:

    ans = E_csum_r[1]

if ans > W_csum[-2]:

    ans = W_csum[-2]



print(ans)

    



n = int(eval(input()))

s = eval(input())

 

W_csum = [0] * (n+1)

E_csum = [0] * (n+1)

for i in range(n):

    if s[i] == 'W':

        W_csum[i+1] = W_csum[i] + 1

        E_csum[i+1] = E_csum[i]

    else:

        W_csum[i+1] = W_csum[i]

        E_csum[i+1] = E_csum[i] + 1

E_csum.append(E_csum[-1])



ans = float('inf')

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

    count = 0

    count += W_csum[i-1]

    count += E_csum[-1] - E_csum[i]

    if count < ans:

        ans = count

print(ans)
n = int(eval(input()))
s = eval(input())
W_csum = [0] * n
E_csum = [0] * n
if s[0] == "W":
    W_csum[0] = 1
else:
    E_csum[0] = 1
for i in range(1, n):
    if s[i] == "W":
        W_csum[i] = W_csum[i - 1] + 1
        E_csum[i] = E_csum[i - 1]
    else:
        W_csum[i] = W_csum[i - 1]
        E_csum[i] = E_csum[i - 1] + 1
W_csum_r = [0] * n
E_csum_r = [0] * n
if s[-1] == "W":
    W_csum_r[0] = 1
else:
    E_csum_r[0] = 1
for i, j in enumerate(list(range(n - 2, -1, -1)), 1):
    if s[j] == "W":
        W_csum_r[i] = W_csum_r[i - 1] + 1
        E_csum_r[i] = E_csum_r[i - 1]
    else:
        W_csum_r[i] = W_csum_r[i - 1]
        E_csum_r[i] = E_csum_r[i - 1] + 1
W_csum_r.reverse()
E_csum_r.reverse()
ans = float("inf")
for i in range(1, n - 1):
    num = 0
    if s[i] == "W":
        num += E_csum_r[i + 1]
        num += W_csum[i - 1]
    else:
        num += E_csum_r[i + 1]
        num += W_csum[i - 1]
    if num < ans:
        ans = num
if ans > E_csum_r[1]:
    ans = E_csum_r[1]
if ans > W_csum[-2]:
    ans = W_csum[-2]
print(ans)

n = int(eval(input()))
s = eval(input())
W_csum = [0] * (n + 1)
E_csum = [0] * (n + 1)
for i in range(n):
    if s[i] == "W":
        W_csum[i + 1] = W_csum[i] + 1
        E_csum[i + 1] = E_csum[i]
    else:
        W_csum[i + 1] = W_csum[i]
        E_csum[i + 1] = E_csum[i] + 1
E_csum.append(E_csum[-1])
ans = float("inf")
for i in range(1, n + 1):
    count = 0
    count += W_csum[i - 1]
    count += E_csum[-1] - E_csum[i]
    if count < ans:
        ans = count
print(ans)

-W_csum = [0] * n -E_csum = [0] * n -if s[0] == "W": -    W_csum[0] = 1 -else: -    E_csum[0] = 1 -for i in range(1, n): +W_csum = [0] * (n + 1) +E_csum = [0] * (n + 1) +for i in range(n): -        W_csum[i] = W_csum[i - 1] + 1 -        E_csum[i] = E_csum[i - 1] +        W_csum[i + 1] = W_csum[i] + 1 +        E_csum[i + 1] = E_csum[i] -        W_csum[i] = W_csum[i - 1] -        E_csum[i] = E_csum[i - 1] + 1 -W_csum_r = [0] * n -E_csum_r = [0] * n -if s[-1] == "W": -    W_csum_r[0] = 1 -else: -    E_csum_r[0] = 1 -for i, j in enumerate(list(range(n - 2, -1, -1)), 1): -    if s[j] == "W": -        W_csum_r[i] = W_csum_r[i - 1] + 1 -        E_csum_r[i] = E_csum_r[i - 1] -    else: -        W_csum_r[i] = W_csum_r[i - 1] -        E_csum_r[i] = E_csum_r[i - 1] + 1 -W_csum_r.reverse() -E_csum_r.reverse() +        W_csum[i + 1] = W_csum[i] +        E_csum[i + 1] = E_csum[i] + 1 +E_csum.append(E_csum[-1]) -for i in range(1, n - 1): -    num = 0 -    if s[i] == "W": -        num += E_csum_r[i + 1] -        num += W_csum[i - 1] -    else: -        num += E_csum_r[i + 1] -        num += W_csum[i - 1] -    if num < ans: -        ans = num -if ans > E_csum_r[1]: -    ans = E_csum_r[1] -if ans > W_csum[-2]: -    ans = W_csum[-2] +for i in range(1, n + 1): +    count = 0 +    count += W_csum[i - 1] +    count += E_csum[-1] - E_csum[i] +    if count < ans: +        ans = count