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:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    S = list(_ for _ in input())
    l = S.count('E')
    r = 0
    ans = min(S.count('E'),S.count('W'))
    print(ans)
    for i in range(N):
        if i != N-1:
            if S[i] == 'E':
                l = l - 1
        if i != 0:                        
            if prev == 'W':
                r = r + 1
        prev = S[i]
        ans = min(ans,l+r)
        # print(ans,l,r)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    S = list(_ for _ in input())
    l = S.count('E')
    r = 0
    ans = N
    for i in range(N):
        if i != N-1:
            if S[i] == 'E':
                l = l - 1
        if i != 0:                        
            if prev == 'W':
                r = r + 1
        ans = min(ans,l+r)
        prev = S[i]
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC98 C

#累積和を用いる
from itertools import accumulate

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

x = [0]+[1 if s[i] == 'W' else 0 for i in range(n)]
y = [0]+[1 if s[i] == 'E' else 0 for i in range(n)]

mx = list(accumulate(x))
my = list(accumulate(y[::-1]))
my = my[::-1]

mi = float('inf')
for i in range(1,n-1):
    a = mx[i-1]
    b = my[i+1]
    mi = min(mi,a+b)
print(mi)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
East = [0] * (N)
if S[0] == "E":
    East[0] = 1
for i in range(N-1):
    if i == N-1:
        break
    if S[i+1] == 'E':
        East[i+1] = East[i] + 1
    else:
        East[i+1] = East[i]
# print(East)
result = East[N-1] -East[1]
if result == 0:
    result = N
for i in range(1,N):
    if i == N-1:
        ans = (i-1) -East[i-2]
    elif i == 1:
        ans = East[N-1] - East[i+1]
    else:
        right_E = East[N-1] - East[i+1]
        left_W = (i-1) -East[i-2]
        ans = right_E + left_W
    if result > ans and ans != 0:
        result = ans
        # print(i)
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
East = [0] * (N)
if S[0] == "E":
    East[0] = 1
for i in range(N-1):
    if i == N-1:
        break
    if S[i+1] == 'E':
        East[i+1] = East[i] + 1
    else:
        East[i+1] = East[i]
# print(East)
result = East[N-1] -East[1]
for i in range(1,N):
    if i == N-1:
        ans = (i-1) -East[i-2]
    elif i == 1:
        ans = East[N-1] - East[i+1]
    else:
        right_E = East[N-1] - East[i+1]
        left_W = (i-1) -East[i-2]
        ans = right_E + left_W
    if result > ans and ans != 0:
        result = ans
        # print(i)
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
East = [0] * (N)
if S[0] == "E":
    East[0] = 1
for i in range(N-1):
    if i == N-1:
        break
    if S[i+1] == 'E':
        East[i+1] = East[i] + 1
    else:
        East[i+1] = East[i]
# print(East)
result = East[N-1] -East[1]
for i in range(1,N):
    if i == N-1:
        ans = (i-1) -East[i-2]
    elif i == 1:
        ans = East[N-1] - East[i+1]
    else:
        right_E = East[N-1] - East[i+1]
        left_W = (i-1) -East[i-2]
        ans = right_E + left_W
    if result > ans:
        result = ans
        # print(i)
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
East = [0] * (N)
if S[0] == "E":
    East[0] = 1
for i in range(N-1):
    if i == N-1:
        break
    if S[i+1] == 'E':
        East[i+1] = East[i] + 1
    else:
        East[i+1] = East[i]
print(East)
result = East[N-1] -East[1]
for i in range(1,N):
    if i == N-1:
        ans = (i-1) -East[i-2]
    elif i == 1:
        ans = East[N-1] - East[i+1]
    else:
        right_E = East[N-1] - East[i+1]
        left_W = (i-1) -East[i-2]
        ans = right_E + left_W
    if result > ans:
        result = ans
        print(i)
print(result)

Submission status: Wrong Answer

Solution code:

from collections import Counter

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

count_E = Counter(S)['E']
count_W = Counter(S)['W']

right = 0
left = count_E
tmp = N
for i in range(N):
    if right + left < tmp:
        tmp = right + left
    if S[i] == 'W':
        right += 1
    else:
        left -= 1
