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

e=[0 for i in range(n)]
w=[0 for i in range(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:
        w[i]=w[i-1]+1
        e[i]=e[i-1]
print(e,w)

mn = 10**10
for i in range(n):
    dire = s[i]
    if dire == "E":
        if i != 0 and i != n-1:
            ans = w[i-1] + (e[n-1] - e[i])
        elif i == 0:
            ans = w[n-1] - w[i]
        else:
            ans = e[n-1] - 1
    else:
        if i != 0 and i != n-1:
            ans = w[i-1] + (e[n-1] - e[i])
        elif i == 0:
            ans = e[n-1] - e[i]
        else:
            ans = w[n-1] - 1
    if ans < mn:
        mn = ans

print(mn)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
e=s.count('E')
w=s.count('W')
if e<=w:
  print(e-1)
else:
  print(w-1)

Submission status: Wrong Answer

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

e_acc, w_acc = 0, 0
e_acc_list = [0]
w_acc_list = [0]
acc = {'E': 0, 'W': 0}
acc_list = {'E': [0], 'W': [0]}
for s in S:
    if s == 'E':
        acc['E'] += 1
    else:
        acc['W'] += 1
    acc_list['E'].append(acc['E'])
    acc_list['W'].append(acc['W'])

def count(l_ind, r_ind, symbol):
    # assert l_ind < r_ind
    if r_ind < 0 or l_ind > N - 1:
        return 0
    else:
        if symbol == 'E':
            return acc_list['E'][r_ind] - acc_list['E'][l_ind]
        else:
            return acc_list['W'][r_ind] - acc_list['W'][l_ind]

cost = 1e10

for i in range(N):  # ind of leader
    tmp = count(0, i - 1, 'W') + count(i + 1, N, 'E')
    if tmp < cost:
        cost = tmp
print(cost)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
s = input()
s_W = [0]
s_E = []

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

W_l = np.cumsum(np.array(s_W))
E_l = np.cumsum(np.array(s_E))
print(W_l)
print(E_l)
ans = []
for j in range(n):
    num = W_l[j]-W_l[0]+E_l[-1]-E_l[j]
    print("num", num)
    ans.append(num)
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
s = input()
s_W = [0]
s_E = [0]

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

W_l = np.cumsum(np.array(s_W))
E_l = np.cumsum(np.array(s_E))
print(W_l)
print(E_l)
ans = []
for j in range(n):
    num = W_l[j]+E_l[-1]-E_l[j+1]
    print("num", num)
    ans.append(num)
print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
s = input()
s_W = [0]
s_E = [0]

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

W_l = np.cumsum(np.array(s_W))
E_l = np.cumsum(np.array(s_E))

ans = []
for j in range(n):
    num = W_l[j]+E_l[-1]-E_l[j]
    ans.append(num)
print(min(ans))

Submission status: Wrong Answer

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

E = [0] * (N + 1)
W = [0] * (N + 1)
for i, s in enumerate(S):
    E[i + 1] = E[i] + (s == 'E')
    W[i + 1] = W[i] + (s == 'W')

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

print(ans)

Submission status: Wrong Answer

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

cumsum_w = [0]*n
n_e = s.count('E')
cumsum_e = [n_e]*n

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

for i in range(1,n):
    if s[i] == 'E':
        cumsum_e[i] = cumsum_e[i-1] - 1
    
    else:
        cumsum_e[i] = cumsum_e[i-1]

min = n
for i in range(n):
    m = cumsum_e[i] + cumsum_w[i]
    if m < min:
        min = m

print(min)

Submission status: Wrong Answer

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

cumsum_w = [0]*n
n_e = s.count('E')
cumsum_e = [n_e]*n

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

for i in range(1,n):
    if s[i] == 'E':
        cumsum_e[i] = cumsum_e[i-1] - 1
    
    else:
        cumsum_e[i] = cumsum_e[i-1]

min = n
for i in range(n):
    m = cumsum_e[i] + cumsum_w[i]
    if m < min:
        min = m

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    S = tuple(input())

    c_e = S.count('E')
    c_w = 0
    ans = n

    for s in S:
        ans = min(ans, c_w + c_e)
        if s == 'E':
            c_e -= 1
        else:
            c_w += 1

    print(ans)
if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
w=[0]*n
for i in range(n):
    if s[i]=="E":
        w[i]=1
from itertools import accumulate    
d=list(accumulate([0]+w))
ans=n
cnt=0
for i in range(n):
    cnt=i-d[i]+d[-1]-d[i]
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
w=[0]*n
for i in range(n):
    if s[i]=="E":
        w[i]=1
from itertools import accumulate    
d=list(accumulate([0]+w))
ans=10**10
cnt=0
for i in range(n):
    cnt=i-d[i]+d[-1]-d[i]
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
w=[0]*n
for i in range(n):
    if s[i]=="E":
        w[i]=1
from itertools import accumulate    
d=list(accumulate([0]+w))
ans=10**10
cnt=0
for i in range(1,n):
    cnt=i-d[i-1]+d[-1]-d[i]-1
    ans=min(ans,cnt)
    cnt=0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
t=list(reversed(s))
#print(s,t)

S,T=[],[]
x,y=0,0
for i in range(n):
    if s[i]=='W':
        x+=1
        S.append(x)
    else:
        S.append(x)
    
    if t[i]=='E':
        y+=1
        T.append(y)
    else:
        T.append(y)

S=[0]+S
T=[0]+T
T.reverse()

z=3*(10**5)
for j in range(n-1):
    z=min(z,S[j]+T[j])
#print(S,T)
print(z)

Submission status: Wrong Answer

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

cnt = 0

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

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

print(ans)

Submission status: Wrong Answer

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

wcnt = s[1:].count('W')
ecnt = s[1:].count('E')

ans = wcnt
el = 0
wl = 0
er = ecnt
wr = wcnt
for i in range(0,n):
    if s[i] == 'E':
        ans = min(ans,wr+el)
        er+=1
        el-=1
    else:
        ans = min(ans,wcnt-1)
        wr+=1
        wl-=1
    
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = S.count('E',1,N)
ans = [cnt]

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

Submission status: Wrong Answer

Solution code:
from sys import maxsize

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

count_e = [0]
count_w = [0]
for i in range(1, n+1):
    if s[i-1] == 'E':
        count_e.append(count_e[i-1]+1)
        count_w.append(count_w[i-1])
    else:
        count_e.append(count_e[i-1])
        count_w.append(count_w[i-1]+1)

min = maxsize
for i in range(n):
    val = count_w[i] + count_e[n] - count_e[i]
    if val < min:
        min = val

print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
RS=S[::-1]
W=[0]
E=[0]
for i in range(N):
    if S[i]=="W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])
W.append(0)
for i in range(N):
    if RS[i]=="E":
        E.append(E[-1]+1)
    else:
        E.append(E[-1])
E.append(0)
E=E[::-1]
print(W)
print(E)
ans=10**9
for i in range(1,N+1):
    if W[i-1]+E[i+1]<ans:
        ans=W[i-1]+E[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
RS=S[::-1]
W=[0]
E=[0]
for i in range(N):
    if S[i]=="W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])
W.append(0)
for i in range(N):
    if RS[i]=="E":
        E.append(E[-1]+1)
    else:
        E.append(E[-1])
E.append(0)
E=E[::-1]
#print(W)
#print(E)
ans=10**9
for i in range(1,N):
    if W[i-1]+E[i+1]<ans:
        ans=W[i-1]+E[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    people_num = int(input())
    directions = input()
    east_direction = [0]
    for i in range(people_num):
        if directions[i] == "E":
            east_direction.append(east_direction[i] + 1)
        else:
            east_direction.append(east_direction[i])
    answer = float("inf")
    print(east_direction)
    for i in range(1, people_num + 1):
        change_to_east = i - 1 - east_direction[i - 1]
        change_to_west = east_direction[-1] - east_direction[i]
        answer = min(answer, change_to_east + change_to_west)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 3*(10**5)+1
cnt_E = S.count('E')
cnt_E_left = 0
cnt_W = S.count('W')
cnt_W_left = 0

for n in range(N):
  ans = min(ans,cnt_W_left+cnt_E-cnt_E_left)
  _ = S[n]
  if _ == 'E':
    cnt_E_left += 1
  elif _ == 'W':
    cnt_W_left += 1

print(ans)

Submission status: Wrong Answer

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

curr_change_cnt = min_change_cnt = sum(c == 'E' for c in s)
for i in range(1, n):
    if s[i - 1] == 'W':
        curr_change_cnt += 1

    if s[i] == 'E':
        curr_change_cnt -= 1

    min_change_cnt = min(curr_change_cnt, min_change_cnt)

print(min_change_cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
e = [0] * (n + 1)
w = [0] * (n + 1)

for i in range(len(s)):
    if s[i] == "E":
        e[i+1] = e[i] + 1
        w[i+1] = w[i]
    else:
        w[i+1] = w[i] + 1
        e[i+1] = e[i]

t = [0] * n
ans = 10 ** 9
for i in range(0, n):
    t = w[i] + e[n] - e[i]
    ans = min(ans, t)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
e = [0] * (n + 1)
w = [0] * (n + 1)

for i in range(len(s)):
    if s[i] == "E":
        e[i+1] = e[i] + 1
        w[i+1] = w[i]
    else:
        w[i+1] = w[i] + 1
        e[i+1] = e[i]

t = [0] * n
ans = 10 ** 9
for i in range(1, n+1):
    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=str(input())
e_cnt=s.count('E')
num=[0]*n #Wの数
num2=[0]*(n+1) #Eno左から数えた数
count=0
count2=0
for i in range(n):
    if s[i]=='W':
        num[i]=count
        num2[i]=e_cnt-count2
        count+=1
    else:
        num[i]=count
        num2[i]=e_cnt-count2 
        count2+=1
    
   
#print(num,num2)

ans=[0]*n

for i in range(n):
    ans[i]=abs(num[i]+num2[i])
print(min(ans))

Submission status: Wrong Answer

Solution code:

n=int(input())
s=str(input())
e_cnt=s.count('E')
num=[0]*n #Wの数
num2=[0]*n #Eno左から数えた数
count=0
count2=0
for i in range(n):
    if s[i]=='W':
        num[i]=count
        num2[i]=e_cnt-count2
        count+=1
    else:
        num[i]=count
        num2[i]=e_cnt-count2 
        count2+=1
    
   

ans=[0]*n

for i in range(n):
    ans[i]=abs(num[i]+num2[i])
print(min(ans))

Submission status: Wrong Answer

Solution code:

n=int(input())
s=str(input())
e_cnt=s.count('E')
num=[0]*n #Wの数
num2=[0]*(n+1) #Eno左から数えた数
count=0
count2=0
for i in range(n):
    if s[i]=='W':
        num[i]=count
        num2[i+1]=e_cnt-count2
        count+=1
    else:
        num[i]=count
        num2[i+1]=e_cnt-count2 
        count2+=1
    
   

ans=[0]*n

for i in range(n):
    ans[i]=abs(num[i]+num2[i+1])
print(min(ans))

Submission status: Wrong Answer

Solution code:

n=int(input())
s=str(input())
e_cnt=s.count('E')
num=[0]*n
num2=[0]*n
count=0
count2=0
for i in range(n):
    if s[i]=='W':
        count+=1
    else:
        count2+=1
    num[i]=count
    num2[i]=e_cnt-count2


ans=[0]*n

for i in range(n):
    ans[i]=abs(num[i]+num2[i])
print(min(ans))

Submission status: Wrong Answer

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

tmp = S[1:0].count('E')
  
minimum = tmp

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

print(minimum)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    people = list(input())

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))[1:]
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))[1:]

    def linearsearch():
        easts_total = easts[-1]
        for i in range(1, N):
            yield wests[i-1] + easts_total - easts[i]

    print(min(linearsearch()))

main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    people = list(input())

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))[1:]
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))[1:]

    def linearsearch():
        easts_total = easts[-1]
        for i in range(1, N-1):
            yield wests[i-1] + easts_total - easts[i+1]

    print(min(linearsearch()))

