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

if S[0] == "E":
    count = S.count("W")
else:
    count = S.count("E")

result = count

for i in range(1,N):
    if S[i-1] == "W" and S[i] == "W":
        count += 1
    elif S[i-1] == "E" and S[i] == "E":
        count -= 1
        if result > count and count >= 0:
            result = count
print(result)

Submission status: Wrong Answer

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

count = S.count("E")
count2 = S.count("W")
result = S.count("E")


if count == N:
    result = 0
else:
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count
for i in range(1, N):
    if S[i-1] == "W" and S[i] == "W":
        count2 += 1
    elif S[i-1] == "E" and S[i] == "E":
        count2 -= 1
        if result > count2:
            result = count2
print(result)

Submission status: Wrong Answer

Solution code:
s = ["", ""]

s[0] = input()
s[1] = input()

WtoE = []
wtoec = 0
EtoW = []
etowc = 0

for c in s[1]:
    if c == "W":
        wtoec = wtoec + 1
    WtoE.append(wtoec)

for c in s[1][::-1]:
    if c == "E":
        etowc = etowc + 1
    EtoW.append(etowc)
EtoW.reverse()
print(WtoE)
print(EtoW)

a = []
for i in range(0, int(s[0])):
    ans = WtoE[i] + EtoW[i]
    if WtoE[i] != 0 and s[1][i] == "W" or EtoW[i] != 0 and s[1][i] == "E":
        ans = ans - 1

    a.append(ans)

print(min(a))

Submission status: Wrong Answer

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

count = S.count("E")
result = S.count("E")


if count == N:
    result = 0
else:
    for i in range(1,N):
        if S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
tmp = 0
west = []
east = []
for i in range(1,N+1):
    west.append(S[0:i].count("W"))
    east.append(S[0:i].count("E"))

_min = N
for i in range(N):
    _WtoE = west[i]
    _EtoW = east[-1] - east[i]
    if _min > _WtoE + _EtoW:
        _min = _WtoE + _EtoW
