There are N people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.
Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.
Find the minimum number of people who have to change their directions.

-----Constraints-----
 - 2 \leq N \leq 3 \times 10^5
 - |S| = N
 - S_i is E or W.

-----Input-----
Input is given from Standard Input in the following format:
N
S

-----Output-----
Print the minimum number of people who have to change their directions.

-----Sample Input-----
5
WEEWW

-----Sample Output-----
1

Assume that we appoint the third person from the west as the leader.
Then, the first person from the west needs to face east and has to turn around.
The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.
It is not possible to have 0 people who have to change their directions, so the answer is 1.

Difficulty: introductory

Starter code:

Solutions:
n=int(input())
s=input()

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

for i in range(1,n):
  if s[i-1]=="W":
    cnt+=1
  if s[i]=="E":
    cnt-=1
  ans=min(ans,cnt)

print(ans)

N = int(input())
S = list(input())

e_count = 0
for s in S:
  if s == 'E':
    e_count += 1

min_inv = float('infinity')
    
for s in S:
  if s == 'E':
    e_count -= 1
  
  min_inv = min(e_count, min_inv)
  
  if s == 'W':
    e_count += 1

print(min_inv)


n=int(input())
s=input()
W_cnt=[0]
E_cnt=[0]

for ss in s:
  w=W_cnt[-1]
  if ss=="W":
    w+=1
  W_cnt.append(w)

for ss in reversed(s):
  e=E_cnt[-1]
  if ss=="E":
    e+=1
  E_cnt.append(e)
E_cnt=E_cnt[::-1]

minc=float("inf")
for i in range(n):
  c=(W_cnt[i] + E_cnt[i+1])
  minc=min(minc,c)
print(minc)


N = int(input())
S = list(input())
ans_list = []

ans = S[1:].count("E")
ans_list.append(ans)

for i in range(1,N):
  if S[i-1] == "W":
    ans += 1
  if S[i] == "E":
    ans -= 1
  ans_list.append(ans)

print(min(ans_list))

N = int(input())
S = input()
numE = [0] * N
numW = [0] * N
for i in range(N):
    if S[i] == 'E':
        numE[i] += 1
    else:
        numW[i] += 1
    if 0 < i:
        numE[i] += numE[i - 1]
        numW[i] += numW[i - 1]
ans = N
for i in range(N):
    if i == 0:
        val = numE[-1] - numE[i]
    elif i == N - 1:
        val = numW[i - 1]
    else:
        val = numE[-1] - numE[i] + numW[i - 1]
    ans = min(ans, val)
print(ans)

N = int(input())
S = input()

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

for i in range(1,N):
  if S[i-1] == "W":
    cnt += 1
  if S[i] == "E":
    cnt -= 1
  ans = min(ans, cnt)
  
print(ans)

n = int(input())
s = str(input())
sE = s.count('E')
sW = s.count('W')
l = []
e, w = 0, 0
for ch in s:
    if ch == 'E':
        e += 1
    else:
        w += 1
    m = (sE-e)+w
    l.append(sE-e+w-1 if ch == 'W' else sE-e+w)
print((min(l)))


#!/usr/bin/env python3

from itertools import accumulate
n = int(input())
s = [0 if i == "E" else 1 for i in str(input())]

s_cumsum = list(accumulate(s))
s_cumsum_rev = list(accumulate(reversed(s)))

ans = 10**10

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

    a_1 = s_cumsum[i-1]
    a_0 = i - a_1
    b_1 = s_cumsum_rev[-2-i]
    b_0 = (n-1-i) - b_1

    # print(a_1+b_0)
    ans = min(ans, a_1+b_0)

ans = min(ans, s_cumsum[-2])
ans = min(ans, (n-1)-s_cumsum_rev[-2])
print(ans)


N = int(input())
S = list(input())

minCount = N
left =  0
right = S.count("E")
for n in range(0, N):
    if n != 0 and S[n-1] == "W":
        left += 1

    if S[n] == "E":
        right -= 1

    if minCount > left + right:
        minCount = left + right

print(minCount)


N = int(input())
S = list(input())

sum_W = [0]
for i in range(1, N):
    if S[i-1] == "W":
        sum_W.append(sum_W[i-1]+1)
    else:
        sum_W.append(sum_W[i-1])

sum_E = [S[1:].count("E")]
for i in range(0, N-1):
    if S[i+1] == "E":
        sum_E.append(sum_E[i]-1)
    else:
        sum_E.append(sum_E[i])

counts = []
for i in range(N):
    count = 0
    counts.append(sum_W[i]+sum_E[i])

print(min(counts))

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


n = int(input())
s = input()
res = n
e = s.count("E")

l_w = 0
l_e = 0
for i in range(n):
    if i == n - 1 and s[i] == "E":
        l_e += 1
    tmp = l_w + (e - l_e)
    res = min(tmp, res)
    if s[i] == "W":
        l_w += 1
    else:
        l_e += 1
print(res)


n = int(input())
s = str(input())
left = s[0]
ans = 10**6
left = {}
left.setdefault('W',0)
left.setdefault('E',0)
right = {}
right.setdefault('E',0)
right.setdefault('W',0)
for i in range(n):
    right[s[i]] += 1