main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    people = list(input())

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))

    def fullsearch():
        easts_total = easts[-1]
        for i in range(1, N):
            yield wests[i-1] + easts_total - easts[i+1]

    print(min(fullsearch()))

main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    people = list(input())

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))

    def fullsearch():
        easts_total = easts[-1]
        for i in range(1, N):
            yield wests[i-1] + easts_total - easts[i]

    print(min(fullsearch()))

main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    people = list(input())

    wests = list(accumulate([0]+people, lambda total, x: total + (1 if x == "W" else 0)))
    easts = list(accumulate([0]+people, lambda total, x: total + (1 if x == "E" else 0)))

    def fullsearch():
        easts_total = easts[-1]
        for i in range(N):
            yield wests[i] + easts_total - easts[i]

    print(min(fullsearch()))

main()

Submission status: Wrong Answer

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

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

# print('count', count)
ans = 10**6
for i in range(N):
    e1, w1 = count[i]
    e2, w2 = count[-1]
    v = w1 + (e2 - e1)
    # print('v', v)
    ans = min(ans, v)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
s = input()
ans = 0
wl = []
el = []
for ss in s:
    if ss == 'W':
        wl.append(1)
        el.append(0)
    else:
        wl.append(0)
        el.append(1)
el.reverse()
wll = list(itertools.accumulate(wl))
ell = list(itertools.accumulate(el))
ell.reverse()

