Problem:


Score : 300 points

Problem Statement

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 1

5
WEEWW

Sample Output 1

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.

Sample Input 2

12
WEWEWEEEWWWE

Sample Output 2

4

Sample Input 3

8
WWWWWEEE

Sample Output 3

3



Sample input:
5
WEEWW


Sample output:
1

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
minnum = 300000
for i in range(N):
    num = 0
    for j in range(N):
        if i < j and S[j] == 'E':
            num += 1
        elif i > j and S[j] == 'W':
            num += 1
    if num < minnum:
        minnum = num
    elif minnum < num:
        break
print(minnum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
minnum = 300000
for i in range(N):
    num = 0
    for j in range(N):
        if i !=j:
            if i < j and S[j] == 'E':
                num += 1
            elif i > j and S[j] == 'W':
                num += 1
    if num < minnum:
        minnum = num
    elif minnum < num:
        break
print(minnum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s1 = S[1:]
b = []
b.append(s1.count('E'))
j = 1
while j < N:
  b.append(0)
  b[j] = b[j-1]
  if S[j] == 'E':
    b[j] += -1
  if S[j-1] == 'W':
    b[j] += 1
  j += 1
print(b)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[x for x in input()]
#print(s)
answers=[]

for i in range(1,N):
    sl=s[:i]
    #print(sl)
    sr=s[i:N]

    l=sl.count("W")
    r=sr.count("E")

    ans=l+r
    #print(ans)
    answers.append(ans)
fa=min(a for a in answers)
print(fa)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[x for x in input()]
#print(s)
answers=[]

for i in range(1,N+1):
    sl=s[:i]
    #print(sl)
    sr=s[i:N]

    l=sl.count("W")
    r=sr.count("E")

    ans=l+r
    #print(ans)
    answers.append(ans)
fa=min(a for a in answers)
print(fa)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[x for x in input()]


for i in range(1,N+1):
    sl=s[:i]
    #print(sl)
    sr=s[i:N]

    l=sl.count("W")
    r=sr.count("E")
    newans=l+r
    ans=l+r-1
    if ans<newans :
        ans=newans
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[x for x in input()]
#print(s)

for i in range(1,N+1):
    sl=s[:i]
    #print(sl)
    sr=s[i:N]

    l=sl.count("W")
    r=sr.count("E")
    newans=l+r
    ans=l+r+1
    if ans<newans :
        ans=newans
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[x for x in input()]
#print(s)
answers=[]

for i in range(1,N+1):
    sl=s[:i]
    #print(sl)
    sr=s[i:N]

    l=sl.count("W")
    r=sr.count("E")

    ans=l+r
    #print(ans)
    answers.append(ans)
fa=min(a for a in answers)
print(fa)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

ruiE, ruiW = [], []
ruie,ruiw = 0, 0
for i in range(len(S)):
    if S[i] == "E":
        ruie += 1
    elif S[i] == "W":
        ruiw += 1

    ruiE.append(ruie)
    ruiW.append(ruiw)

def countE(i,j):
    if i == 0:
        return ruiE[j-1]
    else:
        return ruiE[j-1] - ruiE[i-1]

def countW(i,j):
    if i == 0:
        return ruiW[j-1]
    else:
        return ruiW[j-1] - ruiW[i-1]

#西端
ans = countE(1, len(S))

#間
for h in range(1, len(S)-1):
    count = countW(0, h-1) + countE(h+1, len(S))
    if count <= ans:
        ans = count

#東端
count = countW(0, len(S)-1)
if count <= ans:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
left_w = 0
right_e = S.count("E")
ans = left_w + right_e
for i in range(1, N):
	if S[i] == "W":
		left_w += 1
	if S[N - i] == "E":
		right_e -= 1
	ans = min(ans, right_e + left_w)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

ans = S.count('E')
tmp = ans
for i in range(1, N):
  if S[i] == 'E':
    tmp -= 1
  if S[i-1] == 'W':
    tmp += 1
  if tmp<ans:
    ans=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count=0
counts=[]
for i in range(n):
    east,west = s[:i],s[i+1:]
    for n in east:
        if n=="w":
            count+=1
    for e in west:
        if e == "E":
            count +=1
    counts.append(count)
    
print(min(counts))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count=0
counts=[]
for i in range(n):
    east,west = s[:i],s[i+1:]
    for n in east:
        if n=="w":
            count+=1
    for e in west:
        if e == "e":
            count +=1
    counts.append(count)
    
print(min(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
lst = []
orgS = S[1:N]
cutorgS = orgS.replace("W","")
cutS = len(cutorgS)
lst.append(cutS)
for i in range(2,N):
    if S[i-1] == "W" :
        if S[i] == "E":
            cutS = cutS
        else:
            cutS = cutS + 1
    else:
        if S[i] == "W":
            cutS = cutS
        else:
            cutS = cutS - 1
    lst.append(cutS)
print (min(lst))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()

w_count = [0]
e_count = [0]

a_r = list(reversed(a))

for i in range(1, n+1):
    if a[i-1] == 'W':
        w_count.append(w_count[i-1] + 1)
    else:
        w_count.append(w_count[i-1])
    if a_r[i-1] == 'E':
        e_count.append(e_count[i-1] + 1)
    else:
        e_count.append(e_count[i-1])

w = w_count[1:]
e = list(reversed(e_count[1:]))
print(w)
print(e)

sum = 10000000
for i in range(0, n):
    if sum > w[i] + e[i]:
        sum = w[i] + e[i]

print(sum-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
e=[0]
w=[0]
for i, si in enumerate(s):
    if si=='W':
        w.append(w[i]+1)
    else:
        w.append(w[i])
for i, si in enumerate(reversed(s)):
    if si=='E':
        e.append(e[i]+1)        
    else:
        e.append(e[i])

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
e=[0]
w=[0]
for i, si in enumerate(s):
    if si=='W':
        w.append(w[i]+1)
    else:
        w.append(w[i])
for i, si in enumerate(reversed(s)):
    if si=='E':
        e.append(e[i]+1)        
    else:
        e.append(e[i])

ans=float('inf')
for i in range(n):
    ans=min(ans, w[i]+e[n-i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input().strip())

min = -1

for i in range(n-1):
    if i == 0:
        turn = s[i+1:n].count("E")
    else:
        if s[i-1] == "W" and s[i] == "W":
            turn += 1
        elif s[i-1] == "W" and s[i] == "E":
            next
        elif s[i-1] =="E" and s[i] =="W":
            next
        else:
            turn -=1
    if min == -1 or min >= turn:
        min = turn
        
    

print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=n
cntW=0
cntE=s[1:].count("E")
for i in range(n):
  if s[i]=="E":
    cntE-=1
  if i>0 and s[i-1]=="W":
    cntW+=1
  ans=min(ans, cntE+cntW)
print(ans)

Submission status: Wrong Answer

Solution code:
E = "E"  # ->
W = "W"  # <-

n = int(input().rstrip())

line = input().rstrip()

bef_change_count = line[1:].count(E)
min_change_count = bef_change_count

for leader_i in range(1, n):
    change_count = bef_change_count
    if line[leader_i - 1] == E:
        change_count -= 1
    else:
        change_count += 1

    bef_change_count = change_count
    min_change_count = min(change_count, min_change_count)

print(min_change_count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
s=input()
west=[]
east=[]
for i in range(N):
    west.append(0)
    east.append(0)
    if(s[i]=='W'):
        west[i]=1
    else:
        east[i]=1
eastsum=np.zeros(N)
westsum=np.zeros(N)
westsum[0]=west[0]
eastsum[0]=east[N-1]
for i in range(1,N):
    eastsum[N-1-i]=eastsum[N-i]+east[N-1-i]
    westsum[i]=westsum[i-1]+west[i]
print(int(np.min(eastsum+westsum)))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=input()
count=[]
for i in range(N):
    count.append(0)
    count[i]=count[i]+s[:i].count('W')
    count[i]=count[i]+s[i:].count('E')
    if(s[i]=='E'):
        count[i]=count[i]-1
print(count)
print(min(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

res = min(S[1:].count("E"), S[:(N-1)].count("W"))

for n in range(1, N):
    S1 = S[:(n-1)]
    S2 = S[(n+1):]
    num = max(S1.count("W"), S2[:(N-1)].count("E"))
    if num < res:
        res = num

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i - 1] == "W":
    l += 1
  if s[n - i] == "E":
    r -= 1
  result = min(result, l + r)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i] == "W":
    l += 1
  if s[n - i] == "E":
    r -= 1
  result = min(result, l + r)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i] == "W":
    l += 1
  if s[n - i] == "E":
    r -= 1
  result = max(result, l + r)
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count("E")
count = ans
for i in range(1,n):
    if s[i-1] == "W":
        count += 1
    if s[i] == "E":
        count -= 1
    if ans > count:
        ans = count
if ans == 0:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = s.count("E")
count = ans
for i in range(1,n):
    if s[i-1] == "W":
        count += 1
    if s[i] == "E":
        count -= 1
    if ans > count:
        ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = s.count("E")
count = ans
for i in range(1,n):
    if s[i -1] == "W":
        count += 1
    if s[i] == "E":
        count -= 1
    if ans > count:
        ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(input())
ans = 0
for i in range(n):
  fi = li[:i-1]
  se = li[i+1:]
  hoge = fi.count('E') + se.count('W')
  if ans < hoge:
    ans = hoge
 
print(n - ans - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(input())
ans = 0
piyo = 0
for i in range(n):
  fi = li[:i-1]
  se = li[i+1:]
  hoge = fi.count('W') + se.count('E')
  if piyo < hoge:
    ans = i
    piyo = hoge

print(ans)

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

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

L = []
for i in S:
	if(i not in L):
		L.append(i)

if(len(L) == 1):
	print(1)

else:
	ans = 9999999999
	for i in range(0,N-1):
		cur = 0
		left = S[:i]
		right = S[i+1:]
		e = right.count('E')
		w = left.count('W')
		cur = e+w
#		print(cur,i)
		ans = min(ans,cur)
	print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
l = []

c = 0
for i in s:
  if i == "E":
    c+=1

min = c


for i in range(n-1):
  if s[i] == s[i+1]:
    if s[i] == "W":
      c+=1
    else:
      c-=1
  if c < min:
    min = c

print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
l = []

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

minarg = -1
mini = 114514
sum = 0

for i in range(n-1):
  sum += l[i]
  if sum<mini:
    mini = sum
    minarg = i

hoge = 0
if minarg == 0:
  for i in range(1,n-1):
    if s[i] == "E":
      hoge+=1
elif minarg == n-1:
  for i in range(n-1):
    if s[i] == "W":
      hoge+=1
else:
  for i in range(n):
    if s[i] == "W" and i < minarg+1:
      hoge+=1
    elif s[i] == "E" and i > minarg+1:
      hoge+=1

print(hoge)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
l = []

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

minarg = -1
mini = 114514
sum = 0

for i in range(n-1):
  sum += l[i]
  if sum<mini:
    mini = sum
    minarg = i

hoge = 0
if minarg == 0:
  for i in range(1,n-1):
    if s[i] == "E":
      hoge+=1
else:
  for i in range(n):
    if s[i] == "W" and i < minarg+1:
      hoge+=1
    elif s[i] == "E" and i > minarg+1:
      hoge+=1

print(hoge)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
l = []

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

minarg = -1
mini = 114514
sum = 0

for i in range(n-1):
  sum += l[i]
  if sum<mini:
    mini = sum
    minarg = i

hoge = 0
for i in range(n-1):
  if s[i] == "W" and i < minarg:
    hoge+=1
  elif s[i] == "E" and i > minarg:
    hoge+=1

print(hoge)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())

reS = S[::-1]

wSum = [0 for i in range(N)]
eSum = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        if S[i] == 'W':
            wSum[i] = 1
        if reS[i] == 'E':
            eSum[i] = 1
    else:
        if S[i] == 'W':
            wSum[i] = wSum[i-1] + 1
        else:
            wSum[i] = wSum[i-1]
        if reS[i] == 'E':
            eSum[i] = eSum[i-1] + 1
        else:
            eSum[i] = eSum[i-1]

eSum = eSum[::-1]

cost = eSum[1]

for i in range(1,N):
    if i == N - 1:
        if cost > wSum[N-2]:
            cost = wSum[N-2]
    else:
        if cost > wSum[i-1] + eSum[i+1]:
            cost = eSum[i-1] + eSum[i+1]
print(cost)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(str(input()))

min = 3*10**5
cnt = 0

cnt = S.count("E")

for i in S:
  if min >= cnt:
    min = cnt
  if i == "E":
    cnt -= 1
  elif i == "W":
    cnt += 1

print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(str(input()))

min = 3*10**5
cnt = 0

cnt = S.count("E")

for i in S:
  if i == "E":
    cnt -= 1
  elif i == "W":
    cnt += 1
  if min >= cnt:
    min = cnt

print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

Snum = [(S[i] == 'W') for i in range(N)]
print([sum(Snum[:i]) + (N - i - 1 - sum(Snum[i+1:])) for i in range(N)])

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

e = S.count("E")

left = 0
right = e

look = [left + right]


if S[0]=="W":
    Wdesu = True
else:
    Wdesu = False
    
for i in range(1,N):
    if Wdesu:
        left = left + 1
    
    if S[i] == "W":
        Wdesu = True
    else:
        Wdesu = False
        right = right - 1
    look.append(left + right)

print(min(look))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0

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

for reader in range(1, N):
    minus = 0
    if S[reader] == "E":
        minus = 1
    if S[reader - 1] == "W":
        ans += 1
    elif S[reader - 1] == "E":
        ans -= 1
    if ans - minus < min_ans:
        min_ans = ans - minus
        count = reader

print(min_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
print ('{}'.format(min([N-S.count('W')-1,N-S.count('E')-1])))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    ec = S.count('E')
    wc = 0
    min = N
    for k in S:
        if k == 'E':
            ec -= 1
        else:
            wc += 1
        if min > ec + wc: min = ec + wc
    print(min)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    lst = []
    c = 0
    for i in range(N):
        if S[i] == 'W': c += 1
        lst.append(c)
    min = lst[N - 1] - lst[0]
    c = 0
    for i in range(1, N - 1):
        c = lst[i] + N - lst[N - 1] - (i + 1 - lst[i])
        if min > c: min = c
    if min > N - lst[N - 1]: min = N - lst[N - 1]
    print(min)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(input())
p=m.count("E")
s=p
for i in m:
    if i=="E":
        p-=1
    else:
        p+=1
    s=min(s,p)
    print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]-num_list[i]+i+1-num_list[i]
  ans_list.append(ans)
print(ans_list)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]-num_list[i]+i+1+num_list[0]-num_list[i]
  ans_list.append(ans)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]-num_list[i]+i+1+num_list[0]-num_list[i]
  ans_list.append(ans)
print(ans_list)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]+i+1-num_list[0]
  ans_list.append(ans)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]+i+1-num_list[0]
  ans_list.append(ans)
print(ans_list)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range(N):
  ans=num_list[N-1]-num_list[i]
  ans_list.append(ans)
print(min(ans_list))

Submission status: Wrong Answer

Solution code:

N = int(input())
S = input()
ans = 0

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

for reader in range(1, N):
    if S[reader - 1] == "W":
        ans += 1
    if S[reader - 1] == "E":
        ans -= 1
    if ans < min_ans:
        min_ans = ans

print(min_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
ans = 0

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

for reader in range(1, N):
    if S[reader - 1] == "W":
        ans += 1
    if S[reader - 1] == "E":
        ans -= 1
    if ans  < min_ans:
        min_ans = ans

print(min_ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding:utf-8 -*-

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

m = n
for i in range(1, n):
    left = s[:i].count('W')
    right = s[i:].count('E')
    if left + right < m:
        m = left + right
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())

last_count = 0
for border in range(N):
    # 入れ替える回数
    count = 0
    for i in range(N):
        if i < border:
            if S[i] == 'W':
                count += 1
        elif i > border:
            if S[i] == 'E':
                count += 1

    if border == 0:
        last_count = count
    else:
        if last_count < count:
            print(last_count)
            exit()

    last_count = count

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_num = 10**7
west_num = [0]
east_num = [0]
w_max = 0
e_max = 0
for i in range(0, N): #累積和を求める.
    if S[i] == 'W':
        w_max += 1
    else:
        e_max += 1
        
    west_num.append(w_max)
    east_num.append(e_max)

for i in range(0, N):
    num = west_num[i] + east_num[-1] - east_num[i+1]
    if num < min_num:
        min_num = num
        
print(west_num)
print(east_num)
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_num = 10**6
west_num = [0]
east_num = [0]
w_max = 0
e_max = 0
for i in range(0, N): #累積和を求める.
    if S[i] == 'W':
        w_max += 1
    else:
        e_max += 1
        
    west_num.append(w_max)
    east_num.append(e_max)

for i in range(0, N):
    num = 0
    num = west_num[i] + east_num[-1] - east_num[i]
    if num < min_num:
        min_num = num
        
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_num = 10**6
west_num = [0]
east_num = [0]

for i in range(0, N): #累積和を求める.
    if S[i] == 'W':
        west_num.append(1 + max(west_num))
        east_num.append(max(east_num))
    else:
        west_num.append(max(west_num))
        east_num.append(1 + max(east_num))

for i in range(0, N):
    num = 0
    num = west_num[i] + east_num[-1] - east_num[i]
    if num < min_num:
        min_num = num
        
print(min_num)
print(west_num)
print(east_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_num = 10**6


for i in range(0, N):
    num = 0
    if S[i] == 'E':
        num = sum(x == 'W' for x in S[:i]) + sum(x == 'E' for x in S[i+1:])
    
    else:
        num = sum(x == 'E' for x in S[:i]) + sum(x == 'W' for x in S[i+1:])
        
    if num < min_num:
        min_num = num

        
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

W = [0 for k in range(N)]
E = [0 for k in range(N)]

for k in range(1,N):
    if S[k-1] == "W":
        W[k] = W[k-1] + 1
    else:
        W[k] = W[k-1]

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

ans = 10*9
for k in range(N):
    ans = min(W[k]+E[k],ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

W = [0 for k in range(N)]
E = [0 for k in range(N)]

w = 0
for k in range(N):
    if S[k] == "W":
        w += 1
    W[k] = w

e = 0
for k in range(N):
    if S[N-k-1] == "E":
        e += 1
    E[N-k-1] = e

ans = 10*9
for k in range(N):
    ans = min(W[k]+E[k]-1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:

N = input()
S = raw_input()

ans = 0
ans_w = 0
ans_e = 0

for i in S:
    if i == 'E':
        ans_e += 1

ans = ans_e - 1

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

print ans

Submission status: Wrong Answer

Solution code:
N = input()
S = raw_input()

ans = 0
ans_w = 0
ans_e = 0

for i in S:
    if i == 'E':
        ans_e += 1

ans = ans_e

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

print ans

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
counter = s.count("E")
ans = counter
for i in range(1,n):
	if s[i-1] == "W":
		counter += 1
	elif s[i-1] == "E":
		counter -= 1
	if ans >= counter:
		ans = counter
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
m=n+5
w=0
e=0
for i in range(1,n):
    if s[i]=='E':
        e+=1
m=min(m,w+e)
for i in range(1,n):
    if s[i-1]=='W':
        w+=1
    if s[i]=='E':
        e-=1
    m=min(m,w+e)

Submission status: Wrong Answer

Solution code:


N = int(input())
S = input()
#N = 12
#S = 'WEWEWEEEWWWE'


min = 1000000
e = S.count('E')
w = 0

for i in range(0,N-1):
    flag = 0
    now = S[i]
    if now == 'E':
        e = e - 1
    else:
        flag = 1
    sum = w + e
    if min > sum:
        min = sum
    if flag:
        w = w + 1
print(min)

Submission status: Wrong Answer

Solution code:

N = int(input())
S = input()
#N = 12
#S = 'WEWEWEEEWWWE'


min = 1000000
e = S.count('E')
w = 0

for i in range(0,N-1):
    flag = 0
    now = S[i]
    if now == 'E' and e != 0:
        e = e - 1
    else:
        flag = 1
    sum = w + e
    if min > sum:
        min = sum
    if flag:
        w = w + 1
print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
alle=list(s).count("E")
allw=n-alle
ecnt=wcnt=0
for i in range(n):
    if s[i] == "W":
        ans.append(wcnt+alle-ecnt)
        wcnt+=1
    else:
        ans.append(wcnt+alle-ecnt-1)
        ecnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
alle=list(s).count("E")
allw=n-alle
ecnt=wcnt=0
for i in range(n):
    ans.append(wcnt+alle-ecnt)
    if s[i] == "W":
        wcnt+=1
    else:
        ecnt+=1
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
alle=list(s).count("E")
allw=n-alle
ecnt=wcnt=0
for i in range(n):
    ans.append(wcnt+alle-(i-wcnt+ecnt))
    if s[i] == "W":
        wcnt+=1
    else:
        ecnt+=1
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=[]
alle=list(s).count("E")
allw=n-alle
ecnt=wcnt=0
for i in range(n):
    ans.append(wcnt+alle-(i-wcnt))
    if s[i] == "W":
        wcnt+=1
    else:
        ecnt+=1
print(min(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
w,e=0,s.count('E')
for i in range(n):
    if i =='W':
        n=min(n,w+e)
        w+=1
    else:
        e-=1
        n=min(n,w+e)
print(n)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = stdin.readline().rstrip()
S = stdin.readline().rstrip()


min = 10000000

N = int(N)

for i in range(1, N+1):
    X = S[:i]
    Y = S[i+1:N]
    
    n = X.count("W") + Y.count("E")
    if min > n:
        min = n


print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = n
for i in range(n):
    e = s[:i]
    w = s[i + 1:]
    ans = min(ans,e.count('E') + w.count('W'))
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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


s = list(S)


#s.reverse()
s = np.array([1 if i == 'E' else 0 for i in s])
#str = S.replace('E','1')
#bit_str = str.replace('W','0')
#bit = int(bit_str, base=2)

cost = [0]*N
cost[0] = N - sum(s) - 2*1^s[0]
for i in range(1,N):
    now = s[i]
    bef = s[i-1]
    cost[i] = cost[i-1] + bef - ~now

print(min(cost))

Submission status: Wrong Answer

Solution code:
import numpy as np

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


s = list(S)


#s.reverse()
s = np.array([1 if i == 'E' else 0 for i in s])
#str = S.replace('E','1')
#bit_str = str.replace('W','0')
#bit = int(bit_str, base=2)

cost = [0]*N
cost[0] = N - sum(s) - 1^s[0]
for i in range(1,N):
    now = s[i]
    bef = s[i-1]
    cost[i] = cost[i-1] + bef - ~now

print(min(cost))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())

total = s.count("E")

min_val = total

for char in s:
    min_val = min(min_val, total)
    if char == "E":
        total -= 1
    else:
        total += 1

print(min_val)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
min_count = 10000000000
count = len([s for s in S[1:] if s == "E"])
for i in range(1, N):
    if S[i - 1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    min_count = min(min_count, count)
print(min_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
min_count = 10000000000
count = len([s for s in S[1:] if s == "E"])
for i in range(2, N):
    if S[i - 1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    min_count = min(min_count, count)
print(min_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())

pre_count = 0
post_count = len([k for k in range(N) if S[k] == 'E'])
count = post_count
for i in range(1, N):
    if S[i-1] == 'W':
        pre_count += 1
    if S[i] == 'E':
        post_count -= 1
    if count > pre_count + post_count:
        count = pre_count + post_count

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

sum_w = 0
sum_e = 0

for i in S:
    if i == 'W':
        sum_w += 1
    else:
        sum_e += 1

ct_w = 0
ct_e = 0
ans = N + 1

for i in range(N):
    ans = min(ans, ct_w + sum_e - ct_e)

    if S[i] == 'W':
        ct_w += 1
    else:
        ct_e += 1

if ct_w == 0 or ct_e == 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

sum_w = 0
sum_e = 0

for i in S:
    if i == 'W':
        sum_w += 1
    else:
        sum_e += 1

ct_w = 0
ct_e = 0
ans = N + 1

for i in range(N):
    ans = min(ans, ct_w + sum_e - ct_e)

    if S[i] == 'W':
        ct_w += 1
    else:
        ct_e += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

n = p = S[1:].count("E")

for i in range(0,N-1):
    n = min(p, n)
    if S[i+1] == "E":
        p -= 1
    if S[i] == "W":
        p += 1

print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

n = p = S[1:].count("E")

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

print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

n = p = S[1:].count("E")

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

print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

n = p = S[1:].count("E")

for i in range(1,N):
    if S[i-1] == "W":
        p += 1
    else:
        p -= 1
    n = min(p, n)

print(n)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    s = input()

    cnt = s.count("E")
    min_cnt = cnt

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

    print(min_cnt)

if __name__=='__main__':
   solve()

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
a=S.count("E")
b=S.count("W")
d=min(a,b)
print(d-1)