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()

min_count = N

left = {'W':0, 'E':0}
w = S.count('W')
right = {'W':w, 'E':N-w}

for i in range(N):
    base = S[i]
    right[base] -= 1
    min_count = min(left['W']+right['E'], min_count)
    left[base] += 1
print('ANS', min_count)

Submission status: Wrong Answer

Solution code:
def we(s):
    cnt=s.count('E')
    ans=29999
    for i in s:
        if i=='E':
            cnt-=1
        else:
            ans=min(ans,cnt)
            cnt+=1
    return min(cnt,ans)
input()
print(we(input()))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
l = [i for i in S]
ew = []
ans = int(10e10)
a = l.count("E") 

i = 0
while True:
    num = S.find("EW",i+1)
    if num != -1:
      ew.append(num)
      i = num
    else:
      break
      
for i in ew:
  ans = min(ans,l[:i+1].count("W")*2 + a-i-1)

if ans == int(10e10):
  print(min(l.count("W"),l.count("E")))
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
mi = N
cnt = 0
micnt = N
for i in range(1, N):
  if S[i-1] == "W":
    cnt += 1
  else:
    cnt -= 1
  if cnt < micnt:
    mi = i
    micnt = cnt
if S[0] == "W":
  cnt -= 1
else:
  cnt += 1
if S[N-1] == "W":
  cnt += 1
else:
  cnt -= 1
if -cnt < micnt:
  mi = 0

A = 0
for i in range(N):
  if mi > i:
    if S[i] == "W":
      A += 1
  elif mi < i:
    if S[i] == "E":
      A += 1
    
print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
cusum = [0]*N
cusum[0] = 1 if S[0] == 'E' else 0

for i in range(1,N):
    cusum[i] = cusum[i-1]
    if S[i] == 'E':
        cusum[i]+=1
ans = 999999999999
for i in range(N):
    if i == 0:
        tmp = cusum[N-1] - cusum[0]
    elif i == N-1:
        tmp = N-1 - cusum[N-1]
    else:
        tmp = i - cusum[i-1]
        tmp += cusum[N-1] - cusum[i]
    ans = min(tmp, ans)
print(ans)

Submission status: Wrong Answer

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

output=S.count("E")
a=output

for i in range(N-1):
    if(S[i]=="W"):
        a+=1
    if(S[i+1]=="E"):
        a-=1
    if(a<output):
        output=a
print(output)

Submission status: Wrong Answer

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

e = []
w = []
ek = 0
wk = 0
for i in range(n):
    if s[i] == "E":
        ek += 1
        e.append(ek)
        w.append(wk)
    if s[i] == "W":
        wk += 1
        e.append(ek)
        w.append(wk)

ma = e[n-1]-e[0]
print(e)
print(w)
for i in range(n):
    if i != n-1:
        cos = e[n-1]-e[i] + w[i]
    else:
        cos = w[n-2]
    ma = min(cos,ma)

print(ma)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
e=s.count("E")
w=n-e
wc=0
ec=0
min1=300001
for i in range(len(s)):
    if s[i]=="W":
        wc+=1
    else:
        ec+=1
    el=e-ec
    wl=wc
    min1=min(min1,el+wl)
print(min1)

Submission status: Wrong Answer

Solution code:
S = list(input())
e = S.count('E')
w = S.count('W')
if e > w:
  print(w)
else:
  print(e)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = []
c = 0
for i in range(n):
  c += s[:n].count("W") + s[n+1:].count("E")
  ans.append(c)
  c = 0
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
west = [0]
east = [0]
for i in range(n):
    if s[i] == "W":
        west.append(west[i] + 1)
    else:
        west.append(west[i])
s = s[::-1]
for i in range(n):
    if s[i] == "E":
        east.append(east[i] + 1)
    else:
        east.append(east[i])
east = east[::-1]
ans = []
for i in range(n):
    ans.append(west[i] + east[i])