INF = float("inf")
ans = INF

for i in range(1, n-1):
    ans = min(ans, abs(wll[i-1]+ell[i-1]))

print(ans-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#左から数える
W=[0]*N
w = 0
for i in range(N):
    if S[i] == "W":
        w += 1
    W[i] = w
#右から数える
E = [0]*N
e = 0
for i in range(N):
    if S[N-1-i] == "E":
        e += 1
    E[N-1-i] = e
ans = 10**9
for i in range(N):
    count = W[i] + E[i]
    ans = min(ans,count)
    print(W[i],end=":")
    print(E[i])
print(ans-1)

Submission status: Wrong Answer

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

if 0 != min(s.count('W'), s.count('E')):
    print(min(s.count('W'), s.count('E')) - 1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def main():
    N, S = open(0).read().split()
    cost = S.count("E")
    ans = int(1e9 + 7)
    for si in S:
        if cost < ans:
            ans = cost
        if si == "E":
            cost -= 1
        else:
            cost += 1
    print(ans)
    return


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter



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

    c = Counter(S)

    ans = float("inf")

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

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

N=int(input())
l = input()
mi = 300000

print(l)

for i in range(N):
    count=0
    for j in range(N):
        if i>j:
            if l[j]=="W":
                count+=1
        elif i<j:
            if l[j]=="E":
                count+=1
        else:
            continue
    mi=min(mi,count)

print(mi)

Submission status: Wrong Answer

Solution code:
s=input()
li=list(input())

min = 100000000

w = 0

for index, i in enumerate(li):
  a = 0
  if i == 'W':
    w += 1
  
  s = li[index + 1:].count('E')

  a = w + s
    
  if min > a:
    min = a
    
print(min)

Submission status: Wrong Answer

Solution code:

def Attention():
    N = int(input())
    S = input()
    ans = 300000

    Wcount = [0]
    Ecount = [0]
    cnt = 0
    for i in range(N):
        if S[i] == 'W':
            cnt += 1
        Wcount.append(cnt)
    cnt = 0
    for i in range(N):
        if S[i * -1] == 'E':
            cnt += 1
        Ecount.append(cnt)

    for i in range(N):
        cnt = Wcount[i] + Ecount[(i + 1) * -1]
        ans = min(cnt, ans)
    print(ans)

Attention()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
num = [0 for _ in range(N)]

for i in range(1, N):
  if S[i] == 'E':
    num[0] += 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

all_W_E = [0, 0]
for s in S:
    if s == "W":
        all_W_E[0] += 1
    else:
        all_W_E[1] += 1

now_W = 0
now_E = 0
ans_list = [0] * N

for i in range(N):
    ans_list[i] = (now_W + all_W_E[1] - now_E)
    if S[i] == "W":
        now_W += 1
    else:
        now_E += 1
    
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#------------------------------
#########タイムオーバー########
#------------------------------
# minimum = 300000
# for i in range(N):
    # leftWestNum = S[:i].count('W')
    # rightEstNum = S[i+1:N].count('E')
    # tmpMin = leftWestNum + rightEstNum
    # if tmpMin < minimum:
        # minimum = tmpMin
# print(minimum)

minimum = 3000000
numEast = [0] * (N+1)
numWest = [0] * (N+1)
for i in range(N):
    if S[i] == 'E':
        numEast[i+1] = numEast[i] + 1
        numWest[i+1] = numWest[i]
    else:
        numEast[i+1] = numEast[i]
        numWest[i+1] = numWest[i] + 1

for i in range(N):
    tmpMin = numWest[i] + (numEast[N]-numEast[i])
    if tmpMin < minimum:
        minimum = tmpMin

print(minimum)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
#------------------------------
#########タイムオーバー########
#------------------------------
# minimum = 300000
# for i in range(N):
    # leftWestNum = S[:i].count('W')
    # rightEstNum = S[i+1:N].count('E')
    # tmpMin = leftWestNum + rightEstNum
    # if tmpMin < minimum:
        # minimum = tmpMin
# print(minimum)

minimum = 300000
numEast = [0] * (N+1)
numWest = [0] * (N+1)
for i in range(N):
    if S[i] == 'E':
        numEast[i+1] = numEast[i] + 1
        numWest[i+1] = numWest[i]
    else:
        numEast[i+1] = numEast[i]
        numWest[i+1] = numWest[i] + 1

for i in range(N):
    tmpMin = numWest[i] + (numEast[N]-numEast[i])
    if tmpMin < minimum:
        minimum = tmpMin

print(minimum)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
cnt = [0]*n
for i in range(n):
    cnt[i] = s[0:i].count("w") + s[i+1:n].count("e")
print(min(cnt))

Submission status: Wrong Answer

Solution code:

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

W = [0]
E = [0]

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

ans = float("inf")
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 = input()

W = [0]
E = [0]

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

ans = float("inf")
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 = input()

W = [0]
E = [0]

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

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

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 = n
for i in range(n):
    ans = min(ans, w[i-1]+e[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())
        S=list(input().rstrip().replace("W","1").replace("E","0"))

        csum=["0"]+S
        csum=list(map(int,csum))
        csum=list(accumulate(csum))#Wの数
        ans=10^9+7
        for i in range(1,N+1,1):
            numWleft=csum[i-1]-csum[0]
            numEright=(N-i)-(csum[N]-csum[i])
            ans=min(ans,numWleft+numEright)
        print(ans)

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())
        S=list(input().rstrip().replace("W","1").replace("E","0"))

        csum=["0"]+S
        csum=list(map(int,csum))
        csum=list(accumulate(csum))#Wの数
        ans=10^9+7
        for i in range(1,N,1):
            numWleft=csum[i-1]-csum[0]
            numEright=(N-i)-(csum[N]-csum[i])
            ans=min(ans,numWleft+numEright)
        print(ans)

from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
A = [0] * (N + 1)
mn = 1000000 
pos = 0 
for i in range(N):
        if S[i] == "W":
                A[i + 1] = A[i] + 1   
        else:
                A[i + 1] = A[i]
for i in range(1, N + 1): 
        mn = min(mn, 2*A[i] + N - i - A[N])
print(mn)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
A = [0] * (N + 1)
mn = 1000000 
pos = 0 
for i in range(N):
        if S[i] == "W":
                A[i + 1] = A[i] + 1   
        else:
                A[i + 1] = A[i]
for i in range(N):
        mn = min(mn, 2*A[i] + N - i - A[N])
print(mn)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
S = input()
w, e = [0], [0]
for i in range(N):
    if S[i] == "W":
        if len(w) == 1:
            w.append(1)
        else:
            w.append(w[-1] + 1)
    else:
        if len(w) == 1:
            w.append(0)
        else:
            w.append(w[-1])

    if S[-i-1] == "E":
        if len(e) == 1:
            e.append(1)
        else:
            e.append(e[-1] + 1)
    else:
        if len(e) == 1:
            e.append(0)
        else:
            e.append(e[-1])
ans = 10**9
e = list(reversed(e))
for i in range(1, len(w)):
    if 2 <= i < N-1:
        ans = min(ans, w[i-1] + e[i+1])
    elif i == 1:
        ans = min(ans, e[2])
    elif i == len(w)-1:
        ans = min(ans, w[-2])
    # print(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
S = input()
w, e = [0], [0]
for i in range(N):
    if S[i] == "W":
        if len(w) == 1:
            w.append(1)
        else:
            w.append(w[-1] + 1)
    else:
        if len(w) == 1:
            w.append(0)
        else:
            w.append(w[-1])

    if S[-i-1] == "E":
        if len(e) == 1:
            e.append(1)
        else:
            e.append(e[-1] + 1)
    else:
        if len(e) == 1:
            e.append(0)
        else:
            e.append(e[-1])
ans = 10**9
e = list(reversed(e))
for i in range(1, len(w)):
    if 2 <= i < N-1:
        ans = min(ans, w[i-1] + e[i+1])
    elif i == 1:
        ans = min(ans, e[1])
    elif i == len(w)-1:
        ans = min(ans, w[-2])
    # print(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
S = input()
w, e = [0], [0]
for i in range(N):
    if S[i] == "W":
        if len(w) == 1:
            w.append(1)
        else:
            w.append(w[-1] + 1)
    else:
        if len(w) == 1:
            w.append(0)
        else:
            w.append(w[-1])

    if S[-i-1] == "E":
        if len(e) == 1:
            e.append(1)
        else:
            e.append(e[-1] + 1)
    else:
        if len(e) == 1:
            e.append(0)
        else:
            e.append(e[-1])
ans = 10**9
e = list(reversed(e))
for i in range(1, len(w)):
    if 2 <= i < N-1:
        ans = min(ans, w[i-1] + e[i+1])
    elif i == 1:
        ans = min(ans, e[0])
    elif i == len(w)-1:
        ans = min(ans, w[-1])
    # print(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
S = input()
w, e = [0], [0]
for i in range(N):
    if S[i] == "W":
        if len(w) == 1:
            w.append(1)
        else:
            w.append(w[-1] + 1)
    else:
        if len(w) == 1:
            w.append(0)
        else:
            w.append(w[-1])

    if S[-i-1] == "E":
        if len(e) == 1:
            e.append(1)
        else:
            e.append(e[-1] + 1)
    else:
        if len(e) == 1:
            e.append(0)
        else:
            e.append(e[-1])
ans = 10**9
e = list(reversed(e))
for i in range(len(w)):
    if 1 <= i < N-1:
        ans = min(ans, w[i-1] + e[i+1])
    elif i == 0:
        ans = min(ans, e[0])
    elif i == len(w)-1:
        ans = min(ans, w[-1])
    # print(ans, i)
print(ans)