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:
# author:  Taichicchi
# created: 22.09.2020 12:19:17

import sys

from collections import Counter

N = int(input())

S = input()

e = [0]
w = [0]

for s in S:
    if s == "W":
        w += [w[-1] + 1]
        e += [e[-1]]
    elif s == "E":
        w += [w[-1]]
        e += [e[-1] + 1]

ans = 3 * (10 ** 5) + 1

for i in range(N):
    c = w[i] - w[0]
    c += e[N] - e[i]
    ans = min(c, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
# author:  Taichicchi
# created: 22.09.2020 12:19:17

import sys

from collections import Counter

N = int(input())

S = input()

l = 0
r = Counter(S[1:])["E"]

ans = l + r
flg = False

for i in range(N):
    if flg:
        l += 1
    flg = False
    if S[i] == "E":
        r -= 1

    ans = min(ans, l + r)

    if S[i] == "W":
        flg = True


print(ans)

Submission status: Wrong Answer

Solution code:
# author:  Taichicchi
# created: 22.09.2020 12:19:17

import sys

from collections import Counter

N = int(input())

S = input()

l = 0
r = Counter(S[1:])["E"]
print(f"{l=}{r=}")

ans = l + r
flg = False

for i in range(N):
    if flg:
        l += 1
    flg = False
    if S[i] == "E":
        r -= 1

    ans = min(ans, l + r)

    if S[i] == "W":
        flg = True


print(ans)

Submission status: Wrong Answer

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

ans_temp = 0
ans = 3*10**5+1
for i in range(1, N):
    if S[i] == 'E':
        ans_temp += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cw,ce = s.count("E"),0
ans = cw+ce
for i in s:
    ans = min(ans,cw+ce)
    if i == "W":
        ce += 1
    else:
        if cw>0:
            cw -= 1
print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())
s = list(input())
cw,ce = s.count("E"),0
ans = cw+ce
for i in s:
    ans = min(ans,cw+ce)
    if i == "W":
        ce += 1
        cw -= 1
    else:
        cw -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