ans.sort()
print(ans[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
west = [0]
east = [0]
for i in range(n):
    if s[i] == "W":
        west.append(west[i] + 1)
    else:
        west.append(west[i])
s = s[::-1]
for i in range(n):
    if s[i] == "E":
        east.append(east[i] + 1)
    else:
        east.append(east[i])
east = east[::-1]
ans = 3 * (10**5)
for i in range(n):
    if west[i] + east[i] < ans:
        ans = west[i] + east[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
west = [0]
east = [0]
for i in range(n):
    if s[i] == "W":
        west.append(west[i] + 1)
    else:
        west.append(west[i])
s = s[::-1]
for i in range(n):
    if s[i] == "E":
        east.append(east[i] + 1)
    else:
        east.append(east[i])
east = east[::-1]
ans = west[0] + east[0]
for i in range(n):
    if west[i] + east[i] < ans:
        ans = west[i] + east[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(str(input()))
west = [0]
east = [0]
for i in range(n):
    if s[i] == "W":
        west.append(west[i] + 1)
    else:
        west.append(west[i])
s = s[::-1]
for i in range(n):
    if s[i] == "E":
        east.append(east[i] + 1)
    else:
        east.append(east[i])
east = east[::-1]
ans = west[1] + east[1]
for i in range(n):
    if west[i] + east[i] < ans:
        ans = west[i] + east[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
l=[0]*n
for i in range(n):
    if ls[i]==1:
        a-=1
        l[i]=a
    elif ls[i]==0:
        a+=1
        l[i]=a-1
print(min(l))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[0]*n
for i in range(n):
    if ls[i]==1:
        a-=1
        l[i]=a
    elif ls[i]==0:
        a+=1
        l[i]=a-1
print(min(l))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import math

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[0]*n
for i in range(n):
    if ls[i]==1:
        a-=1
        l[i]=a
    elif ls[i]==0:
        a+=1
        l[i]=a-1
print(l)

Submission status: Wrong Answer

Solution code:
def 解():
    iN = int(input())
    sS = input().rstrip()

    aE= [0]*iN #東向かされる人
    aW= [0]*iN #西向かされる人
    iMinCost = iN
    for i in range(1,iN):
        if sS[i-1] == "W":
            aE[i] = aE[i-1]+1
        else:
            aE[i] = aE[i-1]
    for i in range(iN-2,-1,-1):
        if sS[i+1]=="E":
            aW[i] = aW[i+1]+1
        else:
            aW[i] = aW[i+1]
        if aW[i] + aE[i] < iMinCost :
            iMinCost = aW[i] + aE[i]
    print(iMinCost)
解()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
#print(a)
l=[10**6]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

n=int(input())
s=list(input())
ls=[0 if i=='W' else 1 for i in s]
a=sum(ls)
l=[10**6]
for i in range(n):
    if ls[i]==1:
        a-=1
        l.append(a)
    elif ls[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Submission status: Wrong Answer

Solution code:
import sys
import string
import collections 
input=sys.stdin.readline

n=int(input())
s=list(input())
#print(s)
snum=[0 if i=='W' else 1 for i in s]
#print(snum)
a=sum(snum)
l=[10**6]
for i in range(n):
    if snum[i]==1:
        a-=1
        l.append(a)
    elif snum[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Submission status: Wrong Answer

Solution code:
import sys
import string
import collections 
input=sys.stdin.readline

n=int(input())
s=list(input())
#print(s)
snum=[0 if i=='W' else 1 for i in s]
#print(snum)
a=sum(snum)
l=[10**6]
for i in range(0,n):
    if snum[i]==1:
        a-=1
        l.append(a)
    elif snum[i]==0:
        a+=1
        l.append(a-1)
print(min(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=[0]*n
for i in range(n):
    c[i]=c[i+1:].count('E')+c[:i].count('W')
print(min(c))

Submission status: Wrong Answer

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

cost = list(S).count("E")

ans = 10 ** 6
for si in S:
    if si == "E":
        cost -= 1
    
    if cost > ans:
        ans = cost

    if si == "W":
        cost += 1

print(ans)

Submission status: Wrong Answer

Solution code:
input()
ls = []
ans = 10000000000
from numpy import cumsum
for i in input():
    if i == 'W':
        ls.append(1)
    else:
        ls.append(0)
a = cumsum(ls)
for i in range(len(a)):
    ans = min(ans,len(a)-i-1-a[-1]+a[i]*2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())       
s=input()            
p=0                  
q=0                  
for i in range(n):   
    if s[i]=='E':    
        p+=1         
    else:            
        q+=1         
print(min(p,q))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

LW_cnt = 0
RE_cnt = s.count('E')


numlist = []
for i in range(n):
    if i > 0:
        if s[i-1] == 'W':
            LW_cnt += 1
        if s[i] == 'E':
            RE_cnt -= 1

    numlist.append(LW_cnt+RE_cnt)

# 出力
print("{}".format(min(numlist)))

Submission status: Wrong Answer

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

count = [S[1:].count('E')]
for i in range(1, N):
    check = count[i-1]
    if S[i-1] == 'E':
        check -= 1
    else:
        check += 1
    count.append(check)
print(min(count))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
ans=s.count("E")
if s[0]=="E": ans-=1
chk=ans
for a,i in enumerate(s[1:]):
    if i=="E": chk-=1
    if s[a]=="E": chk+=1
    ans=min(ans,chk)
print(ans)

Submission status: Wrong Answer

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

m = n

for i in range(n):
	if i>0 and s[i]==s[i-1]:
		continue 
	t = 0
	for j in range(n):
		if (j<i and s[j]=="W") or (j>i and s[j]=="E"):
			t += 1
		if t>m:
			break

	m = min(m,t)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())
cnt = []
count = 0

for i in range(1,len(S)):
    if S[i] == "E":
        count += 1
cnt = [count]*N

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

Submission status: Wrong Answer

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

cnt = []
count = 0

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

for i in range(1, len(S)):
    if S[i-1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    cnt.append(count)
print(min(cnt))

Submission status: Wrong Answer

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

cnt = []
count = 0

for i in range(len(S)):
    if S[i] == "E":
        count += 1

for i in range(1, len(S)):
    if S[i-1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    cnt.append(count)
print(min(cnt))

Submission status: Wrong Answer

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

cnt = []
count = 0

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

for i in range(1, len(S)-1):
    if S[i-1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    cnt.append(count)
print(min(cnt))

Submission status: Wrong Answer

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

cnt = []
count = 0

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

for i in range(1, len(S)):
    if S[i-1] == "W":
        count += 1
    if S[i] == "E":
        count -= 1
    cnt.append(count)
print(min(cnt))

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
e_count=s.count("E")
w_count=n-e_count
w_left=0
e_right=e_count
c=[]
for i in range(n):
    if s[i]=='W':
        c+=[w_left+e_right]
        w_left+=1
    else:
        e_right-=1
        c+=[w_left+e_right]
print(min(c))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=str(input())
#W=左
#E=右
ans=[]
count=0
#一番左
for i in range(1,N):
    
    if S[i]=="E":
        count+=1    
        
        
ans.append(count)


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

    ans.append(count)

print(min(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())

S=str(input())

#W=左
#E=右
ans=1000000000000
for i in range(1,N-1):
    count=0
   
    ans=min(ans,S[0:i].count("W")+S[i:N].count("E"))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
a=[]
for i in range(N):
    a.append(S[:i].count("W")+S[i+1:].count("E"))
print(a)
print(min(a))

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
S = raw_input()
slist = []
for i in range(0, N):
	slist.append(S[i])
min = slist.count('E')
cnt = min
for i in range(1, N):
	if slist[i] == 'E':
		cnt = cnt - 1
	if slist[i-1] == 'W':
		cnt = cnt + 1
	if cnt < min:
		min = cnt

print min

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
s = []
cnt = 0
for i in range(N):
    if S[i] == "W":
        s.append(-1)
    elif S[i] == "E":
        s.append(1)
        cnt += 1
        
DP = [cnt]

for i in range(1,N):
    cnt = 0
    if s[i - 1] == -1:
        cnt += 1
    if s[i] == 1:
        cnt -= 1
    DP.append(DP[i - 1] + cnt)

print(min(DP))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(0,N) :
    if i == 0 :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
    elif S[i-1] == "E" and S[i] == "W" :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
print(min(Q))

Submission status: Wrong Answer

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

answer = prev = S[1:].count('E')
print(S.replace('E', 'R').replace('W', 'L'))
print('0', answer)
for i in range(1, N):
    _answer = prev if S[i-1] == 'E' else prev+1
    if S[i] == 'E':
        _answer -= 1
    answer = min(answer, _answer)
    prev = _answer

print(answer)

Submission status: Wrong Answer

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

answer = prev = S[1:].count('E')
for i in range(1, N):
    _answer = prev-1 if S[i-1] == 'E' else prev+1
    answer = min(answer, _answer)
    prev = _answer

print(answer)

Submission status: Wrong Answer

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

answer = float('inf')
prev = None
for i in range(N):
    _answer = 0
    if prev:
        _answer = prev-1 if S[i-1] == 'E' else prev+1
    else:
        _answer = S.count('E')
    answer = min(answer, _answer)
    prev = _answer

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
count_w = 0
count_e = 0
for i in range(n):
    if line[i] == 'W':
        count_w += 1
    else:
        count_e += 1
    cum_sum_w.append(count_w)
    cum_sum_e.append(count_e)
count_list = []
for i in range(n):
    count = 0
    count += cum_sum_w[i]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = input()
S = '*' + S + '*'
W = [x=='W' for x in S]
E = [x=='E' for x in S]
W = np.cumsum(W)
E = np.cumsum(E[::-1])[::-1]

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

Submission status: Wrong Answer

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

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

print(w,e)
m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    if cnt < m:
        m = cnt
print(m)

Submission status: Wrong Answer

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

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

print(w,e)
m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    print(w[i],e[i])
    if cnt < m:
        m = cnt
print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

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

cnt1 = 0
cnt2 = 0
for i in S:
    if i == "W":
        cnt1 += 1
    else:
        cnt2 += 1

print(min(cnt1, cnt2) - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
E = s.count("E")
W = 0
min = n
for s_i in s:
    if s == "E":
        E -= 1
    else :
        W += 1

    change_man = E + W - bool(s_i == "W")

    if min > change_man:
        min = change_man
print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
W_list = []
E_list = []

for i in range(n):
    search_range = s[:i+1]
    W_list.append(search_range.count("W"))
    E_list.append(search_range.count("E"))
min = n
for i in range(n):
    if i == 0:
        change_man = E_list[-1] - E_list[0]
        if min > change_man:
            min = change_man
    left_range = W_list[i-1]
    right_range = E_list[i] - E_list[i-1]
    change_man = left_range + right_range
    if min > change_man:
        min = change_man
print(min)

Submission status: Wrong Answer

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

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        e_east -= 1
    else:
        w_west += 1
    tmp = w_west + e_east - bool(s_i == "E")
    if tmp < min_num:
        min_num = tmp
print(min_num)

Submission status: Wrong Answer

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

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        w_west += 1
    else:
        e_east -= 1
    tmp = w_west + e_east - bool(s_i == "E")
    if tmp < min_num:
        min_num = tmp
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sum_s = [0] * N
sum_s[0] = 1 if S[0] == 'W' else 0
for i in range(1, N):
    if S[i] == 'W':
        sum_s[i] = sum_s[i - 1] + 1
    else:
        sum_s[i] = sum_s[i - 1]
print(sum_s)

lc = 0
rc = (N - 1) - (sum_s[N - 1] - sum_s[0])
ans = lc + rc

for i in range(1, N):
    lc = sum_s[i - 1]
    rc = (N - (i + 1)) - (sum_s[N - 1] - sum_s[i])

    ans = min(ans, lc + rc)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
ans = e[N-1]-e[0]

for i in range(1,N-1):
	total = (w[i-1]) + (e[N-1]-e[i])
	#print(total)
	ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
ans = e[N-1]-e[0]

for i in range(1,N-1):
	if S[i] =='E':
		total = (w[i]) + (e[N-1]-e[i])
	else:
		total = (w[i-1]) + (e[N-1]-e[i])
	#print(total)
	ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
total = e[N-1]-e[0]

for i in range(1,N):
	if S[i] =='E':
		total = (w[i]) + (e[N-1]-e[i])
	else:
		total = (w[i-1]) + (e[N-1]-e[i])
	#print(total)
	ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
total =(e[N-1]-e[0])

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

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
for i in range(N):
	if S[i] =='E':
		total = (w[i]) + (e[N-1]-e[i])
	else:
		total = (w[i]-1) + (e[N-1]-e[i])
	print(total)
	ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(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 = N
#print(w)
#print(e)
for i in range(N):
	if S[i] =='E':
		total = (w[i]-w[0]+1) + (e[N-1]-e[i])
	else:
		total = (w[i]-w[0]) + (e[N-1]-e[i])
	#print(total)
	ans = min(ans, total)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
direction = list(input())
change = [99999999]*N
Ecount = direction.count("E")
Wcount = 0

for i in range(N):
    if direction[i] == 'E':
        Ecount -= 1
    else:
        Wcount += 1
    change[i] = Ecount + Wcount
print(min(change))

Submission status: Wrong Answer

Solution code:
N = int(input())
direction = list(input())
change = [0]*N
change[0] = direction.count("E")
 
for i in range(1, N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    if direction[i] == "W":
        f_p = 1
    change[i] = change[i-1] - f_n + f_p
print(min(change))

Submission status: Wrong Answer

Solution code:
N = int(input())
direction = list(input())
change = [0]*N
Ecount = direction.count("E")
Wcount = 0

for i in range(N):
    if direction[i] == 'E':
        Ecount -= 1
    else:
        Wcount += 1
    change[i] = Ecount + Wcount
print(min(change))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
S = None

def main():
    global S

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

    if N == 2:
        if S == "WE":
            print(1)
        else:
            print(0)
        sys.exit()

    E, W = [], []
    e, w = 0, 0

    for s in S:
        if s == "E":
            e += 1
        else:
            w += 1
        E.append(e)
        W.append(w)

    ans = 10**150
    for leader in range(N):
        if leader == 0:
            ans = min(ans, E[-1] - E[leader + 1])
        elif leader == N - 1:
            ans = min(ans, W[leader - 1])
        else:
            ans = min(ans, W[leader - 1] + E[-1] - E[leader + 1])

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
S = None

def main():
    global S

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

    E, W = [], []
    e, w = 0, 0

    for s in S:
        if s == "E":
            e += 1
        else:
            w += 1
        E.append(e)
        W.append(w)

    ans = 10**150
    for leader in range(N):
        if leader == 0:
            ans = min(ans, E[-1] - E[leader + 1])
        elif leader == N - 1:
            ans = min(ans, W[leader - 1])
        else:
            ans = min(ans, W[leader - 1] + E[-1] - E[leader + 1])

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
S = None

def f(leader):
    return S[:leader].count("W") + S[leader+1:].count("E")

def main():
    global S

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

    if N == 2:
        print(min(f(0), f(1)))
        sys.exit()

    m = N // 2
    center_p = f(m)

    if f(m-1) < center_p:
        i = m - 2
        left_p = f(m-1)
        while i >= 0 and f(i) < left_p:
            left_p = f(i)
            i -= 1
        print(left_p)

    elif f(m + 1) < center_p:
        i = m + 2
        right_p = f(m + 2)
        while i <= N - 1 and f(i) < right_p:
            right_p = f(i)
            i += 1
        print(right_p)

    else:
        print(center_p)


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w_sumlist = []
for s in S:
    n = 1 if s == 'W' else 0
    if not w_sumlist:
        w_sumlist.append(n)
    else:
        w_sumlist.append(w_sumlist[-1] + n)
min_value = pow(10,5)
# print(w_sumlist)
for i in range(len(S)):
    if i == 0:
        num_w = 0
        num_e = len(S) - w_sumlist[-1] - (len(w_sumlist[:1]) - w_sumlist[0])
    else:
        num_w = w_sumlist[i - 1]
        num_e = len(S) - w_sumlist[-1] - (i + 1 - w_sumlist[i])
    min_value = min(min_value, num_w + num_e)
    # print("i:", i, "min_value:", min_value, "num_w:", S[:i], num_w, "num_e:", S[i + 1:], num_e)
print(min_value)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
w_sumlist = []
for s in S:
    n = 1 if s == 'W' else 0
    if not w_sumlist:
        w_sumlist.append(n)
    else:
        w_sumlist.append(w_sumlist[-1] + n)
min_value = pow(10,5)
print(w_sumlist)
for i in range(len(S)):
    if i == 0:
        num_w = 0
        num_e = len(S) - w_sumlist[-1] - (len(w_sumlist[:1]) - w_sumlist[0])
    else:
        num_w = w_sumlist[i - 1]
        num_e = len(S) - w_sumlist[-1] - (i + 1 - w_sumlist[i])
    min_value = min(min_value, num_w + num_e)
    # print("i:", i, "min_value:", min_value, "num_w:", S[:i], num_w, "num_e:", S[i + 1:], num_e)
print(min_value)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = list(input())
WL = [0]*(N+1)
for i in range(0,N):
    if S[i] == 'W':
        WL[i+1] = WL[i] + 1
    else:
        WL[i+1] = WL[i]
T = S[::-1]
ER = [0]*(N+1)
for i in range(0,N):
    if T[i] == 'E':
        ER[i+1] = ER[i] + 1
    else:
        ER[i+1] = ER[i]
print(WL)
print(ER)
ans = N
for i in range(N):
    ans = min(ans,WL[i]+ER[N-i-1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = Counter(list(input()))
print(min(S['W'],S['E']))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

w = [s[0].count('W')]
e = [s[0].count('E')]

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

for i in range(n):
    if i > 0:
        cnt = w[i-1] + e[-1] - e[i-1]
    else:
        cnt = e[-1] - e[0]
    m = min(cnt, m)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sum = 0
for i in S:
    if i == 'E':
        sum += 1

if sum == N - sum:
    print(sum -1)
else:
    print(min(sum, N - sum))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
sum = 0
for i in S:
    if i == 'E':
        sum += 1

print(min(sum, N - sum))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
minnum = 500000
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)