print(tmp)

Submission status: Wrong Answer

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

num_first = 0
for i in range(1, n):
    if s[i] == 'E':
        num_first += 1
    
d.append(num_first)

for i in range(n):
    tmp = 0
    if i == 0 or i == n-1:
        continue
    if s[i-1] == 'W':
        tmp += 1
    if s[i] == 'E':
        tmp -= 1
    d.append(d[i-1] + tmp)

print(min(d))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input()) + 'W'

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
lsw=[0]
lse=[0]
for i in range(n):
	if s[i]=='W':
		lsw.append(lsw[i]+1)
		lse.append(lse[i])
	else:
		lsw.append(lsw[i])
		lse.append(lse[i]+1)
	
ans=[]

for i in range(n):
	can = lsw[i]+(lse[n]-lse[i])
	ans.append(can)
	
print(min(ans))

Submission status: Wrong Answer

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

lst_ans=[]
num_e= s.count("E")
ans = num_e
for i in range(n):
    if s[i] == "E":ans -= 1
    if i != 0:
        if s[i-1]=="W":ans += 1
    lst_ans.append(ans)
print(lst_ans)
print(min(lst_ans))

Submission status: Wrong Answer

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

w = [0] * (N+1)
cnt = 0
for i in range(N):
    if S[i] == 'W':
        cnt += 1
        w[i+1] = cnt
    else:
        w[i+1] = w[i]

e = [0] * (N+1)
cnt = 0
for i in range(N):
    if S[i] == 'E':
        cnt += 1
        e[i+1] = cnt
    else:
        e[i+1] = e[i]

L = []  
for i in range(1, N+1):
    num = w[i-1] + e[N] - e[i]
    L.append(num)
    
print((L))

Submission status: Wrong Answer

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

mincount=s.count('E')
ans=mincount

# それぞれをリーダーとして試算する
for i in range(1,n):
    # リーダーより左のWの数を累積していく
    if s[i]=="E":
        mincount-=1
    if s[i-1]=="W":
        mincount+=1
    ans=min(ans,mincount)
print(ans)

Submission status: Wrong Answer

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

cnt_right = S[1:].count('E')
cnt_left = 0
ans = cnt_right + cnt_left

for ichi in range(len(S)-1):
    if S[ichi] == 'W':
        cnt_left += 1
    if S[ichi+1] == 'E':
        cnt_right -= 1
    ans = min(ans, cnt_right + cnt_left)

Submission status: Wrong Answer

Solution code:
# 入力
N = input()

A1 = [ n=='E' for n in input()]


minimum = sum(A1[1:])
count = minimum
print(count)
for i in range(1,int(N)):
    if(not A1[i-1]):
        count += 1
    if(A1[i]):
        count -= 1
    print(i,count)
    if(count<minimum):
        minimum = count
print(minimum)

Submission status: Wrong Answer

Solution code:
# 入力
N = input()

A1 = [ n=='E' for n in input()]


minimum = sum(A1)
count = minimum
for i in range(1,int(N)):
    if(not A1[i-1]):
        count += 1
    if(A1[i]):
        count -= 1
    if(count<minimum):
        minimum = count
print(minimum)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
move=S.count("E")
ans=[move]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
print(min(s.count('W'),s.count('E')))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

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

line = []
E = 0
W = 0
error = 0

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

counter = 0

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

    line.append(counter)

print(min(line))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

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

line = []
E = 0
W = 0
error = 0

# for i in range(N):
#     if(S[i]=='E'):
#         E += 1
#     elif(S[i]=='W'):
#         W += 1
#     else:
#         error += 1

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

counter = 0

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

    line.append(counter)

print(min(line))

Submission status: Wrong Answer

Solution code:
#coding: utf-8

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

line = []
E = 0
W = 0
error = 0

# for i in range(N):
#     if(S[i]=='E'):
#         E += 1
#     elif(S[i]=='W'):
#         W += 1
#     else:
#         error += 1

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

counter = 0

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

    line.append(counter)

print(line)

Submission status: Wrong Answer

Solution code:
#coding: utf-8

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

line = []