W=[0]*N
E=[0]*N
for i in range(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
A=[0]*N
A[0]=W[N-1]
if S[0]=='W':
    A[0]=A[0]-1
for i in range(1,N):
    A[i]=W[i-1]+E[N-1]-E[i]
print(min(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [str(c) for c in s]

x = a.count('E')
if a[0] == 'E':
    y = x-1
else:
    y=x
for i in range(n-1):
    if a[i] == 'W':
        if a[i+1] == 'W':
            x += 1
        else:
            x = x
    else:
        if a[i+1] == 'W':
            x = x
        else:
            x -= 1
    if y > x:
        y = x
        



print(y)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [str(c) for c in s]

x = a.count('E')
y = x
for i in range(n-1):
    if a[i] == 'W':
        if a[i+1] == 'W':
            x += 1
        else:
            x = x
    else:
        if a[i+1] == 'W':
            x = x
        else:
            x -= 1
    if y > x:
        y = x

print(y)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc098/tasks/arc098_a

import sys
from collections import Counter
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    S = input()
    count = Counter(S)
    left_w = 0
    left_e = 0
    ans = len(S) + 1
    for i in range(len(S)):
        ans = min(ans, left_w + (count["E"] - left_e))
        if S[i] == "W":
            left_w += 1
        else:
            left_e += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
w, e = [0] * (n + 1), [0] * (n + 1)
ans = float("inf")
for i in range(n):
    if s[i] == "W":
        w[i + 1] = w[i] + 1
    else:
        w[i + 1] = w[i]

    if s[n - i - 1] == "E":
        e[i + 1] = e[i] + 1
    else:
        e[i + 1] = e[i]

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

print(ans - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
w, e = [0] * (n + 1), [0] * (n + 1)
ans = float("inf")
for i in range(n):
    if s[i] == "W":
        w[i + 1] = w[i] + 1
    else:
        w[i + 1] = w[i]

    if s[n - i - 1] == "E":
        e[i + 1] = e[i] + 1
    else:
        e[i + 1] = e[i]

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

print(ans)

Submission status: Wrong Answer

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

e=0
w=0

all_e=s.count("E")
ans=float('inf')
for i in range(n):

  ans=min(all_e-e+w,ans)

  if s[i]=="E":
    e+=1
  else:
    w+=1

ans=min(ans,all_e+w,ans)
print(ans)

Submission status: Wrong Answer

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

e=0
w=0

all_e=s.count("E")
ans=float('inf')
for i in range(n):

  ans=min(all_e-e+w,ans)

  if s[i]=="E":
    e+=1
  else:
    w+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = input("N: ")
S = input("S: ")
point_list = []
for i in range(0, len(S)):
	p = 0
	if i >0:
		for c in S[:i]:
			if c == 'W':
				p += 1
	if i + 1 < len(S):
		for d in S[i+1:]:
			if d == 'E':
				p += 1
	point_list.append(p)
print(min(point_list))

Submission status: Wrong Answer

Solution code:
def count_point(S, i):
	p = 0
	if i >0:
		for c in S[:i]:
			if c == 'W':
				p += 1
	if i + 1 < len(S):
		for d in S[i+1:]:
			if d == 'E':
				p += 1
	return (p)



N = input("N: ")
S = input("S: ")
point_list = []
for i in range(0, len(S)):
	point_list.append(count_point(S, i))
print(min(point_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

leftw=[0]*(x+1)
righte=[0]*(x+1)

for i in range(x):
    leftw[i+1]=leftw[i]
    righte[x-i-1]=righte[x-i]

    leftw[i+1]+=1 if s[i]=='W' else 0
    righte[x-i-1]+=1 if s[x-i-1]=='E' else 0
ans=10**6
for leader in range(x):
    ans=min(ans,leftw[leader-1]+righte[leader+1])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
s_=[]
for i in range(n):
  if s[i]=='E':
    s_.append(0)
  else:
    s_.append(1)
rui=[]
rui.append(s_[0])
for i in range(1,n):
  rui.append(rui[-1]+s_[i])
ans=n+1  
for j in range(1,n-1):
  ans=min(ans,rui[j-1]+n-1-j-rui[n-1]+rui[j])
ans_=n-1-rui[n-1]+rui[0]
ans=min(ans,ans_)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections


def main():
    N = int(input())
    S = input()
    cnt = collections.Counter(S)
    E_cnt = cnt['E']
    W_cnt = cnt['W']
    tmp = 0
    if S[0] == 'E':
        ans = E_cnt - 1
    else:
        ans = E_cnt
    for i in range(1, N):
        if S[i] == 'E':
            E_cnt -= 1
        else:
            W_cnt -= 1
        if S[i - 1] == 'W':
            tmp += 1
        ans = min(ans, tmp + E_cnt)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
p=X()
e=[1 if i=="E" else 0 for i in p]
w=[1 if i=="W" else 0 for i in p]
e=list(itertools.accumulate(e))
w=list(itertools.accumulate(w))

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

print(mod)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
p=X()
e=[1 if i=="E" else 0 for i in p]
w=[1 if i=="W" else 0 for i in p]
e=list(itertools.accumulate(e))
w=list(itertools.accumulate(w))

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



print(e)
print(w)
print(mod)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n = int(input())
s = input()
result = 10 ** 9

easts = [0] + list(accumulate(map(lambda x : 1 if x == 'E' else 0, s[::-1])))[::-1] + [0]
wests = [0] + list(accumulate(map(lambda x : 1 if x == 'W' else 0, s))) + [0]

for i in range(1, n):
  result = min(result, wests[i-1] + easts[i+1])

print(result)

Submission status: Wrong Answer

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

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


res = N
for i in range(N):
    res = min(x[i]+y[N-i], res)

print(res)

Submission status: Wrong Answer

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

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


res = N
for i in range(1, N):
    res = min(x[i-1]+y[N-i], res)

print(res)

Submission status: Wrong Answer

Solution code:
# 2020/07/24
# AtCoder Regular Contest 098 - C

# Input
n = int(input())
s = input()

# Init
acme = list()
acmw = list()
acme.append(0)
acmw.append(0)
ans = n+1

# Make accumed list
for i in range(n):
    if s[i] == 'E':
        acme.append(acme[i] + 1)
        acmw.append(acmw[i])
    elif s[i] == 'W':
        acme.append(acme[i])
        acmw.append(acmw[i] + 1)

acme.append(acme[n])
acmw.append(acmw[n])

# Calc
for i in range(1, n+1):
    ecnt = acme[n] - acme[i+1]
    wcnt = acmw[i-1]
    wcnt = ecnt + wcnt
    ans = min(ans, wcnt)

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
# 2020/07/24
# AtCoder Regular Contest 098 - C

# Input
n = int(input())
s = input()

# Init
acme = list()
acmw = list()
acme.append(0)
acmw.append(0)
ans = n+1

# Make accumed list
for i in range(n):
    if s[i] == 'E':
        acme.append(acme[i] + 1)
        acmw.append(acmw[i])
    elif s[i] == 'W':
        acme.append(acme[i])
        acmw.append(acmw[i] + 1)

# Calc
for i in range(1, n+1):
    ecnt = acme[n] - acme[i]
    wcnt = acmw[i]
    wcnt = ecnt + wcnt
    if i == 1 or i == n:
        wcnt = wcnt - 1
    ans = min(ans, wcnt)

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    if S[0] == "E":
        e -= 1
    for s in S:
        if s == "E":
            e -= 1
        ans = min(ans, w+e)
        if s == "W":
            w += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    if S[0] == "E":
        e -= 1
    for s in S:
        ans = min(ans, w+e)
        if s == "E":
            e -= 1
        else:
            w += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    for s in S:
        ans = min(ans, w+e)
        if s == "E":
            e -= 1
        else:
            w += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter
we=Counter(list(S))
enum=we["E"]
wnum=0
ans=10**10
for s in S:
  ans=min(ans, enum+wnum)
  if s=="W":
    wnum+=1
  elif s=="E":
    enum-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as c

n = input()

s = list(input())

x = c.Counter(s)

print(min(x["E"]-1,x["W"]-1))

Submission status: Wrong Answer

Solution code:
import collections as c

n = input()

s = list(input().split())

x = c.Counter(s)

print(min(x["E"]-1,x["W"]-1))

Submission status: Wrong Answer

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

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i+1]
  
  ans = min(c,ans)

print(ans)

Submission status: Wrong Answer

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

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i+1]
  
  ans = min(c,ans)

print(ans)

Submission status: Wrong Answer

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

CNT = []
c = 0
for s in S:
  if s == "E":
    c += 1
  CNT.append(c)
  
ans = N + 10
mn = N + 10
for i in range(N):
  c = 0
  if i > 0:
    c += i - 1 - CNT[i-1]
  if i < N - 1:
    c +=  N - i - 1 - (CNT[N-1] - CNT[i+1])
    
  if c < mn:
    ans = i+1

print(ans)

Submission status: Wrong Answer

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

ans = 100000000
east = 0
west = 0
for i in range(1, n):
    if l[i] == 'E':
        east+=1
ans = east

for i in range(1, n):
    if l[i-1] == 'W':
        west+=1
    elif l[i-1] == 'E':
        east-=1
    ans = min(ans, west + east)
print(ans)

Submission status: Wrong Answer

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

ans = 100000000
east = 0
west = 0
for i in range(n):
    if l[i] == 'E':
        east+=1
ans = east

for i in range(1, n):
    if l[i-1] == 'W':
        west+=1
    elif l[i-1] == 'E':
        east-=1
    ans = min(ans, west + east)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc098/tasks/arc098_a
from collections import Counter, defaultdict
n = int(input())
s = input()

left = defaultdict(int)
right = Counter(s)

ans = float('inf')
for i in range(n):
    l = left['W']
    r = right['E']
    ans = min(ans, l + r)
    t = s[i]
    left[t] += 1
    right[t] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
from collections import Counter
c = Counter([i for i in s])
left_w = 0
right_e = c['E']
if s[0] == 'E':
    right_e -= 1

ans = left_w + right_e
for i in range(1, len(s)-1):
    if s[i-1] == 'W':
        left_w += 1
    if s[i] == 'E':
        right_e -= 1
    ans = min(ans, left_w+right_e)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
import collections
c = collections.Counter(s)
e = c["E"]
w = 0
ans = float("Inf")
for i in range(n):
    ans = min(ans,e+w)
    if s[i] == "W":
        w += 1
    else:
        w -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
li = []
a = s.count("E")
li.append(a)

for i in range(n-1):
    if s[i] == "E" and s[i+1] == "E":
        a -= 1
        li.append(a)
    elif s[i] == "W" and s[i+1] == "W":
        a += 1
        li.append(a)
print(min(li))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

sumW=s[1:].count("W")
sumE=s[1:].count("E")

p=[]
e=sumE
w=0
p.append(e)
for i in range(n-1):
    
    if s[i]=="W":
        w+=1
    else:
        if i!=0:
            e-=1
    p.append(w+e)
    
print(min(p))

Submission status: Wrong Answer

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

sumW=s[1:].count("W")
sumE=s[1:].count("E")

p=[]
e=sumE
w=0
p.append(e)
for i in range(n-1):
    
    if s[i]=="W":
        w+=1
    else:
        e-=1
    p.append(w+e)
    
print(min(p))

Submission status: Wrong Answer

Solution code:

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

w_num = S.count('W')
e_num = S.count('E')

sum = e_num

w_num_list = []
e_num_list = []

if S[0] == 'W':
    w_num_list.append(1)
    e_num_list.append(0)
else:
    w_num_list.append(0)
    e_num_list.append(1)

for i in range(1, N):
    if S[i] == 'W':
        w_num_list.append(w_num_list[i-1] + 1)
        e_num_list.append(e_num_list[i-1])
    else:
        w_num_list.append(w_num_list[i-1])
        e_num_list.append(e_num_list[i-1] + 1)

# print(w_num_list)
# print(e_num_list)

for i in range(0, N):
    if i == 0:
        left_side_reverse_num = 0
        if S[0] == 'E':
            right_side_reverse_num = e_num - 1
        else:
            right_side_reverse_num = e_num
    elif i == N-1:
        if S[N-1] == 'W':
            left_side_reverse_num = w_num - 1
        else:
            left_side_reverse_num = w_num
        right_side_reverse_num = 0
    else:
    # print("left", S[:i])
    # print("right", S[i+1:])
        left_side_reverse_num = w_num_list[i-1]
        right_side_reverse_num = e_num - e_num_list[i+1]

    # print(left_side_reverse_num)
    # print(right_side_reverse_num)

    if sum > left_side_reverse_num + right_side_reverse_num:
        sum = left_side_reverse_num + right_side_reverse_num

    #print(sum)
print(sum)

Submission status: Wrong Answer

Solution code:

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

sum = 3000000
w_num = S.count('W')
e_num = S.count('E')

w_num_list = []
e_num_list = []

if S[0] == 'W':
    w_num_list.append(1)
    e_num_list.append(0)
else:
    w_num_list.append(0)
    e_num_list.append(1)

for i in range(1, N):
    if S[i] == 'W':
        w_num_list.append(w_num_list[i-1] + 1)
        e_num_list.append(e_num_list[i-1])
    else:
        w_num_list.append(w_num_list[i-1])
        e_num_list.append(e_num_list[i-1] + 1)

# print(w_num_list)
# print(e_num_list)

for i in range(0, N):
    if i == 0:
        left_side_reverse_num = 0
        if S[0] == 'E':
            right_side_reverse_num = e_num - 1
        else:
            right_side_reverse_num = e_num
    elif i == N-1:
        if S[N-1] == 'W':
            left_side_reverse_num = w_num - 1
        else:
            left_side_reverse_num = w_num
        right_side_reverse_num = 0
    else:
    # print("left", S[:i])
    # print("right", S[i+1:])
        left_side_reverse_num = w_num_list[i-1]
        right_side_reverse_num = e_num - e_num_list[i+1]

    # print(left_side_reverse_num)
    # print(right_side_reverse_num)

    if sum > left_side_reverse_num + right_side_reverse_num:
        sum = left_side_reverse_num + right_side_reverse_num

    #print(sum)
print(sum)

Submission status: Wrong Answer

Solution code:

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

sum = 3000000
w_num = S.count('W')
e_num = S.count('E')

w_num_list = []
e_num_list = []

if S[0] == 'W':
    w_num_list.append(1)
    e_num_list.append(0)
else:
    w_num_list.append(0)
    e_num_list.append(1)

for i in range(1, N):
    if S[i] == 'W':
        w_num_list.append(w_num_list[i-1] + 1)
        e_num_list.append(e_num_list[i-1])
    else:
        w_num_list.append(w_num_list[i-1])
        e_num_list.append(e_num_list[i-1] + 1)

# print(w_num_list)
# print(e_num_list)

for i in range(0, N):
    if i == 0:
        left_side_reverse_num = 0
        right_side_reverse_num = e_num
    elif i == N-1:
        left_side_reverse_num = w_num
        right_side_reverse_num = 0
    else:
    # print("left", S[:i])
    # print("right", S[i+1:])
        left_side_reverse_num = w_num_list[i-1]
        right_side_reverse_num = e_num - e_num_list[i+1]

    # print(left_side_reverse_num)
    # print(right_side_reverse_num)

    if sum > left_side_reverse_num + right_side_reverse_num:
        sum = left_side_reverse_num + right_side_reverse_num

    #print(sum)
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
nsums=[0]*N

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

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  if S[i]=='W':left+=1
  nsums[i] = right + left
  min_sum = min(min_sum,nsums[i])
print(min_sum)

Submission status: Wrong Answer

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

sum_w = [0]
sum_e = [0]

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

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

#print(sum_e, sum_w)
sumu = [x+y for x, y in zip(sum_w, sum_e)]

print(min(sumu))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
stock = []
INF = 10**9
for i in range(1,len(S)-1):
  if (S[i-1] == "E") & (S[i+1] == "W"): stock.append(i)

dic = {k:0 for k in stock}


for i in stock:
  for j in range(i-1,0,-1):
    if j < 0: break
    else:
      if S[j] == "E" : dic[i] += 1
      else: break

  for j in range(i+1, len(S)):
    if j > len(S)-1: break
    else:
      if S[j] == "W" : dic[i] += 1
      else: break

if dic: 
  max_k = max(dic, key=dic.get)
  count = 0
  for i in range(0,max_k):
    if S[i] == "W": count += 1

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

else: count = INF








print(min(count,S[1:].count("E"),S[:-1].count("W")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
E = [0]
W = [0]

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

E = E[1:]
W = W[1:]

ans = min(W[-1]-W[0],E[-1])

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 = str(input())
E = [0]
W = [0]

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

E = E[1:]
W = W[1:]

ans = min(W[-1]-W[0],E[-2])

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(input())
E = [0]
W = [0]

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

E = E[1:]
W = W[1:]

ans = n*2

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

print(ans)

Submission status: Wrong Answer

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

ans = min(W[-1],E[-1])

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

Submission status: Wrong Answer

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

ans = min(W[-1],E[-1])

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = S.count("E") - S.startswith("E")
ans = c
for i in range(N-1):#リーダーをsの右のヤツに変える
    s = S[i]
    if s == "W":
        c += 1
    else:
        c -= 1
        ans = min(c,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = S.count("E") - S.startswith("E")
ans = c
for s in S:#リーダーをsの右のヤツに変える
    if s == "W":
        c += 1
    else:
        c -= 1
        ans = min(c,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
string = input()
es = [0]
ws = [0]
for s in string:
    if s == 'E':
        es.append(es[-1]+1)
        ws.append(ws[-1])
    else:
        es.append(es[-1])
        ws.append(ws[-1]+1)
ans = float('inf')
for i in range(1, len(string)):
    score = ws[i-1] + es[-1] - es[i]
    ans = min(score, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8')
    L = len(S)
    A = [0]*L
    for i in range(L):
        if S[i] == 'E':
            if i == 0:
                A[i] = 1
            else:
                A[i]=A[i-1]+1
        else:
            if i == 0:
                continue
            else:
                A[i]=A[i-1]
    print(A)
    ans = INF
    for i in range(N):
        tmp = 0
        if i>0:
            tmp += i - A[i-1]
        if i<N-1:
            tmp += A[N-1]-A[i]
        ans = min(ans,tmp)
    print(ans)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

r=[0]*n
l=[0]*n
r[0]=0
if s[0]=='E':
    l[0]=s.count('W')
else:
    l[0]=s.count('W')-1

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

ans=114514
for i in range(n):
    ans=min(ans, n-1-(r[i]+l[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
DP=[0]*N
l=0
for i,x in enumerate(S):
  DP[i]+=l
  if x=="W":
    l+=1
r=0
for i,y in enumerate(S[::-1]):
  DP[N-1-i]+=r
  if y=="E":
    r+=1
print(N-1-max(DP))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ruir=[0]*N
ruil=[0]*N


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

    nowl=ruil[-i]
    if S[-(i)]=="E":
        nowl+=1
    ruil[-(i+1)]=nowl

ans=10**5
for i in range(N):
    ans=min(ans, ruir[i]+ruil[i])
#print(ruil,ruir)
print(ans)

Submission status: Wrong Answer

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

ruir=[0]*N
ruil=[0]*N


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

    nowl=ruil[-i]
    if S[-(i)]=="E":
        nowl+=1
    ruil[-(i+1)]=nowl

ans=10**5
for i in range(N):
    ans=min(ans, ruir[i]+ruil[i])
#print(ruil,ruir)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=ss()
wcnt,ecnt=0,0
ans=10**100
wsum=arr.count("W")
esum=n-wsum

for i in range(n):
    ans=min(wcnt+esum-ecnt,ans)
    
    if arr[i]=="W":
        wcnt+=1
    else:
        ecnt+=1

print(ans)

Submission status: Wrong Answer

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

# [West, East]
l = [0, 0]
L = []
m = [0, 0]
M = [0] * N
for i in range(N):
  if S[i] == 'W':
    l[0] += 1
    L.append(list(l))
  else:
    l[1] += 1
    L.append(list(l))

for i in range(N-1, -1, -1):
  if S[i] == 'W':
    m[0] += 1
    M[i] = list(m)
  else:
    m[1] += 1
    M[i] = list(m)
    
count = []
for i in range(N):
  if i == 0:
    count.append(M[1][0])
  elif i == N-1:
    count.append(L[N-2][1])
  else:
    count.append(L[i-1][0]+M[i+1][1])

print(min(count))