ans = 10**6
for i in range(n):
    right[s[i]] -= 1
    ans = min(ans,left['W']+right['E'])
    #print(left,right)
    left[s[i]] += 1
print(ans)
    


import math
import sys
import os
from operator import mul
import numpy as np

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


N = I()
S = list(_S())
ans = N

Sn = np.array(S)
S_cum = np.zeros(N+1,dtype='int')
S_cum[1:] = np.cumsum(Sn=='W')

Snr=np.flip(Sn, 0)
S_cumr = np.zeros(N+1,dtype='int')
S_cumr[1:] = np.cumsum(Snr=='E')

# print(S_cum)
# print(S_cumr)

for i in range(N):
    attention = S_cum[i] + S_cumr[N-(i+1)]
    # print(attention)
    ans = min(ans, attention)

print(ans)

n = int(input())
s = input()

w = [0]*n
e = [0]*n
if s[0] == "W": w[0] = 1
else: e[0] = 1
for i in range(1,n):
  if s[i] == "W":
    w[i] = w[i-1]+1
    e[i] = e[i-1]
  else:
    w[i] = w[i-1]
    e[i] = e[i-1]+1

ans = float("inf")
for i in range(n):
  t = 0
  if i != 0: t += w[i-1]
  if i != n-1: t += e[-1] - e[i]
  if t < ans: ans = t
print(ans)  

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N = ii()
S = input()
cnt = [0] * N

for i in range(N):
    if S[i] == 'W':
        cnt[i] = 1

cnt = list(accumulate(cnt))
ans = N

for i in range(N):
    if S[i] == 'E':
        ans = min(ans, cnt[i] + (N-1-i)-(cnt[-1]-cnt[i]))
    else:
        ans = min(ans, i+1-cnt[i] + (N-1-i)-(cnt[-1]-cnt[i]))

print(ans)

N=int(input())
S=list(input())
e,w=[0]*(N+1),[0]*(N+1)
for i in range(1,N+1):
    w[i] += w[i-1] + (1 if S[i-1]=='W' else 0)
    e[i] += e[i-1] + (1 if S[i-1]=='E' else 0)
ans=N
for i in range(N):
    ans=min(ans,w[i]+e[-1]-e[i+1])
print(ans)

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    s = input()

    ans = 0
    for i in s[1:]:
        if i == "E":
            ans += 1
    l = [ans]

    for i in range(n-1):
        trial = 0
        if s[i] == "W":
            trial += 1
        if s[i+1] == "E":
            trial -= 1
        ans += trial
        l.append(ans)

    print((min(l)))


def __starting_point():
    main()

__starting_point()

n = int(input())
s = input()
arr = []
E = s.count('E')
w = 0
e = 0
for i in range(n):
  if s[i] == 'W':
    arr.append(w + E - e)
    w += 1
  else:
    arr.append(w + E - e - 1)
    e += 1
ans = min(arr)
print(ans)

N = int(input())
S = input()
e = S.count("E")
cnt = e
for i in S:
    if i == "E":
        cnt -= 1
    else:
        cnt += 1
    e = min(e, cnt)
print(e)

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n = int(input())
    s = list(input())
    enum = [1 if c == 'E' else 0 for c in s]
    wnum = [1 if c == 'W' else 0 for c in s]
    enuma = tuple(accumulate(enum))
    wnuma = tuple(accumulate(wnum))
    wnumm = wnuma[-1]
    wnuma2 = [wnumm - wn for wn in wnuma]
    num = max(wnuma2[0], enuma[-2])
    for i1 in range(1, n - 1):
        num = max(num, enuma[i1 - 1] + wnuma2[i1])
    r = n - num - 1
    print(r)

def __starting_point():
    main()
__starting_point()

#
# abc096 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    S = list(input())

#    ans = float("inf")
#    for i in range(N):
#        if i == 0:
#            ans = min(ans, S[1:].count("E"))
#        elif i == N-1:
#            ans = min(ans, S[0:N-1].count("W"))
#        else:
#            ans = min(ans, S[0:i].count("W") + S[i+1:].count("E"))
#    print(ans)

    W = [0] * N
    E = [0] * N
    L = 0
    R = 0

    for i in range(N):
        if S[i] == "W":
            L += 1
        if S[N-1-i] == "E":
            R += 1
        W[i] = L
        E[N-1-i] = R

    ans = float("inf")
    for i in range(N):
        ans = min(ans, E[i]+W[i]-1)
    print(ans)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

EW=0
ans=99999999999999999999999999999999

N=int(input())
S=input()

for i in range(N):
    if i==0:
        pass
    elif S[i]=="E":
        EW+=1
if ans>EW:
    ans=EW

for j in range(1,N):
    if S[j]=="E":
        EW-=1
    if S[j-1]=="W":
        EW+=1

    if ans>EW:
        ans=EW
print(ans)


N=int(input())
S=list(input())
e,w=[0]*(N+1),[0]*(N+1)
for i in range(1,N+1):
    w[i] += w[i-1] + (1 if S[i-1]=='W' else 0)
    e[i] += e[i-1] + (1 if S[i-1]=='E' else 0)