for n in range(N):
    samurai = ''
    if(n==0):
        for i in range(N):
            samurai += 'W'
    else:
        for i in range(n):
            samurai += 'W'
        for j in range(n, N):
            samurai += 'E'

    #print(samurai)
    counter = 0

    for i in range(N):
        if(samurai[i]==S[i]):
            counter += 0
        else:
            counter += 1
    #print(counter)
    line.append(counter)

ans = min(line) -1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
ans_list = [0]*n
e_num = Counter(s)['E']
ans = e_num
for i in range(1, n):
    if s[i] == 'E':
        e_num -= 1
    if s[i-1] == 'W':
        e_num += 1
    ans = min(e_num, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
ans_list = [0]*n
for i in range(n):
    if s[i] == 'W':
        ans_list[i] = (Counter(s[i+1:])['W'] + Counter(s[:i])['E'])
    else:
        ans_list[i] = (Counter(s[i+1:])['E'] + Counter(s[:i])['W'])
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
ans_list = []
for i in range(n):
    if s[i] == 'W':
        ans_list.append(Counter(s[i+1:])['W'] + Counter(s[:i])['E'])
    else:
        ans_list.append(Counter(s[i+1:])['E'] + Counter(s[:i])['W'])
print(min(ans_list))
print(ans_list)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
ans_list = []
for i in range(n):
    if s[i] == 'W':
        ans_list.append(Counter(s[i+1:])['W'] + Counter(s[:i])['E'])
    else:
        ans_list.append(Counter(s[i+1:])['E'] + Counter(s[:i])['W'])
print(min(ans_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
s_min = s[:].count("E")
s_now = s[:].count("E")

for i in range(1,n):
    if s[i-1] == "E" and s[i] == "E":
        s_now -= 1
    if s[i-1] == "W" and s[i] == "W":
        s_now += 1
    s_min = min(s_min, s_now)
print(s_min)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=list(S())

  if n==1:
    return 0

  l2=[0]*(n+1)
  for i in range(n):
    if l[i]=='E':
      l2[i+1]+=1

  for i in range(1,n+1):
    l2[i]+=l2[i-1]

  mn=inf
  for i in range(1,n):
    mn=min(mn,l2[-1]-l2[i]+i-2-l2[i-1])

  return mn

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=list(S())

  if n==1:
    return 0

  l2=[0]*(n+1)
  for i in range(n):
    if l[i]=='E':
      l2[i+1]+=1

  for i in range(1,n+1):
    l2[i]+=l2[i-1]

  mn=inf
  for i in range(1,n):
    mn=min(mn,l2[-1]-l2[i]+i-1-l2[i-1])

  return mn

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=list(S())

  l2=[0]*(n+1)
  for i in range(n):
    if l[i]=='E':
      l2[i+1]+=1

  for i in range(1,n+1):
    l2[i]+=l2[i-1]

  mn=inf
  for i in range(1,n):
    mn=min(mn,l2[-1]-l2[i]+i-1-l2[i-1])

  return mn

print(main())

Submission status: Wrong Answer

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

w = [0]
e = [0]

rs = s[::-1]
for i, c in enumerate(s):
  if c == "W":
    w.append(w[i]+1)
  else:
    w.append(w[i])
    
for i, c in enumerate(rs):
  if c == "E":
    e.append(e[i]+1)
  else:
    e.append(e[i])

e.reverse()

print(min([w[i-1]+e[i+1] for i in range(1, len(e)-1)]))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
EW = []
for n in range(N-1):
  if (S[n]=="E") and (S[n+1]=="W"):
    EW.append(n)
if EW == []:
  EW = [-1, len(S)-1]

mn_ans = 1000000
for i in range(len(EW)):
  ans = S[:EW[i]+1].count("W") + S[EW[i]+1:].count("E")
  if mn_ans > ans:
    mn_ans = ans
print(mn_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
EW = []
for n in range(N-1):
  if (S[n]=="E") and (S[n+1]=="W"):
    EW.append(n)
if EW == []:
  EW = [-1, len(S)]

mn_ans = 1000000
for i in range(len(EW)):
  ans = S[:EW[i]+1].count("W") + S[EW[i]+1:].count("E")
  if mn_ans > ans:
    mn_ans = ans
print(mn_ans)

Submission status: Wrong Answer

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

cost = S.count('E')

ans = N
for c in S:
    if c == 'E':
        cost -= 1
    else:
        if ans > cost:
            ans = cost
        cost += 1
else:
    if ans > cost:
        ans = cost
print(cost)

Submission status: Wrong Answer

Solution code:
import re

def calc(people):
    ans = 10 ** 6
    Ws = 0
    Es = people.count("E")
    ans = min(ans, Ws + Es)

    for i in range(1, len(people)):
        if people[i] == "E":
            Es -= 1
        
        if people[i - 1] == "W":
            Ws += 1

        ans = min(ans, Ws + Es)
    
    return ans


if __name__ == "__main__":
    _ = input()
    people = input()

    print(calc(people))

Submission status: Wrong Answer

Solution code:
import re

def calc(people):
    people_sp_by_W = re.split(r'W+', people)
    people_sp_by_E = re.split(r'E+', people)

    return min(len(people_sp_by_W), len(people_sp_by_E)) - 1

if __name__ == "__main__":
    _ = input()
    people = input()

    print(calc(people))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
W_count = [0] * (N + 1)
E_count = [0] * (N + 1)

for i in range(len(S)):
  W_count[i + 1] = W_count[i] + (1 if S[i] == 'W' else 0)
  E_count[i + 1] = E_count[i] + (1 if S[i] == 'E' else 0)

answer = 4 * (10 ** 5)
for i in range(len(S)):
  if i == 0:
    answer = min(answer, E_count[-1] - E_count[1])
  elif i == len(S) - 1:
    answer = min(answer, W_count[len(S) - 2] - W_count[0])
  else:
    answer = min(answer, W_count[i - 1] - W_count[0] + E_count[-1] - E_count[i + 1])

print(answer)

Submission status: Wrong Answer

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(map(lambda x: x, inputs[0]))
    N = len(persons)
    cumsum_w = []
    cumsum_w.append(0)

    for i, p in enumerate(persons):
        sum_w = cumsum_w[i] + 1 if p == "W" else cumsum_w[i]
        cumsum_w.append(sum_w)

    counts = []
    for i, _ in enumerate(cumsum_w):
        if i == N:
            break
        sum = cumsum_w[i - 1] + ((N - i) - (cumsum_w[N] - cumsum_w[i]))
        counts.append(sum)

    min = counts[0]
    for value in counts:
        min = value if min > value else min

    return min


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(map(lambda x: x, inputs[0]))
    N = len(persons)
    counts = []
    for leader, _ in enumerate(persons):
        count = 0
        for p in range(0, leader):
            if persons[p] == "W":
                count += 1
        for p in range(leader + 1, N):
            if persons[p] == "E":
                count += 1
        counts.append(count)
    min = counts[0]
    for count in counts:
        if min > count:
            min = count

    return min


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

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

ans = float('inf')
sum_E = [0]
sum_W = [0]
cnt_e = 0
cnt_w = 0

for i in range(N):
	if S[i] == 'E':
		cnt_e += 1
	else:
		cnt_w += 1
	sum_E.append(cnt_e)
	sum_W.append(cnt_w)

print(sum_E,sum_W)


for i in range(N):
	ans = min(ans, sum_W[i] + sum_E[-1] - sum_E[i+1])

print(ans)

Submission status: Wrong Answer

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

res = float('inf')
W_sum = [0]
E_sum = [S.count('E')]
for i in range(0, N):
    W_sum.append(W_sum[i] + 1 if S[i] == 'W' else W_sum[i]) 
    E_sum.append(E_sum[i] - 1 if S[i] == 'E' else E_sum[i])
    res = min(res, W_sum[i] + E_sum[i])
    
print(res)

Submission status: Wrong Answer

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

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

print(W_sum) 
print(E_sum) 
res = float('inf')
for i in range(0, N+1):
    res = min(res, W_sum[i] + E_sum[i])
    
print(res)

Submission status: Wrong Answer

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

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

res = float('inf')
for i in range(1, N+1):
    res = min(res, W_sum[i] + E_sum[i])
    
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N = readi()
    a = reads()
    e = arr(N + 1)
    w = arr(N + 1)
    for i in range(N):
        e[i + 1] = e[i] + (1 if a[i] == "E" else 0)
        w[i + 1] = w[i] + (1 if a[i] == "W" else 0)

    dbg(e=e)
    dbg(w=w)

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
R=[0]
for i in range(N):
    R.append(R[i]+(A[i]=="W"))
min([R[i]+(N-i-1)-(R[-1]-R[i+1]) for i in range(N)])

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
temp = S.count('E')
ans = [temp]

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

print(min(ans))

Submission status: Wrong Answer

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

N = int(input())
S = input()
cnt = [0] * (N+1)
cnt[0] = 0
ans = N

for i in range(N):
    cnt[i+1] = cnt[i]
    if S[i] == 'W':
        cnt[i+1] += 1

for j in range(N):
    ans = min(ans, cnt[j-1] + (N - j) - (cnt[N]-cnt[j]))

print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
S = input()
cnt = S.count('E')
ans = cnt

for v in S:
  if v == 'E':
    cnt -= 1
  else:
    cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = S.count('E')
ans = cnt

for v in S:
  if v == 'E':
    cnt -= 1
  else:
    cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Wrong Answer

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

print(ans)
#print(E)
#print(W)

Submission status: Wrong Answer

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


def solve(N: int, S: str):
    W = 0
    E = 0
    for c in S:
        if c == 'W':
            W += 1
        else:
            E += 1
    w, e = 0, 0
    ret = float('inf')
    for i in range(N):
        ret = min(ret, (w + E - e))
        if S[i] == 'W':
            w += 1
        else:
            e += 1
    print(ret)
    return


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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    print(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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

numLeft = [0] * N
numRight = [S.count("E")] * N

for i in range(N):
	if i > 0:
		if S[i] == "W":
			numRight[i] = numRight[i - 1]
		else:
			numRight[i] = numRight[i - 1] - 1
	if i < N - 1:
		if S[i] == "W":
			numLeft[i + 1] = numLeft[i] + 1
		else:
			numLeft[i + 1] = numLeft[i]

num = [0] * N
for j in range(N):
	num[j] = numLeft[j] + numRight[j]
print(min(num))

Submission status: Wrong Answer

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

numLeft = [0] * N
numRight = [S.count("E")] * N

for i in range(N):
	if S[i] == "W":
		if i >= 1:
			numRight[i] = numRight[i - 1]
		if i <= N - 2:
			numLeft[i + 1] = numLeft[i] + 1
	elif S[i] == "E":
		if i >= 1:
			numRight[i] = numRight[i - 1] - 1
		if i <= N - 2:
			numLeft[i + 1] = numLeft[i]

num = [0] * N
for j in range(N):
	num[j] = numLeft[j] + numRight[j]
print(min(num))

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    data = list(input())
    soppo = data[1:].count('E')

    ans = soppo
    if data[0] == 'W':
        soppo += 1

    for i in range(1, num):
        if soppo < ans:
            ans = soppo
        now_person = data[i]

        if now_person == 'E':
            soppo -= 1
        else:
            soppo += 1

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    data = list(input())
    count_e = data[1:].count('E')
    count_w = 0

    ans = num
    for i in range(num):
        now_person = data[i]
        kari = count_w + count_e
        if kari < ans:
            ans = kari
        if now_person == 'E' and i != 0:
            count_e -= 1
        else:
            count_w += 1

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    num = int(input())
    data = list(input())
    count_e = data[1:].count('E')
    count_w = 0

    ans = num
    for i in range(num):
        now_person = data[i]
        kari = count_w + count_e
        if kari < ans:
            ans = kari
        if now_person == 'E':
            count_e -= 1
        else:
            count_w += 1

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    num = int(input())
    data = list(input())
    count_e = data.count('E')
    count_w = 0

    ans = num
    for i in range(num):
        now_person = data[i]
        kari = count_w + count_e
        if kari < ans:
            ans = kari
        if now_person == 'E':
            count_e -= 1
        else:
            count_w += 1

    print(ans)



if __name__ == '__main__':
    main()

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