print(_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = []
x = 0
y = s[1:n].count('E')
for ch in s[:n-1]:
    t.append(x+y)
    if ch == 'W':
        x += 1
    else:
        y -= 1    
print(min(t))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = []
x = 0
y = s[1:n].count('E')
for ch in s[:-1]:
    t.append(x+y)
    if ch == 'W':
        x += 1
    else:
        y -= 1    
print(min(t))

Submission status: Wrong Answer

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

count = S.count("E")
result = S.count("E")


if count == N:
    result = 0
else:
    for i in range(1,N):
        if (S[i-1] == "W" and S[i] == "E") or (S[i-1] == "E" and S[i] == "W"):
            pass
        elif S[i-1] == "W" and S[i] == "W":
            count += 1
        elif S[i-1] == "E" and S[i] == "E":
            count -= 1
            if result > count:
                result = count
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
t = []
x = 0
y = s[1:n].count('E')
for ch in s:
    t.append(x+y)
    if ch == 'W':
        x += 1
    else:
        y -= 1    
print(min(t))

Submission status: Wrong Answer

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

count=0
i=0
j=N-1

while i<j:
    if s[i]=="E":
        i+=1
        continue
    if s[j]=="W":
        j-=1
        continue
    pre_i=i
    pre_j=j
    pos_i=i
    pos_j=j
    j_i=0
    j_j=0
    while s[pos_i]=="W":
        pos_i+=1
        j_i+=1
    while s[pos_j]=="E":
        pos_j-=1
        j_j+=1
    if j_i<j_j:
        i=pos_i
        count+=pos_i-pre_i
    else:
        j=pos_j
        count+=pre_j-pos_j
    
print(count)

Submission status: Wrong Answer

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

count=0
i=0
j=N-1

while i<j:
    if s[i]=="E":
        i+=1
        continue
    if s[j]=="W":
        j-=1
        continue
    sub_i=i
    sub_j=j
    j_i=0
    j_j=0
    while s[sub_i]=="W":
        sub_i+=1
        j_i+=1
    while s[sub_j]=="E":
        sub_j-=1
        j_j+=1
    if j_i<j_j:
        i=sub_i
        count+=sub_i-i
    else:
        j=sub_j
        count+=j-sub_j
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
S = list(raw_input())
D = [[0, 0]]
W = [0] * (N+2)
E = [0] * (N+2)
for i in range(N):
 if S[i] == 'W':
  W[i+1] = W[i]+1
for i in range(N)[::-1]:
 if S[i] == 'E':
  E[i] = E[i+1]+1
ans = N+1
for w, e in zip(W, E):
  if w+e < ans:
   ans = w+e
print ans

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
l = S.count("E")
k = l

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

Submission status: Wrong Answer

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

count=0
i=0
j=N-1

while i<j:
    if s[i]=="E":
        i+=1
        continue
    if s[j]=="W":
        j-=1
        continue
    sub_i=i
    sub_j=j
    j_i=0
    j_j=0
    while s[sub_i]=="W":
        sub_i+=1
        j_i+=1
    while s[sub_j]=="E":
        sub_j-=1
        j_j+=1
    if j_i<j_j:
        i=sub_i
        count+=1
    else:
        j=sub_j
        count+=1
    
print(count)

Submission status: Wrong Answer

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

ms = n
a = 0
b = s.count('E')
for i in range(n):
	if(s[i] == 'W'):
		a += 1
	if(s[i] == 'E'):
		b -= 1
	# c = s[0:i].count('W')
	# c += s[i+1:n].count('E')
	c = a + b
	if(ms > c):
		ms = c

print(ms)

Submission status: Wrong Answer

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

count = S.count("E")
result = S.count("E")

for i in range(1,N):
    if (S[i-1] == "W" and S[i] == "E") or (S[i-1] == "E" and S[i] == "W"):
        pass
    elif S[i-1] == "W" and S[i] == "W":
        count += 1
    elif S[i-1] == "E" and S[i] == "E":
        count -= 1
        if result > count:
            result = count
print(result)

Submission status: Wrong Answer

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

SUM = 10000000
#1番目は終わり
W_sum = 0
E_sum = S[-(N-1):].count('E')

#両サイドからカウントする
#文字が変化したらカウント
for i in range(1, N-1):#i番目を選ぶ
    left = S[i-1]
    right = S[-(N-(i))+1]

    if left == 'W':
        W_sum += 1
    if right == 'E':
        E_sum -= 1
    
    sumsum = W_sum + E_sum
    if sumsum < SUM:#更新
        SUM = sumsum

print(SUM)

Submission status: Wrong Answer

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

h = N // 2

while True:
    west = S[0:h]
    east = S[h+1:N]
    saisyou = west.count("W") + east.count("E")
    
    west = S[0:h+1]
    east = S[h+2:N]
    right = west.count("W") + east.count("E")

    west = S[0:h-1]
    east = S[h:N]
    left = west.count("W") + east.count("E")

    if min(saisyou, left, right) == left:
        h -= 1
    if min(saisyou, left, right) == right:
        h += 1
    if min(saisyou, left, right) == saisyou:
        print(saisyou)
        break

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()

    E = s[1:]
    j = s[0]
    c = 0
    for i in E:
        if i == 'E':
            c = c + 1
    m = c 

    for i in s:
        if i == 'E':
            c = max(c - 1, 0)
        else:
            c = c + 1

        m = min(m, c)

    print(m)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = input()
min_people = n - 1
pos = int(n/2)
checked_pos = []

def we_counter(pos):
  front = collections.Counter(s[:pos])
  back = collections.Counter(s[pos+1:])
  people = front['W'] + back['E']
  return people

for i in range(2,n):
  people = we_counter(pos)

  front_p = pos - int(n / (2 * i))
  if front_p >= 0:
    left_shift = we_counter(front_p)
  else:
    left_shift = people

  back_p = pos + int(n / (2 * i))
  if back_p < n:
    right_shirt = we_counter(back_p)
  else:
    right_shirt = people

  if left_shift < right_shirt:
    pos = front_p
  elif right_shirt < left_shift:
    pos = back_p
  else:
    front_p = pos-1
    back_p = pos+1

    if front_p >= 0:
      left_shift = we_counter(front_p)
    else:
      left_shift = people
    if back_p < n:
      right_shift = we_counter(back_p)
    else:
      right_shift = people

    if left_shift > right_shift:
      pos = front_p
    elif right_shift > left_shift:
      pos = back_p
    else:
      break

  if people < min_people:
    min_people = people

  if pos in checked_pos or pos < 0 or pos >= n:
    break
  else:
    checked_pos.append(pos)

print(min_people)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()

    E = s[1:]
    j = s[0]
    c = 0
    for i in E:
        if i == 'E':
            c = c + 1
    m = c 

    for i in s:
        if i == 'E':
            c = max(c - 1, 0)
        else:
            c = c + 1

        m = min(m, c)
        print(m)



    print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[:0])["W"] + Counter(st[1:])["E"]
