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

ruiseki_w = [0]
ruiseki = 0
for i in s[1:]:
    if i == 'W':
        ruiseki += 1
        ruiseki_w.append(ruiseki)
    else:
        ruiseki_w.append(ruiseki)

ruiseki_e = [s.count('E')]
ruiseki = s.count('E')
for i in s[1:]:
    if i == 'E':
        ruiseki -= 1
        ruiseki_e.append(ruiseki)
    else:
        ruiseki_e.append(ruiseki)
        
ninzu = [ruiseki_w[i] + ruiseki_e[i] for i in range(n)]
print(min(ninzu))

Submission status: Wrong Answer

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

count_w =[s[:i].count('W') for i in range(n)]
count_e =[s[::-(i+1)].count('E') for i in range(n)]

ninzu = n
for i in range(n):
    ninzu = min(ninzu, count_w[i]+count_e[i])
print(ninzu)

Submission status: Wrong Answer

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

counts = []
for n in [0, N-1]:
    count = 0
    for i in range(N):
        if i == n:
            continue
        if n<i and people[i]=='E':
            count +=1
        if n>i and people[i]=='W':
            count +=1
    print(count)
    counts.append(count)

print(min(counts))

Submission status: Wrong Answer

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

counts = []
for n in range(N):
    count = 0
    for i in range(N):
        if i == n:
            continue
        if n<i and people[i]=='E':
            count +=1
        if n>i and people[i]=='W':
            count +=1
    counts.append(count)

min(counts)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = input()


ans = 3 * 10 ** 5

i = 0
while i <= n:
  idx_EW = s[i:].find("EW")

  if idx_EW != -1:
    ans = min(ans, s[:i+idx_EW].count("W") + s[i+idx_EW+1:].count("E"))
    i = i + idx_EW + 1
  else:
    if i == 0:
      ans = min(s.count("W"), s.count("E"))
    break
    
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	N = int(input())
	S = input()
	dpe = [0]*(N+1)
	dpw = [0]*(N+1)

	for i in range(N):
		if S[i] == "E" and i > 0:
			dpe[i-1] += 1
		elif S[i] == "W" and i < N-1:
			dpw[i+1] += 1

	for i in range(N-1, 0, -1):
		dpe[i-1] += dpe[i]

	for i in range(N-1):
		dpw[i+1] += dpw[i]

	ans = 3*(10**5)
	for i in range(N-1):
		ans = min(ans, dpe[i]+dpw[i])

	print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

W = 0

for i in S:
    if i == 'W':
        W += 1

print(W-2)

Submission status: Wrong Answer

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

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

print(minans)

Submission status: Wrong Answer

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

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