ans=N
for i in range(N):
    ans=min(ans,w[i]+e[-1]-e[i+1])
print(ans)

n=int(input())
s=input()

def count(n,s):
    cntw=0
    cnte=0
    mcntw=0
    mcnte=0
    maxn=0
    for i in range(n):
        if s[i]=="W":
            cntw+=1
        else:
            cnte+=1
        if maxn<cnte-cntw:
            maxn=cnte-cntw
            mcnte=cnte
            mcntw=cntw

    if cntw==0 or cnte==0:
        print((0))
        return

    else:
        print((mcntw+cnte-mcnte))
        return
count(n,s)



N = int(input())
S = list(input())

ans = N

left_W = 0
right_E = S[1:].count("E")

for n in range(N):
  if n == 0:
    ans = min(ans,S[1:].count("E"))
        
  elif n == N-1 :
    ans = min(ans,S[:n].count("W"))
      
  else:
    if S[n] == "E":
      right_E -= 1
    if S[n-1] == "W":
      left_W += 1
    ans = min(ans,left_W + right_E)

print(ans)

N = int(input())
S = input()
ans =  S.count("E")
left = 0
right = ans
for i in S:
    if i == "E":
        right -= 1
        ans = min(ans,right+left)
    if i == "W":
        ans = min(ans,right+left)
        left += 1
print(ans)

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

num_E = [0] * N
num_W = [0] * N
max_num = 0
leader_index = 0
for i, c in enumerate(S):
    if c == "W":
        num_W[i] = num_W[i - 1] + 1
        num_E[i] = num_E[i - 1]
    else:
        num_W[i] = num_W[i - 1]
        num_E[i] = num_E[i - 1] + 1
    tmp = num_E[i] - num_W[i]
    if max_num < tmp:
        leader_index = i
        max_num = tmp

print(S[:leader_index].count("W") + S[leader_index + 1:].count("E"))

n = int(input())
s = input()
l = [0]*n
r = [0]*n
for i in range(1, n):
    l[i] = l[i-1] + (s[i-1] == 'W')
for i in range(n-2, -1, -1):
    r[i] = r[i+1] + (s[i+1] == "E")
ans = n-1
for i in range(n):
    ans = min(ans, l[i]+r[i])
print(ans)



n = int(input())
s = input()
l = [0] * n
r = [0] * n
ans = n
for i in range(n):
    if i == 0:
        if s[0] == "W":
            l[0] = 1
    elif s[i] == "W":
        l[i] = l[i - 1] + 1
    else:
        l[i] = l[i - 1]
    if i == 0:
        if s[-1] == "E":
            r[0] = 1
    elif s[-i-1] == "E":
        r[i] = r[i - 1] + 1
    else:
        r[i] = r[i - 1]
for i in range(n):
    if i == 0:
        ans = min(ans, r[n - 1 - i])
    elif i == n - 1:
        ans = min(ans, l[i - 1])
    else:
        ans = min(ans, l[i - 1] + r[n - 1 - i])
print(ans)

N = int(input())
S = input()

A = [0]*N
B = [0]*N

for i in range(1, N):
    A[i] = A[i-1] + (1 if S[i-1]=='W' else 0)
    B[N-i-1] = B[N-i] + (1 if S[N-i]=='E' else 0)

print(min(map(lambda x: x[0]+x[1], zip(A, B))))

import math

n = int(input())
s = input()

eS = [0] * n
wS = [0] * n

ec = 0
for i in range(n):
    eS[i] = ec
    if s[i] == "W":
        ec += 1

wc = 0
for i in reversed(list(range(n))):
    wS[i] = wc
    if s[i] == "E":
        wc += 1

ans = 10000000

for i in range(n):
    ans = min(ans, eS[i] + wS[i])

print(ans)


n = int(input())
s = input()
e = s.count('E')
w = s.count('W')
ans = 1000000
e_counter = 0
w_counter = 0
for i in range(len(s)):
    if s[i] == 'E':
        e_counter += 1
    else:
        w_counter += 1
    d = w_counter
    if s[i] == 'W':
        d -= 1
    ans1 = d + (e - e_counter)
    ans = min(ans1, ans)
print(ans)

N = int(input())
S = list(input())
directed = [S[1:].count("W")]

for i in range(1, len(S)):
  d = directed[i - 1]
  if S[i - 1] == "E":
    d += 1
  if S[i] == "W":
    d -= 1
  directed.append(d)

print(N - max(directed) - 1)

n=int(input())
s=list(input())
sw=[0]
se=[0]
swc=0
sec=0
for i in range(n):
    if s[i]=='W':
        swc+=1
    else:
        sec+=1
    sw.append(swc)
    se.append(sec)
m=n
for i in range(n+1):
    m=min(m,sw[i]+se[-1]-se[i])
print(m)


n = int(input())
A =input()
e = A.count('E')
cnt = e

for i in A:
    if i == 'E':
        cnt -= 1
    else:
        cnt += 1
    e = min(e,cnt)

print(e)

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 20:18:57 2020