previous = st[0]
for i in range(1,n):
    temp = ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

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

nW = 0
nE = 0

for i in range(N):
    if S[i] == 'E':
        nE += 1
    else:
        nW += 1

count = N

for i in range(N):
    if S[i] == 'E':
        temp = 1
    else: 
        temp = 0
    tempW = 0
    tempE = 0
    for j in range(i):
        if S[j] == 'W':
            tempW += 1
            if tempW > N/2:
                break
        else:
            tempE += 1
            if nE - tempE > N/2:
                break 
    if tempW + nE - tempE - temp < count:
        count = tempW + nE - tempE - temp

print(count)

Submission status: Wrong Answer

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

count = S.count("E")
result = 300000

for i in range(1,N):
    if (S[i-1] == "W" and S[i] == "E") or (S[i-1] == "E" and S[i] == "W"):
        pass
    elif S[i-1] == "W" and S[i] == "W":
        count += 1
    elif S[i-1] == "E" and S[i] == "E":
        count -= 1
        if result > count:
            result = count
print(result)

Submission status: Wrong Answer

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

count = S.count("E")
result = 300000

for i in range(1,N):
    if (S[i-1] == "W" and S[i] == "E") or (S[i-1] == "E" and S[i] == "W"):
        print(count)
        pass
    elif S[i-1] == "W" and S[i] == "W":
        print(count)
        count += 1
    elif S[i-1] == "E" and S[i] == "E":
        print(count)
        count -= 1
        if result > count:
            result = count
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[:0])["W"] + Counter(st[1:])["E"]
previous = st[0]
for i in range(1,n):
    temp = ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

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

count=0
i=0
j=N-1

while i<=j:
    if s[i]=="E":
        i+=1
        continue
    if s[j]=="W":
        j-=1
        continue
    sub_i=i
    sub_j=j
    j_i=0
    j_j=0
    while s[sub_i]=="W":
        sub_i+=1
        j_i+=1
    while s[sub_j]=="E":
        sub_j-=1
        j_j+=1
    if j_i<j_j:
        i=sub_i
        count+=1
    else:
        j=sub_j
        count+=1
    
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 22:24:56 2018