print(minans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    eCount = [0]
    wCount = [0]
    for i in range(N):
        ce = S[i]
        cw = S[-i-1]
        eCount.append(eCount[i] + (1 if ce == "W" else 0))
        wCount.append(wCount[i] + (1 if cw == "E" else 0))
    result = 10 ** 18
    for i in range(N):
        result = min(result, eCount[i] + wCount[N - i])
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


e = [0]
w = [0]

cnt_e = 0
cnt_w = 0
for i in range(n):
	if s[i] == "E" :
		cnt_e += 1
	else:
		cnt_w += 1

	e.append(cnt_e)
	w.append(cnt_w)

ans = n +1
for j in range(n):
	t = w[i]  + e[n] - e[ i +1 ]
	
	ans = min(ans,t)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
e=[]
w=[]
cnt_e=0
cnt_w=0
e.append(0)
w.append(0)
for x in s:
    if x=="E":
        cnt_e+=1
    else:
        cnt_w+=1
    e.append(cnt_e)
    w.append(cnt_w)

ans=100000000
for i in range(n):
    t=(w[i-1])+(e[n]-e[i+1])
    ans=min(ans,t)

print(ans)

Submission status: Wrong Answer

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

wests = [1 if s == 'W' else 0 for s in S]
w_sums = []
for i in wests:
    if len(w_sums) == 0:
        w_sums.append(i)
    else:
        w_sums.append(w_sums[-1] + i)

easts = [0 if s == 'W' else 1 for s in S]
e_sums = []
for i in easts:
    if len(e_sums) == 0:
        e_sums.append(i)
    else:
        e_sums.append(e_sums[-1] + i)


res = N
for i in range(0,N):
    if i == 0:
        left = 0
    else:
        left = w_sums[max(i - 1,0)]

    if i == N - 1:
        right = 0
    else:
        right = e_sums[-1] - e_sums[i + 1]
    res = min(left + right,res)

print(res)

Submission status: Wrong Answer

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

subS = [0]
for i,s in enumerate(S):
    subS.append(subS[-1]+int(s=="W"))
subS.append(subS[-1])

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

Submission status: Wrong Answer

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

Is = [1 if s == 'W' else 0 for s in S]
sums = [0]
for i in Is:
 if len(sums) == 0:
  sums.append(i)
 else:
  sums.append(sums[-1] + i)

res = N
for i in range(0,N):
 left = sums[max(i - 1,0)]
 right = ((N - i - 1) - (sums[-1] - sums[i + 1]))
 res = min(left + right,res)

print(res)

Submission status: Wrong Answer

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

Is = [1 if s == 'W' else 0 for s in S]
sums = [0]
for i in Is:
 if len(sums) == 0:
  sums.append(i)
 else:
  sums.append(sums[-1] + i)

res = N
for i in range(0,N + 1):
 left = sums[max(i - 1,0)]
 right =((N - i - 1) - (sums[-1] - sums[min(i + 1,N)]))
 res = min(left + right,res)

print(res)

Submission status: Wrong Answer

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

Is = [1 if s == 'W' else 0 for s in S]
sums = [0]
for i in Is:
 if len(sums) == 0:
  sums.append(i)
 else:
  sums.append(sums[-1] + i)

res = N
for i in range(0,N):
 left = sums[max(i - 1,0)]
 right =((N - i - 1) - (sums[-1] - sums[min(i + 1,N)]))
 res = min(left + right,res)

print(res)

Submission status: Wrong Answer

Solution code:
# 2019/04/10
# AtCoder Beginner Contest 098 - C

n = int(input())
s = input()
wl = [0]*(n+1)
el = [0]*(n+1)

for i in range(n):
    if s[i] == "W":
        wl[i+1] = wl[i] + 1
        el[i+1] = el[i]
    else:
        el[i+1] = el[i] + 1
        wl[i+1] = wl[i]

minp = 10**6
for i in range(n):
    chp = wl[i] + (el[n]-el[i])
    if chp < minp:
        minp = chp

print(minp)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
print(min(b.count("W"),b.count("E")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
st = []
result = 10 ** 9 + 7
for a in range(n):
    e, w = 0, 0
    if s[a] == 'E': e += 1
    elif s[a] == 'W': w += 1
    st.append((st[a-1][0]+e, st[a-1][1]+w) if a > 0 else (e, w))
le, lw = st[n-1]
for a in range(n):
    tmp = 0
    if a > 0: tmp += st[a-1][1]
    if a < n - 1: tmp += le - st[a+1][0]
    if result > tmp: result = tmp
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
result = 3*10**5
for i in range(0, N):
    l = len([h for h in S[:i+1] if h == 'W'])
    r = len([h for h in S[i+1:] if h == 'E'])
    if result > l+r:
        result = l+r
print(result)

Submission status: Wrong Answer

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

numE = S.count('E')
numTurn = numE
numW = 0

for i in range(N):
    if numTurn > numE + numW:
        numTurn = numE + numW
    if S[i] == 'E':
        numE -= 1
    else:
        numW += 1

print(numTurn)

Submission status: Wrong Answer

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

left_E = [0] * N
left_W = [0] * N

for i in range(N-1):
    if S[i] == "E":
        left_E[i+1] = left_E[i] + 1
        left_W[i+1] = left_W[i]
    else:
        left_E[i+1] = left_E[i]
        left_W[i+1] = left_W[i] + 1

min_count = 100000000
#print(left_E)
#print(left_W)

right_E = [0] * N
offset = 0
if S[0] == "E":
    offset -= 1
if S[N-1] == "E":
    offset += 1
for i in range(N):
    right_E[i] = left_E[N-i-1] + offset

for i in range(N):
    change_count = left_W[i] + right_E[i]
    if change_count < min_count:
        min_count = change_count
print(min_count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
l=list(S)
E=[0]*N
W=[0]*N

if S[0]=='E':
    E[0]=1
else:
    W[0]=1

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
S = input()

w_count = S.count('W')
e_count = S.count('E')

result = 10**13
left_w = 0
right_e = e_count
for s in S:
    # i番目がリーダーの場合
    result = min(result, left_w + right_e)
    if s == 'W':
        left_w += 1
    else:
        right_e -= 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

ans = 9999999
for l in range(1,N+1):
    num = E[N] - E[l+1] + W[l-1]
    if ans > num:
        ans = num

print(ans)

Submission status: Wrong Answer

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

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

ans = 300000
for l in range(1,N+1):
    num = E[N] - E[l+1] + W[l-1]
    if ans > num:
        ans = num

print(ans)

Submission status: Wrong Answer

Solution code:
#ABC 098 C - Attention
N = int(input())
S = input()

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

print(ans)

Submission status: Wrong Answer

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

E = [0]*(N+2)
W = [0]*(N+2)
for i in range(1,N+1):
    if S[i-1] == 'E':
        E[i] = E[i-1] + 1
        W[i] = W[i-1]
    else:
        W[i] = W[i-1] + 1
        E[i] = E[i-1]
#print(E)
#print(W)
ans = N
for l in range(1,N+1):
    num = E[N]-E[l+1]
    num += W[l-1]-W[0]
    if ans >= num:
        ans = num
if ans == 0 and E[N] == W[N]:
  ans = int(N/2)
print(ans)

Submission status: Wrong Answer

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

E = [0]*(N+2)
W = [0]*(N+2)
for i in range(1,N+1):
    if S[i-1] == 'E':
        E[i] = E[i-1] + 1
        W[i] = W[i-1]
    else:
        W[i] = W[i-1] + 1
        E[i] = E[i-1]
#print(E)
#print(W)
ans = N
for l in range(1,N+1):
    num = E[N]-E[l+1]
    num += W[l-1]-W[0]
    if ans >= num:
        ans = num
if ans == 0:
    ans = int(N/2)
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
def main(N, S):
    sum = [0]
    res = float("inf")
    for i in range(N):
        if(S[i]=="W"):
            sum.append(sum[-1]+1)
        else:
            sum.append(sum[-1])
    for i in range(1, N):
        res = min(res, sum[i-1]+(N-i)-(sum[N]-sum[i]))
    print(res)
    
if(__name__ == "__main__"):
    N = int(input())
    S = input()
    
    main(N, S)

Submission status: Wrong Answer

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

original_w = []
prev = 0
for i in range(N):
    if S[i] == 'W':
        prev += 1
    original_w.append(prev)

original_e = []
prev = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'E':
        prev += 1
    original_e.insert(0, prev)

#print(min([original_w[i - 1] + original_e[i + 1] for i in range(1, N - 1)] + [original_e[1], original_w[N - 2]]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=input()
half=n//2
if s[half]=="E":
    if "W" in s[half+1:]:
        half=s.find("W",half+1)
    else:
        half=n-1
else:
    if "E" in s[0:half]:
        half=s.rfind("E",0,half)
    else:
        half=0
before=dict(Counter(s[0:half])).get("W",0)
after=dict(Counter(s[half+1:])).get("E",0)
print(before+after)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=input()
half=n//2
if s[half]=="E":
    half=s[half:].find("W")-1
else:
    half=s[0:half].rfind("E")+1
before=dict(Counter(s[0:half])).get("W",0)
after=dict(Counter(s[half+1:])).get("E",0)
print(before+after)

Submission status: Wrong Answer

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

def main():
	N = int(input())
	tmp = input()
	lines = list(tmp)
	
	nisi = [0 for _ in range(N)]
	higasi = [0 for _ in range(N)]
	for i, val in enumerate(lines):
		if val == "W":
			if i != 0:
				nisi[i] = nisi[i-1] + 1
			else:
				nisi[i] = 1
		else:
			if i != 0:
				nisi[i] = nisi[i-1]
			else:
				nisi[i] = 0
		
	for i in range(N-1, -1, -1):
		if lines[i] == "E":
			if i < N-1:
				higasi[i] = higasi[i+1] + 1
			else:
				higasi[i] = 1
		else:
			if i < N-1:
				higasi[i] = higasi[i+1]
			else:
				higasi[i] = 0
	
	ans_min = 100001
	for i, val in enumerate(lines):
		ans = 0
		ans1 = 0
		ans2 = 0
		if i < (N - 1):
			ans1 = higasi[i+1]
		if i > 0:
			ans2 = nisi[i-1]
		ans = ans1 + ans2
			
		if ans_min > ans:
			ans_min = ans
	
	print(ans_min)
		
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
turn = S[1:].count('E')
min_turn = 300000
for i in range(N):
    if S[i] == 'E':
        turn -= 1
    if (S[i-1] == 'W') and (1 <= i):
        turn += 1
    if min_turn > turn:
        min_turn = turn
print(min_turn)

Submission status: Wrong Answer

Solution code:
int_n = int(input())
str_s = input()

li_west = [0] * int_n
for i in range(int_n - 1):
    if str_s[i] == 'W':
        li_west[i + 1] = li_west[i] + 1
    else:
        li_west[i + 1] = li_west[i]
li_east = [0] * int_n

for i in range(int_n - 1, 0, -1):
    print(i)
    if str_s[i] == 'E':
        li_east[i - 1] = li_east[i] + 1
    else:
        li_east[i - 1] = li_east[i]

minimum = 999999
for i in range(int_n):
    int_w = li_west[i] + li_east[i]
    minimum = min(minimum, int_w)

print(minimum)

Submission status: Wrong Answer

Solution code:
int_n = int(input())
str_s = input()

li_west = [0] * int_n
for i in range(int_n - 1):
    if str_s[i] == 'W':
        li_west[i + 1] = li_west[i] + 1
    else:
        li_west[i + 1] = li_west[i]
li_east = [0] * int_n

for i in range(int_n - 1, -1, -1):
    if str_s[i] == 'E':
        li_east[i - 1] = li_east[i] + 1
    else:
        li_east[i - 1] = li_east[i]

minimum = 999999
for i in range(int_n):
    int_w = li_west[i] + li_east[i]
    minimum = min(minimum, int_w)

print(minimum)

Submission status: Wrong Answer

Solution code:
num=int(input())
n=input()
m=len(n)
cnt=['' for i in range(m)]
cnt[0]=n.count('E')

for i in range(m-1):
    point=0
    if n[i]=='W':
        point+=1
    if n[i+1]=='E':
        point-=1
    cnt[i+1]=cnt[i]+point
    
print(min(cnt))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
W=[0]*n
E=[0]*n
W[0]=1 if s[0]=="W" else 0
for i in range(n-1):
  W[i+1]=W[i]+ (1 if s[i+1]=="W" else 0)
  E[i+1]=(i+2)-W[i+1]
ans=10**9
for i in range(1,n):
  ans=min(ans,(W[i-1]+E[-1]-E[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
W=[0]*n
W[0]=1 if s[0]=="W" else 0
for i in range(n-1):
  W[i+1]=W[i]+ (1 if s[i+1]=="W" else 0)
ans=(n-1)-(W[n-1]-W[0])
for i in range(1,n-1):
  hidari=W[i-1]
  migi  =(n-(i+1))-(W[n-1]-W[i])
  ans=min(ans,(hidari+migi))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=len([i for i in range(1,n) if s[i]=='E'])
l=0
i=1
x=n
while i<=n-1:
    if s[i]=='E' and s[i-1]=='E':
        r=r-1
        l=l
    elif s[i]=='W' and s[i-1]=='W':
        r=r
        l=l+1
    elif s[i]=='W' and s[i-1]=='E':
        r=r
        l=l
    elif s[i]=='E' and s[i-1]=='W':
        r=r-1
        l=l+1
    x=min(l+r,x)
    i+=1
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
r=len([i for i in range(1,n) if s[i]=='E'])
l=0
print(l,r)
i=1
x=n
while i<=n-1:
    if s[i]=='E' and s[i-1]=='E':
        r=r-1
        l=l
    elif s[i]=='W' and s[i-1]=='W':
        r=r
        l=l+1
    elif s[i]=='W' and s[i-1]=='E':
        r=r
        l=l
    elif s[i]=='E' and s[i-1]=='W':
        r=r-1
        l=l+1
    x=min(l+r,x)
    i+=1
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = [0]
e = [0]
for i in range(len(s)):
    if s[i]=="W":
        w.append(w[i]+1)
        e.append(e[i])
    else:
        w.append(w[i])
        e.append(e[i]+1)
ans = 10**9
for i in range(0,len(s)):
    ans = min(ans,w[i]+e[-1]-e[i+1])
print(w)
print(e)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = [0]
e = [0]
for i in range(len(s)):
    if s[i]=="W":
        w.append(w[i]+1)
        e.append(e[i])
    else:
        w.append(w[i])
        e.append(e[i]+1)
ans = 10*9
for i in range(0,len(s)):
    ans = min(ans,w[i]+e[-1]-e[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = [0]
e = [0]
for i in range(len(s)):
    if s[i]=="W":
        w.append(w[i]+1)
        e.append(e[i])
    else:
        w.append(w[i])
        e.append(e[i]+1)
ans = 10*9
for i in range(1,len(s)):
    ans = min(ans,w[i]+e[-1]-e[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
d = {"E":0, "W":0}
for i in s:
    d[i] += 1
print(min(d.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
W_count = 0
W_cumulative = []
for i in range(N):
    if S[i] == "W":
        W_count += 1
    W_cumulative.append(W_count)

ans = N
W_cumulative.insert(0,0)
for i in range(1,N+1):
    count = W_cumulative[i-1]
    count += N - W_cumulative[-1] - i + W_cumulative[i-1] + 1
    ans = min(ans,count)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
line=str(input())
line=line.replace('E','0')
line=line.replace('W','1')
line=list(map(int,line))
v=0
for i in range(n-1):
  if line[i]==0 or line[i+1]==0:
    pass
  else:
    v=line[0:i].count(0)+line[i+1:n].count(1)
    break
print(v)

Submission status: Wrong Answer

Solution code:
n=int(input())
line=list(str(input()))
def turn_e(x):
  count=0
  for i in range(x):
    if line[x]=='W':
      count+=1
  return count
def turn_w(x):
  count=0
  for i in range(x+1,n):
    if line[x]=='E':
      count+=1
  return count
v=n
for i in range(n):
  if (turn_e(i)+turn_w(i))<v:
    v=turn_e(i)+turn_w(i)
print(v)

Submission status: Wrong Answer

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

w = 0
e = s.count('E')
ans = w + e
for si in s:
  if s == 'E':
    e -= 1
  else:
    w += 1
  ans = min(ans, w + e)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = 0
e = 0
for i in s:
    if i == 'W':
        w += 1
    else:
        e += 1

lw = 0
re = e
a = []
for i in range(n):
    if i == 0:
        if s[i] == 'W':
            a.append(e)
        else:
            a.append(e-1)
    elif i == n-1:
        if s[i] == 'W':
            a.append(w-1)
        else:
            a.append(w)
    else:
        if s[i] == 'E':
            re -= 1
        if s[i-1] == 'W':
            lw += 1

        a.append(lw+re)

print(min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = 0
e = 0
for i in s:
    if i == 'W':
        w += 1
    else:
        e += 1
 
lw = 0
re = e
a = []
for i in range(n):
    if i == 0:
        if s[i] == 'W':
            a.append(re)
        else:
            a.append(re-1)
    else:
        if s[i] == 'E':
            re -= 1
            
        if s[i-1] == 'W':
            lw += 1

        a.append(lw+re)

print(min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = 0
e = 0
for i in s:
    if i == 'W':
        w += 1
    else:
        e += 1

lw = 0
re = e
a = []
for i in range(n):
    if i == 0:
        if s[i] == 'W':
            a.append(re)
        else:
            a.append(re-1)
    else:
        if s[i] == 'E':
            re -= 1
            
        if s[i-1] == 'W':
            lw += 1

    a.append(lw+re)

print(min(a))

Submission status: Wrong Answer

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

ans = 10**9+7
for i in range(1,N+1):
  l = S[i:]
  r = S[:i-1]
  if(S[i-1] == "W"):
    ans = min(ans, l.count("W") + r.count("E"))
  else:
    ans = min(ans, l.count("E") + r.count("W"))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
num_s=[]
value=[]
left=0
for f_s in s:
    if(f_s=="E"):
        num_s.append(0)
    else:
        num_s.append(1)
right=sum(num_s[0:])
len_s=n
value.append(len_s-right)
for p in range(1,n):
    left+=num_s[p-1]
    right-=num_s[p]
    len_s-=1
    value.append(left+len_s-right)
print(min(value))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
S = np.array(list(input()))
n = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = 0
S = np.array(S, dtype=int)
S = np.cumsum(S)
last = S[N-1]
for i in range(N):
    ls = i - S[i]
    rs = last - S[i]
    n.append(ls+rs)
print(min(n))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
num_s=[]
value=[]
left=0
for f_s in s:
    if(f_s=="E"):
        num_s.append(0)
    else:
        num_s.append(1)
right=sum(num_s)
len_s=n
value.append(len_s-right)
for p in range(1,n):
    left+=num_s[p-1]
    right-=num_s[p]
    len_s-=1
    value.append(left+abs(right-len_s))
print(min(value))

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==5:
  exit()
s=list(input())
l=[]
sh=s[0]
s.remove(sh)
c=0
for i in s:
  if i=='E':
    c+=1
l.append(c)
for i in range(len(s)):
  tsu=s[i]
  if sh=='W':
    c+=1
  if tsu=='E':
    c-=1
  l.append(c)
  sh=tsu
print(min(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(input())
ans=0

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

cnt=ans

for i in range(n):
    if s[i:i+2]=='WW':
        cnt=cnt+1
    elif s[i:i+2]=='EE':
        cnt=cnt-1
    else:
        0
        
    print('i,s[i:i+2],ans,cnt',i,s[i:i+2],ans,cnt)
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=str(input())
ans=0

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

cnt=ans

for i in range(n-1):
    if s[i:i+2]=='WW':
        cnt=cnt+1
    elif s[i:i+2]=='EE':
        cnt=cnt-1
    else:
        0
        
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 3 * 10 ** 5
    left = 0
    right = S[1:].count('E')
    for n in range(2, N):
        if S[n - 1] == 'W':
            left += 1
        if S[n] == 'E':
            right -= 1
        ans = min(ans, left + right)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
N, S = int(input()), input()
countw, counte = 0, S.count("E")

ans = 3 * 10 ** 5
for s in S:
    if s == "W":
        ans = min(ans, counte + countw)
        countw += 1
    elif s == "E":
        ans = min(ans, counte + countw)
        counte -= 1
print(ans)

Submission status: Wrong Answer

Solution code:

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


wn = s.count('W')
en = n - wn

ans = en if s[0]=='W' else en -1

wc = 0
for i in range(1,len(s)):
    if s[i-1] == 'W':
        wc += 1
    else:
        en -= 1
    ans = min(ans, en + wc )

print(ans)

Submission status: Wrong Answer

Solution code:

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


wn = s.count('W')
en = n - wn

ans = en if s[0]=='W' else wn -1

wc = 0
for i in range(1,len(s)):
    if s[i-1] == 'W':
        wc += 1
    else:
        en -= 1
    ans = min(ans, en + wc )

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy

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

li = numpy.asarray([1 if i == 'W' else 0 for i in s])
w = numpy.cumsum(li)
e = numpy.cumsum(1 - li[::-1])[::-1]

su = w + e
ans = min(su) - 1

print(li, w, e)
print(ans)

Submission status: Wrong Answer

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

L = [1 if s == 'W' else 0 for s in S]
R = [1 if s == 'E' else 0 for s in S][::-1]

for i in range(1, N):
    L[i] += L[i-1]
    R[i] += R[i-1]

L = [0] + L
R = R[::-1] + [0]

print(min([L[i] + R[i] for i in range(N)]))

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    s = input()
    line = [0 for _ in range(n)]

    for i, c in enumerate(s):
        if c == 'E':
            for li in range(0, i):
                line[li] += 1
            
        elif c == 'W':
            for ri in range(i+1, n):
                line[ri] += 1
        print(line)
    
    mini = min(line)
    print(mini)
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
eastcount = [0 for i in range(N+1)]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
w_num = S.count('W')
e_num = S.count('E')
a = 0
b = e_num
min = n+1
if(len(set(S)) == 1):
    print(0)
else:
    for i in S:
        if(i == 'E'):
            b -= 1
        else:
            a+=1
        if(a+b < min):
            min = a+b

    print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
m = mi= a.count("E")
for i in range(n):
    if a[i] == "W" : m+=1
    else : m-=1
    mi = min(mi,m) 
print(m)

Submission status: Wrong Answer

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

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