@author: liang
"""

N = int(input())
S = input()

tmp = 0

for i in range(1,N):
    if S[i] == "E":
        tmp += 1

ans = 10**6
for i in range(N):
    if ans > tmp:
        ans = tmp
    if i == N-1:
        break
    if S[i] == "W":
        tmp += 1
    if S[i+1] == "E":
        tmp -= 1
    #print(tmp)
        
print(ans)

N = int(input())
S = input()


w_cnt = 0
e_cnt = 0
w_lst = []
e_lst = []

for s in S:
    if s == 'W':
        w_cnt += 1

    else:
        e_cnt += 1

    w_lst.append(w_cnt)
    e_lst.append(e_cnt)

ans = float('inf')
e_all = e_lst[-1]
for i in range(N):
    if S[i] == 'W':
        t = w_lst[i] - 1 + e_all - e_lst[i]
    else:
        t = w_lst[i] + e_all - e_lst[i]

    ans = min(ans, t)


print(ans)

n = int(input())
a = list(input())
wcnt,ecnt,ans,box = 0,0,0,[]
W = a.count("W")
E = a.count("E")
for i in range(n-1):
  if a[i] == "W":
    box.append(E+wcnt)
    wcnt += 1
    W -= 1
  else:
    box.append(E+wcnt)
    ecnt += 1
    E -= 1
if a[n-1] == "W":
  W -= 1
  box.append(E+wcnt)
  wcnt += 1
else:
  E -= 1
  box.append(E+wcnt)
  ecnt += 1
print(min(box))

n = int(input())
s = input()

e_all = s.count("E")
w_all = s.count("W")
e_l = 0
w_l = 0

unti = [0] * n

for i in range(n):
    if s[i] == "E":
        e_l += 1
        unti[i] = w_l + (e_all - e_l) 
    if s[i] == "W":
        unti[i] = w_l + (e_all - e_l) 
        w_l += 1


#print(unti)
print(min(unti))

n = int(input())
s = input()

left = [0] * n
right = [0] * n

tmp = 0
for i in range(1, n):
    if s[i - 1] == "W":
        tmp += 1
        left[i] = tmp
    else:
        left[i] = tmp

tmp = 0
for i in range(n - 2, -1, -1):
    if s[i + 1] == "E":
        tmp += 1
        right[i] = tmp
    else:
        right[i] = tmp

res = 10**9
for i in range(n):
    res = min(res, left[i] + right[i])
print(res)


N = int(input())
S = input()

EP = [0]*(N+1)
WP = [0]*(N+1)
CP = [0]*N
for T in range(0,N):
    EP[N-T-1] = EP[N-T]+(S[N-1-T]=='E')
    WP[T+1] = WP[T]+(S[T]=='W')
for T in range(0,N):
    CP[T] = EP[T+1]+WP[T]
print(min(CP))

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    east = [0] * (N + 1)
    west = [0] * (N + 1)
    for i in range(N):
        east[i + 1] = east[i] + (1 if S[i] == 'E' else 0)
        west[i + 1] = west[i] + (1 if S[i] == 'W' else 0)

    ans = INF
    for i in range(N):
        if ans > west[i] + east[N] - east[i + 1]:
            ans = west[i] + east[N] - east[i + 1]

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

n=int(input())
s=input()
v=[0 for i in range(n)]

for i in range(n):
    j=0
    if s[i]=="E":
        j=1
    else:
        j=-1
    if i==0:
        v[i]+=j
    else:
        v[i]+=j+v[i-1]

sum=-2
w=0
res=""
for i in range(n):
    if sum<v[i]:
        sum=v[i]
        wmax=w
        emax=i-w
        res=s[i]
    if s[i]=="W":
        w+=1

if res=="W":
    print((wmax+s.count("E")-emax))
else:
    print((wmax+s.count("E")-emax-1))


N = int(input())
S = list(input())
allW = S.count('W')
allE = S.count('E')
numW = S.count('E')
numE = 0
ans = 3*10**5
for i in range(N):
    if S[i] == 'E':
        numW -= 1
    ans = min(ans,numW + numE)
    if S[i] == 'W':
        numE += 1   
print(ans)

N = int(input())
S = list(input())

lst = [0]*N
Re = S.count("E")
Lw = 0

for i in range(N):
    if S[i] == "E":
        Re -= 1
        lst[i] = Re + Lw
    else:
        Lw += 1
        lst[i] = Re + Lw - 1

ans = min(lst)
print(ans)


n=int(input())
s=input()

dp_w=[0]
dp_e=[0]

for i in range(n):
    if i!=0:
        dp_w.append(dp_w[-1])
        dp_e.append(dp_e[-1])
    if s[i]=="W":
        dp_w[-1]+=1
    else:
        dp_e[-1]+=1

def migi(i):
    if i==n-1:
        return 0
    return dp_e[n-1]-dp_e[i]
def hidari(i):
    if i==0:
        return 0
    return dp_w[i-1]
ans=1000000000000000
for i in range(n):
    right=migi(i)
    left=hidari(i)
    ans=min(right+left,ans)
print(ans)

n = int(input())
s = list(input())
cnt = 0
ans_list = [0]
e_cnt = 0

for i in range(1,n):
    if s[i-1] == "E" and s[i] == "E":
        cnt -= 1
        e_cnt += 1
    if s[i-1] == "E" and s[i] == "W":
        cnt -= 0
    if s[i-1] == "W" and s[i] == "E":
        cnt += 0
        e_cnt += 1
    if s[i-1] == "W" and s[i] == "W":
        cnt += 1
    ans_list.append(cnt)

print(min(ans_list) + e_cnt)

from collections import Counter
n = int(input())
s = input()
sn = Counter(s)

l = 0
r = sn['E']

ans = r
for i in range(n):
    if s[i] == 'W':
        l += 1
    else:
        r -= 1
    ans = min(ans, l+r)
print(ans)


n = int(input())
s = input()

w = [0]*n
e = [0]*n

if s[0] == "W": w[0] += 1
else: e[0] += 1
for i in range(1,n):
  if s[i] == "W":
    w[i] = w[i-1]+1
    e[i] = e[i-1]
  else:
    w[i] = w[i-1]
    e[i] = e[i-1]+1

ans = float("inf")
if e[n-1]-e[0] < ans: ans = e[n-1]-e[0]
if w[n-1] < ans: ans = w[n-1]

for i in range(1,n-1):
  t = w[i-1] + e[n-1]-e[i]
  if t < ans: ans = t
print(ans)

n = int(input())
s = input()

ans = [0]*(n+1)
for i in range(n):
  if s[i] == 'E':
    ans[i+1] = ans[i] + 1
  else:
    ans[i+1] = ans[i]
    
print(min(i-ans[i]+ans[n]-ans[i+1] for i in range(n)))

def count(left_w, right_e):
    return left_w + right_e


def main():
    n = int(input())
    s = str(input())

    w_count = s.count('W')
    e_count = n - w_count

    lst = []
    left = 0
    left_w = 0
    right = n
    right_e = e_count
    for i in range(n):
        s_alp = s[i]
        right -= 1
        if s_alp == 'E':
            right_e -= 1

        lst.append(count(left_w, right_e))

        left += 1
        if s_alp == 'W':
            left_w += 1

    minimum = min(lst)
    print(minimum)


def __starting_point():
    main()
__starting_point()

n = int(input())
s = input()
e = s.count("E")
w = n - e
ans = 10**9
if s[0] == "W":
    cnt = e
else:
    cnt = e-1
num = cnt
for i in range(n-1):
    if s[i] == s[i+1] and s[i] == "E":
        cnt -= 1
    elif s[i] == s[i+1]:
        cnt += 1
    ans = min(ans,cnt,num)
    ans = max(ans,0)
print(max(ans,0))

n=int(input())
s=list(input())
ans=[0]*n
ans[0]+=list(s[1:]).count("E")
for i in range(1,n):
    if s[i]=="E" and s[i-1]=="E":
        ans[i]=ans[i-1]-1
    elif (s[i]=="E" and s[i-1]=="W") or (s[i-1]=="E" and s[i]=="W"):
        ans[i]=ans[i-1]    
    else:
        ans[i]=ans[i-1]+1
print(min(ans))

# -*- coding: utf-8 -*-

N = int(input())
S = list(input())

W = [0] * N
E = [0] * N

W_pre = E_pre = 0
for i in range(N):
    if S[i] == "W":
        W[i] = W_pre + 1
        E[i] = E_pre
    else:
        W[i] = W_pre
        E[i] = E_pre + 1
    W_pre = W[i]
    E_pre = E[i] 

ans = N
for i in range(N):
    if i>0:
        res1 = W[i-1]
    else:
        res1 = 0
    res2 = E[N-1]-E[i]
    #print(i,res1,res2)
    ans = min(ans,res1+res2)

print(ans)


N = int(input())
S = input()
a = S.count("E")
c = a 

for s in S:
  if s=="E":
    c-=1
  else:
    c+=1
  a=min(a,c)

print(a)

N = int(input())
S = input()
l = 0
r = S[1:N].count('E')
ans = l+r

for n in range(1,N):
  if S[n-1]=="W":
    l+=1
  if S[n]=="E":
    r-=1
  ans=min(ans,l+r)

print(ans)

n = int(input())
s = input()

count = s.count('E')
ans = s.count('E')
for i in range(len(s)):
    if s[i] == 'E':
        count -=1
    else:
        count+=1
    ans = min(count,ans)
print(ans)

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: list(map(int, INPUT().split()))
S_MAP = lambda: list(map(str, INPUT().split()))
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

    left, right = 0, S[1:].count('E')
    ans = left + right
    for i in range(N-1):
        if S[i] == 'W':
            left += 1
        if S[i+1] == 'E':
            right -= 1

        ans = min(ans, left + right)

    print(ans)


def __starting_point():
    main()

__starting_point()

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# # from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, S):
    W_sum = [0]
    E_sum = [0]
    for s in list(S):
        if s == 'W':
            W_sum.append(W_sum[-1] + 1)
            E_sum.append(E_sum[-1])
        else:
            W_sum.append(W_sum[-1])
            E_sum.append(E_sum[-1] + 1)

    ans = N + 1
    for i in range(1, N + 1):
        ans = min(W_sum[i - 1] + (E_sum[-1] - E_sum[i]), ans)

    print(ans)



def __starting_point():
    N = int(input())
    S = input()
    solve(N, S)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

__starting_point()

n=int(input())
s=list(input())

E=s.count('E')
W=s.count('W')

if s[0]=='E':
  ans=E-1
else:
  ans=E
  
ans1=[]
ans1.append(ans)
  
for x in range(1,n):
  if s[x]=='E':
    if s[x-1]=='E':
      ans-=1
      
  else:
    if s[x-1]=='W':
      ans+=1
  ans1.append(ans)
  
print(min(ans1))

def main():
    N = int(input())
    S = input()
    lst = [0] * N
    ans = N

    if S[0] == "E":
        lst[0] = 1
    for i in range(1, N):
        if S[i] == "E":
            lst[i] = lst[i - 1] + 1
        else:
            lst[i] = lst[i - 1]

    for i in range(N):
        if i == 0:
            left = 0
        else:
            left = i - lst[i - 1]
        right = lst[N - 1] - lst[i]

        if left + right < ans:
            ans = left + right

    print(ans)


def __starting_point():
    main()

__starting_point()

N = int(input())
S = list(input())
E = S[1:].count('E')
W = 0
mi = E+W
for i in range(1,N):
    if S[i] == 'E':E -= 1
    if S[i-1] == 'W':W+=1
    if E+W <= mi:mi = E+W
print(mi)


N = int(input())
S = input()

west = [0]*N
east = [0]*N

tmp = 0
for i in range(1,N):
    if S[i-1] == 'W':
        tmp += 1
        west[i] = tmp
    else:
        west[i] = tmp

tmp = 0
for i in range(N-2,-1,-1):
    if S[i+1] == 'E':
        tmp += 1
        east[i] = tmp
    else:
        east[i] = tmp

ans = float('inf')
for i in range(N):
    ans = min(ans,west[i]+east[i])
print (ans)


import sys

N = int(input())
S = input()

W = [0]*N
E = [0]*N
ans = N
for i in range(1, N):
    W[i] = W[i-1]+1 if S[i-1]=='W' else W[i-1]
    E[-i-1] = E[-i]+1 if S[-i]=='E' else E[-i]

for i in range(N):
    ans = min(W[i]+E[i], ans)

print(ans)





n=int(input())
S=list(input())
W=[0]*(n+1)
E=[0]*(n+1)
for i in range(n):
  W[i]=W[i-1]+S[i].count("W")
  E[n-i-1]=E[n-i]+S[n-i-1].count("E")
W = W[:n]
E = E[:n]
ans = 1000000
for i in range(n):
  ans = min(ans,W[i]+E[i]-1)
print(ans)


n=int(input())
s=input()
W=0 ; E=s[1:].count("E")
ans=float("inf")
for i in range(n):
    ans=min(ans, W+E)
    if i==n-1:print(ans);return
    if s[i]=="W":
        W+=1
    if s[i+1]=="E":
        E-=1

N = int(input())
S = input()

e_all = S.count('E')

w_cnt = 0
e_cnt = 0
ans = float('inf')
for i in range(N):
    if S[i] == 'W':
        w_cnt += 1
        ans = min(ans, w_cnt - 1 + e_all - e_cnt)
    else:
        e_cnt += 1
        ans = min(ans, w_cnt + e_all - e_cnt)

print(ans)


n = int(input())
s = input()

from collections import Counter
count = Counter(s[1:])
x = count["E"]

temp =x
for i in range(1,n):
    if s[i-1] =="W":
        x +=1
    if s[i] =="E":
        x -=1
    temp = min(temp,x)

print(temp)        

n = int(input())
s = input()
res = n
w = 0
e = 0
for i in range(n):
    if s[i] == "W":
        w += 1
    else:
        e += 1

l_w = 0
l_e = 0
for i in range(n):
    if i == n - 1 and s[i] == "E":
        l_e += 1
    tmp = l_w + (e - l_e)
    res = min(tmp, res)
    if s[i] == "W":
        l_w += 1
    else:
        l_e += 1
print(res)


N = int(input())
S = input()
west = S.count('W')
east = N - west 
Q = [0,0,west,east] #[自分より西で西向き、東向き、自分より東で西向き、東向き]
ans = N-1
for i in range(N):
    if S[i]=='W':
        Q[2]-=1
        cnt = Q[0]+Q[3]
        Q[0]+=1
    else:
        Q[3]-=1
        cnt = Q[0]+Q[3]
        Q[1]+=1
    ans = min(ans,cnt)
print(ans)

N = int(input())
r = input()

E_sum = sum(x == "E" for x in r)
W_sum = N-E_sum
left_sum = 0
right_sum = E_sum
min_sum = E_sum
for i in range(N):
  if i == 0:
    if r[i] == "E":
      min_sum -= 1
    prev_sum = min_sum
  else:
    if (r[i-1], r[i]) == ("W", "W"):
      prev_sum += 1
    elif (r[i-1], r[i]) == ("E", "W"):
      pass
    elif (r[i-1], r[i]) == ("E", "E"):
      prev_sum -= 1
    elif (r[i-1], r[i]) == ("W", "E"):
      pass
  if min_sum > prev_sum:
    min_sum = prev_sum

print(min_sum)

#!/usr/bin/env python

n = int(input())
s = input()

total_E = s.count('E')
total_W = n-total_E

right_E = []
tmp_E = total_E
tmp_W = 0 
for i in range(n):
    if s[i] == 'E':
       tmp_E -= 1 
    right_E.append(tmp_E)

left_W = [0] 
for i in range(1,n):
    if s[i-1] == 'W':
       tmp_W += 1 
    left_W.append(tmp_W)

candidates = []
for i in range(n):
    candidates.append(right_E[i]+left_W[i])

#print('candidates =', candidates)
#print('right_E =', right_E)
#print('left_W =', left_W)
ans = min(candidates)
print(ans)


n = int(input())
s = [(i == "W")*1 for i in list(input())]
c = [0]*(n+1)
for i in range(n):
    c[i+1] = c[i] + s[i]
ans = float("inf")
for i in range(n):
    t = c[i] + (n-i-1-c[-1]+c[i+1])
    ans = min(ans,t)
print(ans)

inf = float('inf')
n = int(input())
s = input()

right_e = s.count("E")
left_w = 0
cnt = inf

for e in s:
  if e == "W":
    cnt = min(cnt, right_e + left_w)
    left_w += 1
  else:
    right_e -= 1
    cnt = min(cnt, right_e + left_w)
print(cnt)

N=int(input())
S=input()
a=[0]
for i in range(N):
    a.append(a[-1])
    if S[i]=='W':
        a[-1]+=1

ans=N
for i in range(N):
    ans=min(ans,a[i]+N-(i+1)-(a[N]-a[i+1]))
print(ans)


n = int(input())
s = input()
wcnt = [0] * n
ecnt = [0] * (n)
enum = 0
wnum = 0
for i in range(n):
    if s[i] == "W":
        wnum += 1
    wcnt[i] += wnum
    if s[-i - 1] == "E":
        enum += 1
    ecnt[-i - 1] += enum
ans = 10 ** 10
for i in range(n):
    temp = 0
    if i - 1 >= 0:
        temp += wcnt[i - 1]
    if i + 1 < n:
        temp += ecnt[i + 1]
    ans = min(ans, temp)
print(ans)


N=int(input())
S=input()
ans=S.count("W")
ans1=-10
for i in range(N):
  if S[i]=="W":
    ans-=1
  if i!=0:
    if S[i-1]=="E":
      ans+=1
  ans1=max(ans,ans1)
print(N-1-ans1)

n=int(input())
s=input()
l,r=[],[]
ans=min(s.count("W"),s.count("E"))
k=s.count("E")
for i in range(n):
    if s[i]=="W":
        k+=1
    else:
        k-=1
    ans=min(ans,k)
print(ans)

def main():
    n = int(input())
    ss = list(input())
    num_sum = [0]*n
    west_sum = 0
    east_sum = 0
    for i in range(1, n):
        if ss[i-1] == 'W':
            west_sum += 1
        num_sum[i] += west_sum

    for i in range(n-2, -1, -1):
        if ss[i+1] == 'E':
            east_sum += 1
        num_sum[i] += east_sum

    ans = min(num_sum)
    print(ans)

def __starting_point():
    main()

__starting_point()

from itertools import accumulate
n = int(input())
s = list(input())
l = [1 if s[i] == "E" else 0 for i in range(n)]
l = list(accumulate(l))
ans = l[-1]-l[0]
for i in range(1, n):
    ans = min(ans, i-l[i-1] + l[-1]-l[i])
print(ans)

def schange(s):
    if s=="E":
        return 1
    else:
        return 0

n = int(input())
s = list(map(schange,input()))
ssum = [0]*(n+1)

for i in range(n):
    ssum[i+1] = ssum[i] + s[i]

ans = float('inf')
for i in range(1,n+1):
    turnE = (i-1)-ssum[i-1]
    turnW = ssum[-1] - ssum[i]
    ans=min(ans,turnE+turnW)
    
print(ans)

N = int(input())
S = input()
 
oE = S.count("E")
Wo = 0

L = []
for i in range(N):
    if i == 0:
        if S[i] == "E":
            oE -= 1
    else:
        if S[i-1] == "W":
            Wo += 1
        if S[i] == "E":
            oE -= 1
    L.append(Wo + oE)
    if Wo + oE == 0:
        break
print(min(L))

n = int(input())
s = input()

li = []
for i in range(n):
    if s[i]=="W":
        li.append(-1)
    else:
        li.append(1)

cumsum = [li[0]]
for i in range(n-1):
    cumsum.append(cumsum[i] + li[i+1])

l = cumsum.index(max(cumsum))
w_to_e = 0
e_to_w = 0

for i in range(n):
    if i < l:
        if li[i]==-1:
            w_to_e += 1
    elif i > l:
        if li[i]==1:
            e_to_w += 1
print(e_to_w + w_to_e)

from collections import deque

N=int(input())
S=input()

left=deque([0])
right=[0]
for i in range(N):
  if S[i]=='W':plus=1
  else:plus=0
  left.append(left[-1]+plus)
  if S[-i-1]=='E':plus=1
  else:plus=0
  right.append(right[-1]+plus)
  
left.popleft()
right = right[::-1]
right.pop()

print(min([left[i]+right[i] for i in range(N)])-1)

N=int(input())
S=list(str(input()))
east=S[1:].count('E')
ans_min = east
ans = east
for l in range(1,N):
  if S[l-1]=='W':
    ans+=1
  if S[l]=='E':
    ans-=1
  if ans<=0:
    ans_min = 0
    break
  if ans < ans_min:
    ans_min = ans
print(ans_min)


N=int(input())
S=list(input())

dp_f=[0 for _ in range(N)]
dp_b=[0 for _ in range(N)]
for n in range(1,N):
    if S[n-1]=="W":
        tmp=1
    else:
        tmp=0
    dp_f[n]=dp_f[n-1]+tmp

for n in reversed(range(N-1)):
    if S[n+1]=="E":
        tmp=1
    else:
        tmp=0
    dp_b[n]=dp_b[n+1]+tmp

MIN=N
for n in range(N):
    if n==N-1:
        MIN=min(MIN,dp_f[N-1])
    elif n==0:
        MIN=min(MIN,dp_b[0])
    else:
        MIN=min(MIN,dp_f[n]+dp_b[n])
print(MIN)

n = int(input())
s = input()
cnt_e = [0] * n
cnt_w = [0] * n
for i in range(n):
    if i == 0 :
        if s[i] == 'E':
            cnt_e[i] = 1
        else :
            cnt_w[i] = 1
    else :
        if s[i] == 'E':
            cnt_e[i] = cnt_e[i-1] + 1
            cnt_w[i] = cnt_w[i-1]
        else :
            cnt_e[i] = cnt_e[i-1]
            cnt_w[i] = cnt_w[i-1] + 1
ans = 3 * 10**5 + 1
for i in range(n):
    if s[i] == 'E':
        e = cnt_e[-1] - cnt_e[i]
        w = cnt_w[i]
    else :
        e = cnt_e[-1] - cnt_e[i]
        w = cnt_w[i] - 1
    ans = min(ans, e + w)
print(ans)


N=int(input())
S=input()
S="N"+S+"N"
ans=0
E=0
W=S.count("W")
for i in range(1,N+1):
    if S[i-1]=="E":
        E+=1
    if S[i]=="W":
        W-=1
    tmp=E+W
    if tmp>ans:
        ans=tmp
ans=N-1-ans
print(ans)


n = int(input())
s = input()

west_back = s.count("W")
east_back = n-west_back
west_front = 0
east_front = 0

ans = 10**6
for i in range(n):
    if s[i] == "W":
        west_front += 1
        west_back -= 1
        key = west_front+east_back-1
    else:
        east_front += 1
        east_back -= 1
        key = west_front+east_back
    ans = min(ans, key)
print(ans)


n = int(input())
s = input()
c = [0,0]
for i in range(n):
    if (s[i]=="E"):
        c[0] += 1
    else:
        c[1] += 1
b = [0,0]
ans = c[0]
for i in range(n):
    if (s[i]=="E"):
        c[0] -= 1
        b[0] += 1
    else:
        c[1] -= 1
        b[1] += 1
    ans = min(ans,c[0]+b[1])
print(ans)

N = int(input())
N_List = str(input())
C_Ans = N_List[1:].count("E")
Ans = C_Ans
for i in range(1,N):
    C_Ans = C_Ans + (0,1)[N_List[i-1] == "W"] - (0,1)[N_List[i] == "E"]
    if C_Ans < Ans:
        Ans = C_Ans

print(Ans)

n = int(input())
s = input()

# full search
cnt = s.count('E')

ans = cnt
for i in range(n):
    if s[i] == 'E':
        cnt -= 1
        if ans > cnt:
            ans = cnt
    
    else:
        cnt += 1

print(ans)

n=int(input())
s=input()
data=[0]*(n+1)
for i in range(n):
  if s[i]=='E':
    data[i+1]=data[i]+1
  else:
    data[i+1]=data[i]
print(min(i-data[i]+data[n]-data[i+1] for i in range(n)))

import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return list(map(int, stdin.readline().split()))
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    S = ns()
    E = np.cumsum([1 if s == 'E' else 0 for s in S][::-1])[::-1]
    W = np.cumsum([1 if s == 'W' else 0 for s in S])
    ans = E + W
    print((np.min(ans) - 1))


def __starting_point():
    main()

__starting_point()

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

N = int(input())
S = input()
L = [0]*(N+1)
for i in range(N):
  if S[i]=="E":
    L[i+1] = L[i]+1
  else:
    L[i+1] = L[i]
print(min(i-L[i]+L[N]-L[i+1] for i in range(N)))

n = int(input())
s = input()

dp = [0] * n

for i in range(1,n):
  if s[i] == "E":
    dp[0] += 1

for i in range(1,n):
  dp[i] = dp[i-1]
  if s[i-1] == "W":
    dp[i] += 1
  if s[i] == "E":
    dp[i] -= 1

print(min(dp))

import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [_ for _ in input()]

left, right = 0, S[1:].count('E')
ans = left + right
for i in range(N-1):
    if S[i] == 'W':
        left += 1
    if S[i+1] == 'E':
        right -= 1

    ans = min(ans, left + right)

print(ans)