@author: sakas
"""

N = int(input())
S = list(input())
left = []
right = S[:1]
count = right.count('E')
sub = 0
    

for i in range(N):
    left = S[i-1:]
    right = S[:i+1]
    sub = right.count('E') + left.count('W')
    
    if count < sub:
        count = sub
    

print(count)

Submission status: Wrong Answer

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

SUM = 10000000
#1番目は終わり
W_sum = 0
E_sum = S[-(N-1):].count('E')

#両サイドからカウントする
#文字が変化したらカウント
for i in range(1, N-1):#i番目を選ぶ
    left = S[:i]
    right = S[-(N-(i))+1:]

    if left[i-1] == 'W':
        W_sum += 1
    if right[0] == 'E':
        E_sum -= 1
    
    sumsum = W_sum + E_sum
    if sumsum < SUM:#更新
        SUM = sumsum

print(SUM)

Submission status: Wrong Answer

Solution code:
#Attention

#ライブラリ
import copy

#入力
N = int(input())
S = list(input())
ans = []
#計算
for i in range(1,N-1,1):
	S_hidari = copy.copy(S[0:i])
	S_migi = copy.copy(S[i+1:N])
	if i == 1:
		ans.append(S_hidari.count('W')-1+S_migi.count('E'))
		continue
	if i == N-2:
		ans.append(S_hidari.count('W')+S_migi.count('E')-1)
		continue
	ans.append(S_hidari.count('W')+S_migi.count('E'))

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 3*10**5
t = n//2
c1 = s[:t]
d1 = s[t+1:]
if c1.count("W") <= d1.count("E"):
	for i in range(0,t+1):
		count = 0
		a = s[:i]
		b = s[i+1:]
		ac = a.count("W")
		bc = b.count("E")
		count = ac + bc
		if count <= ans:
			ans = count
else:
	for i in range(t+1,n):
		count = 0
		a = s[:i]
		b = s[i+1:]
		ac = a.count("W")
		bc = b.count("E")
		count = ac + bc
		if count <= ans:
			ans = count
print(ans)

Submission status: Wrong Answer

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

SUM = 10000000
#1番目は終わり
W_sum = 0
E_sum = S[-(N-1):].count('E')

#両サイドからカウントする
#文字が変化したらカウント
for i in range(1, N):#i番目を選ぶ
    left = S[:i]
    right = S[-(N-(i))+1:]

    if left[i-1] == 'W':
        W_sum += 1
    if right[0] == 'E':
        E_sum -= 1
    
    sumsum = W_sum + E_sum
    if sumsum < SUM:#更新
        SUM = sumsum

print(SUM)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

s = list(S)
s.reverse()
s_bit = np.array([1 if i == 'E' else 0 for i in s])
bit_mask = np.array([pow(2,i) for i in range(N)])
bit = np.dot(s_bit, bit_mask)

delta = np.array([s_bit[i+1] - 1^s_bit[i] for i in range(N-1)])
ruiseki = np.zeros(N-1)
for i in range(N-2):
    ruiseki[i+1] = ruiseki[i] + delta[i]
minruiseki = min(ruiseki)

a = bit & (1 << 0)
b = (pow(2, N) - 1) - (pow(2, 0 + 1) - 1)
c = b | a
bit_cost = bit ^ c
cost_0 = bin(bit_cost).count("1")

print(int(minruiseki + cost_0))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
right = S[1:N].count("E")
left = 0
min = right

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

        # min -= 1
    # count = S[0:i].count("W") + S[i+1:N].count("E")
    # if min > count:
    #     min = count
print(min)

Submission status: Wrong Answer

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

w_cnt = s.count("W")
e_cnt = s.count("E")

if w_cnt > e_cnt:
   for i in range(int(n/2)+1, 0, -1):
      if i == 0:
         cnt = s.count("E")
         if s[0] == "E":
            cnt = cnt - 1
      elif i == n -1:
         cnt = s.count("W")
         if s[n-1] == "W":
            cnt -= 1
      else: 
         a = s[:i]
         b = s[i+1:]
         a_cnt = a.count("W")
         if a_cnt > min_c: continue
         b_cnt = b.count("E")
         if b_cnt > min_c: continue
         cnt = a_cnt + b_cnt
         if cnt > min_c: continue
      min_c = min(min_c, cnt)
else:
   for i in range(int(n/2)+2, n):
      if i == 0:
         cnt = s.count("E")
         if s[0] == "E":
            cnt = cnt - 1
      elif i == n -1:
         cnt = s.count("W")
         if s[n-1] == "W":
            cnt -= 1
      else: 
         a = s[:i]
         b = s[i+1:]
         a_cnt = a.count("W")
         if a_cnt > min_c: continue
         b_cnt = b.count("E")
         if b_cnt > min_c: continue
         cnt = a_cnt + b_cnt
         if cnt > min_c: continue
      min_c = min(min_c, cnt)

print(min_c)

Submission status: Wrong Answer

Solution code:
#Attention

#ライブラリ
import copy

#入力
N = int(input())
S = list(input())
ans = []
#計算
for i in range(1,N-1,1):
	S_hidari = copy.copy(S[0:i])
	S_migi = copy.copy(S[i+1:N])
	if i == 1:
		ans.append(S_hidari.count('W')-1+S_migi.count('E'))
		break
	if i == N-2:
		ans.append(S_hidari.count('W')+S_migi.count('E')-1)
		break
	ans.append(S_hidari.count('W')+S_migi.count('E'))
	print(S_hidari)
	print(S_hidari.count('W'))
	print(S_migi)
	print(S_migi.count('E'))
	print("-----------------------")

print(min(ans))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()

    E = s[1:]
    j = s[0]
    c = 0
    for i in E:
        if i == 'E':
            c = c + 1
    m = c 

    for i in s:
        if i == 'E':
            c = c - 1
        else:
            c = c + 1
        m = min(m, c)

    print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[:0])["W"] + Counter(st[1:])["E"]
th = Counter(st[:n])["W"] + Counter(st[n+1:])["E"]
previous = st[0]
for i in range(1,n):
    temp = ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E" and i != n):
        temp-=1
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

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

min = N

for i in range(N):
 a = S[0:i].count("W") + S[i+1:N-1].count("E")
 if a < min:
  min = a

print(min)

Submission status: Wrong Answer

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

import os
import sys

def main():
    list_length = int(input())
    result = list_length
    data = list(input())
    for i in range(list_length):
        c = l_count(i, data)
        if c is None:
            continue
        elif result > c:
            result = c
    print(result)

def l_count(i, data):
    if i > 1 and (data[i - 1] != "E" or data[i] != "W"):
        return None
    west = data[:i].count("W")
    east = data[i:].count("E")
    return west + east

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

SUM = 10000000
#1番目は終わり
W_sum = 0
E_sum = S[-(N-1):].count('E')

#両サイドからカウントする
#文字が変化したらカウント
for i in range(1, N):#i番目を選ぶ
    left = S[:i]
    right = S[-(N-(i)):]
    if left[i-1] == 'W':
        W_sum += 1
    if right[0] == 'E':
        E_sum -= 1
    
    sumsum = W_sum + E_sum
    if sumsum < SUM:#更新
        SUM = sumsum

print(SUM)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[:0])["W"] + Counter(st[1:])["E"]
th = Counter(st[:n])["W"] + Counter(st[n+1:])["E"]
previous = st[0]
for i in range(1,n):
    temp = ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "W"):
        temp-=1
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

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

result = 300000

for i in range(1,N):
    count = S.count("E")
    if (S[i-1] == "W" and S[i] == "E") or (S[i-1] == "E" and S[i] == "W"):
        pass
    elif S[i-1] == "W" and S[i] == "W":
        count += 1
    elif S[i-1] == "E" and S[i] == "E":
        count -= 1
        result = count
print(result)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
q = raw_input()

etow = []
wtoe = []

nowe = 0
noew = 0

for a in range(n):
  etow.append(noew)
  wtoe.append(nowe)
  if q[a] == "W":
    nowe += 1
  if q[n - 1 - a] == "E":
    noew += 1

wtoe = wtoe[::-1]
mi = 9999999

print etow
print wtoe

for a in range(n):
  #print etow[a] , wtoe[a]
  if etow[a] + wtoe[a] < mi:
    mi = etow[a] + wtoe[a]
print mi

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[:0])["W"] + Counter(st[1:])["E"]
th = Counter(st[:n])["W"] + Counter(st[n+1:])["E"]
previous = st[0]
for i in range(1,n):
    temp = ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
flag=1
result=S[1:].count("E")
res=result
for i in range(len(S)-1):
    if(S[i] == S[i+1]):
        if(S[i]=="E"):
            res-=1
            flag=1
        else:

            if(flag==1):
                result=min(res,result)
                flag=0
            res+=1
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[1:])["E"]
th = Counter(st[:n])["W"]
previous = st[0]
for i in range(1,n):
    temp =ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    if(temp < ma):
        ma = temp
print(ma)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
st = input()
l = []
stc = Counter(st)
ma = Counter(st[1:])["E"]
th = Counter(st[:n])["W"]
previous = st[0]
for i in range(1,n):
    temp =ma
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    if(temp < ma):
        ma = temp
    if(th-(n-i) > ma):
        break
print(ma)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
q = raw_input()

etow = []
wtoe = []

nowe = 0
noew = 0

for a in range(n):
  etow.append(noew)
  wtoe.append(nowe)
  if q[a] == "W":
    nowe += 1
  if q[n - 1 - a] == "E":
    noew += 1

wtoe = wtoe[::-1]
mi = 99999

#print etow
#print wtoe

for a in range(n):
  #print etow[a] , wtoe[a]
  if etow[a] + wtoe[a] < mi:
    mi = etow[a] + wtoe[a]
print mi

Submission status: Wrong Answer

Solution code:
n=int(input())
x=input()
s=list(x)
 
list=[]
for i in range(n):
    a=0
    l=s[:i]
    a+=l.count("W")
    k=s[i+1:]
    a+=k.count("E")
    list.append(a)
 
f=min(list)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
str = s[1:]
a = 0
for i in str:
  if i == "E":
    a += 1
b = a

for i in range(n-2):
  if str[i] == "W":
    if str[i+1] == "E":
      continue
    else:
      a += 1 
  else:
    if str[i+1] == "E":
      a -= 1
      if b > a:
        b = a 
      else:
        continue
if s[n-2] == "E":
  if s[n-1] == "E":
    if b == a:
      b = b-1

      
print(b)

Submission status: Wrong Answer

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

list=[]
for i in range(n):
    a=0
    l=list[:i]
    a+=l.count("W")
    k=list[i+1:]
    a+=k.count("E")
    list.append(a)

f=min(list)

print(f)

Submission status: Wrong Answer

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

ms = n
for i in range(n):
	c = s[0:i].count('W')
	c += s[i+1:n].count('E')
	if(ms >= c):
		ms = c
	else:
		break

print(ms)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
flag=1
res_prev=1000000
result=S[1:].count("E")
res=result
for i in range(len(S)-1):
    if(S[i] == S[i+1]):
        if(S[i]=="E"):
            res-=1

        else:
            flag=1
            if(flag==1):
                result=min(res,result)
                flag=0
            res+=1
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
min=300000
for i in range(0,n):
    change=0
    l=s[i];
    for j in range(0,i):
        if(s[j]!=s[i]):
            change=change+1
    for j in range(i+1,n):
        if(s[j]==s[i]):
            change=change+1
    if(change<min):
        min=change
print(min)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
flag=1
res_prev=100000
result=S[1:].count("E")
res=result
for i in range(len(S)-1):
    if(S[i] == S[i+1]):
        if(S[i]=="E"):
            res-=1

        else:
            flag=1
            if(flag==1):
                result=min(res,result)
                flag=0
            res+=1
print(result)

Submission status: Wrong Answer

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

import os
import sys

def main():
    list_length = int(input())
    result = list_length
    data = list(input())
    for i in range(list_length):
        c = l_count(i, data)
        if c is None:
            continue
        elif result > c:
            print(i, c)
            result = c
    print(result)

def l_count(i, data):
    if i > 1 and data[i - 1] != "E":
        return None
    west = data[:i].count("W")
    east = data[i:].count("E")
    return west + east

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
total = 0
l_c, r_c = 0,0
r_c = s.count('E')
min = r_c
for i in range(1,n):
    if(s[i-1] == 'W'):
        r_c += 1
    if(s[i] == 'E'):
        r_c -=1
    if(min > r_c):
        min = r_c
print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
str = s[1:]
a = 0
for i in str:
  if i == "E":
    a += 1
b = a

for i in range(n-2):
  if str[i] == "W":
    if str[i+1] == "E":
      continue
    else:
      a += 1 
  else:
    if str[i+1] == "E":
      a -= 1
      if b > a:
        b = a 
      else:
        continue
if s[n-2] == "E":
  if s[n-1] == "E":
    b = b-1
      
print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
f = 0
l = 0
fs = s[: int(n / 2)]
ls = s[int(n / 2) + 1:]
for i in fs:
    if i == "W":
        f += 1

for i in ls:
    if i == "E":
        l += 1

fs = s[: int(n / 2) + 1]
fres = f + l
for i in fs:
    if fs.pop(-1) == "E":
        if fs[-1] == "E":
            break
    elif fs[-1] == "W":
            fres -= 1


ls = s[int(n / 2):]
lres = f + l
for i in ls:
    if ls.pop(0) == "W":
        if ls[0] == "W":
            break
    elif ls[0] == "E":
        lres -= 1


print(min([fres, lres]))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input()
# 左側のWの数と右側のEの数を数える (和が小さいのが答え)
# min = 3 * 10**5
# 毎回list_aとかの中身を計算させているのが良くない
# (一回計算したらわかる話)
list_a_cnt = 0
list_b_cnt = 0
list_a = list(s[0:0])
list_b = list(s[1:])
list_b_cnt = list_b.count('E')
min = list_a_cnt + list_b_cnt
for i in range(N):
    if s[i] == "W":
        list_a_cnt += 1
    elif s[i] == "E":
        list_b_cnt -= 1
    #print(s[0:i],s[i:])
    #print(list_a_cnt,list_b_cnt)
    if list_a_cnt + list_b_cnt < min:
        min = list_a_cnt + list_b_cnt
print(min)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = left + (1 - center)
    right = right + center
    center = s[i]
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)

Submission status: Wrong Answer

Solution code:
import re

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

#print(S)
# pos = [0 for i in range(N)]
# for i in range(N):
#     if(S[i]=="E"):
#         pos[i] = i-1
#     else:
#         pos[i] = i+1
# print(pos)


ini = 0
for i in range(N):
    if S[i] == "E":
        ini += 1
    else:
        break

fin = N
for i in range(N):
    if(S[N-i-1]=="W"):
        fin -=1
    else:
        break

S = S[ini:fin]
#print(S)


N = len(S)
res = N
for i in range(N):
    if i==0:
        string = "W"*N
    else:
        string = "E"*(i-1)+S[i]+"W"*(N-i)
    num = 0
    for j in range(N):
        if string[j]!=S[j]:
            num+=1
    res = min(res,num)
    
print(res)

Submission status: Wrong Answer

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

ans = N*N
tmp = ""

for i in range(N):
    tmp += S[i]
    ct = 0
    if i != 0:
        for j in tmp:
            if j == 'W':
                ct += 1

    for j in range(i+1, N):
        if S[j] == 'E':
            ct += 1
    if i == 0:
        ans = ct
    elif i != 0 and ans > ct:
        ans = ct
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = i - center
    right = right + center
    center = s[i]
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)

Submission status: Wrong Answer

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

r_count = 0

for x in range(N):
    if S[x] == 'E':
        continue
    a = list(S[0:x])
    b = list(S[x + 1: N])
    change_count = (a.count('W') + b.count('E'))
    if change_count == 0:
        r_count = 0
        break
    elif r_count == 0:
        r_count = change_count
    elif r_count > change_count:
        r_count = change_count

print(r_count)

Submission status: Wrong Answer

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

list=[]
for i in range(n):
    a=0
    for j in range(i):
        if s[j]=="W":
            a+=1
    for k in range(n-i-1):
        if s[k+i+1]=="E":
            a+=1
    list.append(a)

f=max(list)

print(f)

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input().strip())
    s = input().strip()

    m = 300000
    right_e = len([x for x in s if x == 'E'])
    left_w = 0
    
    for i, x in enumerate(s):
        if x == 'W':
            left_w += 1
            c = left_w + right_e - 1            
        else:
            right_e -= 1
            c = left_w + right_e + 1
        

        m = min(m, c)

    print(m)


if __name__ == '__main__':
    main()