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: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
count_prev = 300000
i = 0

while i < n:
    count = 0
    front = s[0:i]
    back = s[i+1:n]

    if i > 0:
        count += front.count('W')
    count += back.count('E')

    if count_prev > count:
        count_prev = count
    i += 1

print(count_prev)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())
S = input()
 
c=[]
 
for i in range(0,N):
    if i==0:
        c.append(S[1:].count("E"))
    elif i == N-1:
        c.append(S[0:N-1].count("W"))
    else:
        if S[i-1] == S[i] and S[i] == S[i+1]:
            pass    
        else:
            c.append(S[0:i].count("W") + S[i+1:].count("E")) 

print(min(c))

Submission status: Time Limit Exceeded

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

# numはstartからendまで
def mozisu(text, num):
    ans = 0
    ans += text[:num].count("W")
    ans += text[num+1:].count("E")
    return ans

li = []
start = S.find("W")
end = S.rfind("E")
if end < start:
    print(0)
else:
    for i in range(end - start + 1):
        li.append(mozisu(S, i+start))
        if 0 in li:
            break
    print(min(li))

Submission status: Time Limit Exceeded

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":
        return None
    west = len([d for d in data[:i] if d == "W"])
    east = len([d for d in data[i:] if d == "E"])
    return west + east

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
m = []
for i in range(n):
    list_1 = s[0:i]
    list_2 = s[i+1:n]
    list_1_unique = list((list_1))
    list_2_unique = list((list_2))
    k = 0
    for j in list_1_unique:
        if j == 'W':
            k += 1
    for l in list_2_unique:
        if l == 'E':
            k += 1
    m.append(k)
print(min(m))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(1,N):
    W = S[0:i-1]
    E = S[i:N]
    Wchange = W.count("W")
    Echange = E.count("E")
    total = Wchange + Echange
    lst.append(total)
    i = i+1
print(min(lst))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
min = 10000000000
for i in range(n):
    lead = s[i]
    right = s[:i]
    left = s[i+1:]
    change = right.count('W') + left.count('E')
    if min > change:
        min = change
print(min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
min = 3 * 10 ** 15
for i in range(n):
    tmp = S[0:i].count("W") + S[i+1:n].count("E")
    if min > tmp:
        min = tmp
print(min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
a=300000
for i in range(n):
    left = s[0:i].replace("E","")
    right = s[i + 1:n].replace("W","")
    b = len(left) + len(right)
    if a > b:
        a = b
print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 300001
for i in range(N):
  tmp_count = 0
  s1 = S[0:i]
  s2 = S[i+1:]
  for j in range(len(s1)):
    if s1[j]=='W':
      tmp_count += 1
  for k in range(len(s2)):
    if s2[k]=='E':
      tmp_count += 1
  if count>tmp_count:
    count = tmp_count
print(count)

Submission status: Time Limit Exceeded

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)

print(f)

Submission status: Time Limit Exceeded

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[-1]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
    if(th-(n-i) > min(ma)):
        break
print(min(ma))

Submission status: Time Limit Exceeded

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

    
    count_list.append(count)

print(min(count_list))

Submission status: Time Limit Exceeded

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

# numはstartからendまで
def mozisu(text, num):
    ans = 0
    ans += text[:num].count("W")
    ans += text[num+1:].count("E")
    return ans

li = []
start = S.find("W")
end = S.rfind("E")
if end < start:
    print(0)
else:
    for i in range(end - start + 1):
        li.append(mozisu(S, i+start))
    print(min(li))

Submission status: Time Limit Exceeded

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

for i in range(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: Time Limit Exceeded

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[-1]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
    if(th-(n-i) > min(ma)):
        break
print(min(ma))

Submission status: Time Limit Exceeded

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
    mask = [string[j]!=S[j] for j in range(N)]
    num = sum(mask)
    res = min(res,num)
    
print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())
S = input()
 
c=[]
 
for i in range(0,N):
	c.append(S[0:i].count("W") + S[i+1:].count("E"))
 
print(min(c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
m = []
for i in range(0,n):
    list_1 = s[0:i]
    list_2 = s[i+1:n]
    list_1_unique = list((list_1))
    list_2_unique = list((list_2))
    k = 0
    for j in list_1_unique:
        if j == 'W':
            k += 1
    for l in list_2_unique:
        if l == 'E':
            k += 1
    m.append(k)
print(min(m))

Submission status: Time Limit Exceeded

Solution code:
lis=[]
n=int(input())
saidai = n + 1
lis += input()
for rida in range(n):
    count=0
    for i in range(n):
        if i < rida and lis[i] == "W":
            count += 1
        elif i > rida and lis[i] == "E":
            count += 1
    if count < saidai:
        saidai = count
print(saidai)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
n_list = []

num = 0
num += S[1:].count("E")
n_list.append(num)
for i in range(1, N-2):
    num = 0
    num += S[:i-1].count("W") + S[i+1:].count("E")
    n_list.append(num)
num = 0
num += S[:N-1].count("W")
n_list.append(num)

if (len(n_list) > 0):
    print(min(n_list))
else:
    print(0)

Submission status: Time Limit Exceeded

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

saisyou = N

for i in range(1,N):
    west = S[0:i-1]
    east = S[i:N]
    tmp = west.count("W") + east.count("E")
    if saisyou > tmp:
        saisyou = tmp
print(saisyou)

Submission status: Time Limit Exceeded

Solution code:

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

S1 = []
S2 = []
scorelist = []
for i in range(N):
    S1 = S[0:i]
    S2 = S[i+1:N]
    """print(S1)
    print(S2)"""
    score = 0
    countW = S1.count("W")
    countE = S2.count("E")
    score = countW + countE
    scorelist.append(score)
ans = min(scorelist)
print(ans)

Submission status: Time Limit Exceeded

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=min(list)

print(f)

Submission status: Time Limit Exceeded

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":
        return None
    west = data[:i].count("W")
    east = data[i:].count("E")
    return west + east

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
a=10000000
for i in range(n):
    left = s[0:i]
    right = s[i + 1:n]
    left = left.replace("E", "")
    right = right.replace("W", "")
    b = len(left) + len(right)
    if a > b:
        a = b
print(a)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = input()
ans = 10**6
for i in range(len(s)):
    x = collections.Counter(s[:i])
    y = collections.Counter(s[i+1:len(s)])
    ans = min(ans,x["W"]+y["E"])
print(ans)

Submission status: Time Limit Exceeded

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

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

c=[]

for i in range(0,N):
    if i==0:
        cnt = S[1:].count("E")
        c.append(cnt)
        if cnt == 0:
            break
    elif i == N-1:
        cnt = S[0:N-1].count("W")
        c.append(cnt)
        if cnt == 0:
            break
    else:
        cnt = (S[0:i].count("W") + S[i+1:].count("E"))
        c.append(cnt)
        if cnt == 0:
            break

print(min(c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = list(input())
min = 3 * 10 ** 15
for i in range(n):
    tmp = S[0:i].count("W") + S[i+1:n].count("E")
    if min > tmp:
        min = tmp

print(min)

Submission status: Time Limit Exceeded

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[::-1][0]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
    if(th-(n-i) > min(ma)):
        break
print(min(ma))

Submission status: Time Limit Exceeded

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)

global cost_N,min
cost_N = np.zeros(N)
def cost(i):
    global cost_N, min
    if i == 0:
        a = bit & (1 << i)
        b = (pow(2, N) - 1) - (pow(2, i + 1) - 1)
        c = b | a
        bit_cost = bit ^ c
        cost_N[0] = bin(bit_cost).count("1")
        return cost_N[0]
    else:
        cur = s_bit[i]
        bef = s_bit[i-1]
        cost_N[i] = cost(i-1) - (1^cur) + bef
        return cost_N[i]

cost(N-1)
print(int(min(cost_N)))

Submission status: Time Limit Exceeded

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

tmin = 0
for i in range(0, n):
    t = 0
    for j in range(0, n):
        if j == i:
            continue
        sd = "E" if j < i else "W"
        if s[j] != sd:
             t += 1
    if t < tmin or i == 0:
         tmin = t
print(tmin)

Submission status: Time Limit Exceeded

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[::-1][0]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
    if(th-(n-1) > min(ma)):
        break
print(min(ma))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range (1,N):
    if S[i] == "W":
        continue
    count = S[0:i].count("W") + S[i+1:N].count("E")
    if min > count:
        min = count
print(min)

Submission status: Time Limit Exceeded

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[::-1][0]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
    if(temp - (n-i) > min(ma)):
        break
print(min(ma))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s= input()

D = N
for i in range(N):
    L,R = s[:i],s[i+1:]
    n1,n2 = Counter(L),Counter(R)
    num = n1["W"] + n2["E"]
    if num < D:
        D = num
print(D)

Submission status: Time Limit Exceeded

Solution code:
#Attention

#入力
N = int(input())
S = list(input())
ans = []
#計算
for i in range(N):
	leader = i
	counter = 0
	for j in range(0,leader,1):
		if S[j] == "W":
			counter += 1
	for k in range(leader+1,N,1):
		if S[k] == "E":
			counter += 1
	ans.append(counter)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
ans = n
for i in range(0, n):
	s1 = s[:i]
	s2 = s[i+1:]
	a = s1.count("W") + s2.count("E")
	if a < ans:
		ans = a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()
    m = 3*10**5
    l = []

    for i in s:
        if i == 'E':
            l.append(1)
        else:
            l.append(0)

    for i, x in enumerate(s):
        W = l[:i]
        E = l[i+1:]
        m = min(len(W) - sum(W) + sum(E), m)

    print(m)

Submission status: Time Limit Exceeded

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

# numは0からnまで
def mozisu(text, num):
    ans = 0
    ans += text[:num].count("W")
    ans += text[num+1:].count("E")
    return ans

li = []
for i in range(N):
    li.append(mozisu(S, i))

print(min(li))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
d = []
for i in range(0,n):
    list_1 = s[0:i]
    list_2 = s[i+1:n]
    a = list_1.count('W')
    b = list_2.count('E')
    c = a+b
    d.append(c)
print(min(d))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import collections

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()

people = []

for i in range(N):
    people.append(S[i])

tmp = collections.Counter(people[1:])
tmp2 = tmp['E']
tmp3 = collections.Counter(people[:N-1])
tmp4 = tmp['W']
minv = min(tmp2, tmp4)

for i in range(1, N-2):
    front = people[:i+1]
    tail = people[i+2:]
    tmp4 = collections.Counter(front)['W'] + collections.Counter(tail)['E']
    if tmp4 < minv:
        minv = tmp4

print(minv)

Submission status: Time Limit Exceeded

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

min_changed_num = sum(s[1:n])

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

print(min_changed_num)

Submission status: Time Limit Exceeded

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

changes = []
for leader in range(1, n+1):
    change = 0
    change += s[:leader-1].count("W")
    change += s[leader:].count("E")

    changes.append(change)

print(min(changes))

Submission status: Time Limit Exceeded

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

r_count = 0

for x in range(N):   
    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: Time Limit Exceeded

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

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

    if sumsum < SUM:#更新
        SUM = sumsum

print(SUM)

Submission status: Time Limit Exceeded

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[::-1][0]
    if(previous == "W"):
        temp+=1
    previous = st[i]
    if(st[i] == "E"):
        temp-=1
    ma.append(temp)
print(min(ma))

Submission status: Time Limit Exceeded

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

S1 = []
S2 = []
scorelist = []
for i in range(N):
    S1 = S[0:i]
    S2 = S[i+1:N]
    """print(S1)
    print(S2)"""
    score = 0
    for j in range(i):
        if S1[j] == "W":
            score += 1
    for k in range(N-i-1):
        if S2[k] == "E":
            score += 1
    scorelist.append(score)
ans = min(scorelist)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
list = [str(S[i]) for i in range(N)]

result = 300000

def cal(n):
    count = 0
    count = list[:n].count("W") + list[n:].count("E")
    return count

for i in range(N):
    if result > cal(i):
        result = cal(i)
    
print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = list(input())
r = 3 * 10**5 + 1
MAX = 'E' if s.count('E') < s.count('W') else 'W'
for l in range(n):
  sm = 0
  if s[l] == MAX: continue
  for m in range(n):
    if m < l and s[m] == 'W': sm += 1
    if l < m and s[m] == 'E': sm += 1
  r = min(r, sm)

print(r)

Submission status: Time Limit Exceeded

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

changes = []
for leader in range(1, n-1):
    change = 0
    change += s[:leader-1].count("W")
    change += s[leader:].count("E")

    changes.append(change)

print(min(changes))

Submission status: Time Limit Exceeded

Solution code:

def abc098_c():
    import numpy as np
    n = int(input())
    s = input()
    count_min = n
    w_num = s.count("W")
    for i in range(n):
        w_left = s[:i].count("W")
        e_right = n - w_num - (i - w_left) - (s[i] == "E")
        count = w_left + e_right
        if count == 0:
            return 0
        if count_min > count:
            count_min = count

    return count_min


print(abc098_c())

Submission status: Time Limit Exceeded

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

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

c=[]

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

print(min(c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s = list(s)
count = 0
count_up = []

for i_all in range(n):
    leader = s[i_all]
    if i_all == 0:
        for i_first in range(1,n):
            if s[i_first] == "E":
                count += 1
    elif i_all == n-1:
        for i_last in range(n-1):
            if s[i_last] == "W":
                count += 1
                if count > max(count_up):
                    continue
    else:
        for i_a in range(i_all):
            if s[i_a] == "W":
                count +=1
                if count > max(count_up):
                    continue
        for i_b in range(i_all+1,n):
            if s[i_b] == "E":
                count += 1
                if count > max(count_up):
                    continue
    count_up.append(count)
    count = 0
print(min(count_up))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s = list(s)
count = 0
count_up = []

for i_all in range(n):
    leader = s[i_all]
    if i_all == 0:
        for i_first in range(1,n):
            if s[i_first] == "E":
                count += 1
    elif i_all == n-1:
        for i_last in range(n-1):
            if s[i_last] == "W":
                count += 1
        if count > max(count_up):
            continue
    else:
        for i_a in range(i_all):
            if s[i_a] == "W":
                count +=1
        for i_b in range(i_all+1,n):
            if s[i_b] == "E":
                count += 1
        if count > max(count_up):
            continue
    count_up.append(count)
    count = 0
print(min(count_up))

Submission status: Time Limit Exceeded

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

r_count = 0

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

print(r_count)

Submission status: Time Limit Exceeded

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


total = 3 * 10 ** 5

for i in range(n):
    total = min(total,(s[:i].count("W")+s[i:].count("E")))

print(total)

Submission status: Time Limit Exceeded

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

changes = []
for leader in range(n-1):
    change = 0
    change += s[:leader].count("W")
    change += s[leader:].count("E")

    changes.append(change)

print(min(changes))

Submission status: Time Limit Exceeded

Solution code:
def abc098_c():
    import numpy as np
    n = int(input())
    s = input()
    counts = np.zeros(n)
    w_num = s.count("W")
    for i in range(n):
        w_left = s[:i].count("W")
        e_right = n - w_num - (i - w_left) - (s[i] == "E")
        counts[i] = w_left + e_right

    return int(min(counts))


print(abc098_c())

Submission status: Time Limit Exceeded

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

for i in range(n):
	west = s[:i-1]
	east = s[i+1:]
	change = west.count("W") + east.count("E")
	cmin.append(change)

print(min(cmin))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
mn = 3*(10**5)
for i in range(n):
    if i == 0:
        es = list(s[1:])
        if mn > es.count("E"):
            mn = es.count("E")
    elif i == n:
        ws = list(s[:n])
        if mn > ws.count("W"):
            mn = ws.count("W")
    else:
        ws = list(s[:i])
        es = list(s[i+1:])
        if mn > (ws.count("W") + es.count("E")):
            mn = (ws.count("W") + es.count("E"))
print(mn)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
# 左側のWの数と右側のEの数を数える
min = 3 * 10**5
for i in range(N):
    list_a = list(s[0:i])
    list_b = list(s[i:])
    #print(list_a, list_b)
    if list_a.count('W')+list_b.count('E') < min:
        min = list_a.count('W')+list_b.count('E')
print(min)

Submission status: Time Limit Exceeded

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

# numは0からnまで
def mozisu(text, num):
    ans = 0
    for i in text[:num]:
        if i == "W":
            ans += 1
    for i in text[num+1:]:
        if i == "E":
            ans += 1
    return ans

li = []
for i in range(N):
    li.append(mozisu(S, i))

print(min(li))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 1000000
for i in range(0,n):
    s1 = s[:i]
    s2 = s[i+1:]
    c = s1.count("W") + s2.count("E")
    ans = min(ans, c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = input()
min_people = n - 1

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


for i in range(n):
  people = we_counter(i)
  if people < min_people:
    min_people = people

print(min_people)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
l = []
r = []
ans = s.count("E")
nagasa = len(s)
for i in range(1, nagasa):
    l = s[0:i]
    r = s[i+1:nagasa+1]
    tmp = l.count("W") + r.count("E")
    if ans > tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
list = [str(S[i]) for i in range(N)]

result = []

def cal(n):
    count = 0
    count = list[:n].count("W") + list[n:].count("E")
    return count

for i in range(N):
    result.append(cal(i))
    
# print(result)
print(min(result))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
min_change = n-1
for x in range(n):
    change = 0
    for y in range(n):
        if x > y:
            if s[y] == 'E': continue
            change += 1
        elif x < y:
            if s[y] == 'W': continue
            change += 1
    if min_change > change: min_change = change
print(min_change)

Submission status: Time Limit Exceeded

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

count=0
min=1000000

min=s.count("E")

for i in range(N):
    a=s[:i+1]
    b=s[i+1:]
    count+=a.count("W")
    count+=b.count("E")
    if min>count:
        min=count
    count=0

print(min)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()
    m = 3*10**5

    for i, x in enumerate(s):
        W = s[:i]
        E = s[i+1:]

        m = min(m, W.count('W') + E.count('E'))

    print(m)

Submission status: Time Limit Exceeded

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

D = N
for i in range(N):
    temp = 0
    for j in range (N):
        if (i < j) and (s[j] == "E" ) or  (i > j) and (s[j] == "W" ) :
            temp += 1
    if temp < D:
        D = temp
print(D)

Submission status: Time Limit Exceeded

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

ans = 3*10^5

for i in range(N):
    n = 0

    n += S[:i].count("W")
    n += S[i+1:].count("E")

    if ans > n:
        ans = n

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()
anss = [] 
for i in range(N):
 chE = S[0:i].count("W")
 chW = S[i+1:N].count("E")
 anss.append(chW+chE)
 
print(min(anss))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
min = float("inf")

for i in range(N):
    count = 0
    for j, s in enumerate(S):
        if j < i and s == "W":
            count +=1
        if j > i and s == "E":
            count +=1

    if min >  count:
        min = count
print(min)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
Slist=list(S)
c=[]
for i in range(0,N-1):
    slice=S[0:i]
    slice=S[i+1:N]
    a=S[0:i].count('W')
    b=S[i+1:N].count('E')
    c.append(a+b)
print(min(c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
min_change = n-1
for x in range(n):
    change = 0
    for y in range(n):
        if x > y:
            if s[y] == 'E':
                continue
            change += 1
        elif x < y:
            if s[y] == 'W':
                continue
            change += 1
    if min_change > change: min_change = change

print(min_change)

Submission status: Time Limit Exceeded

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

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

s1 = list(s)
s2 = list(s)

# print(s1)
# print(s2)
# print('')

numlist = []
for i in range(n):
    if i > 0:
        for j in range(i):
            s2[j] = 'E'
    for j in range(i+1,n):
        s2[j] = 'W'

    temp = 0
    for j in range(n):
        if s1[j] != s2[j]:
            temp += 1

    numlist.append(temp)

    # print(s1)
    # print(s2)
    # print('')

# 出力
print("{}".format(min(numlist)))

Submission status: Time Limit Exceeded

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)

min = N
for i in range(N):
    a = bit & (1 << i)
    b = (pow(2,N) - 1) - (pow(2,i+1) - 1)
    c = b | a
    cost = bit ^ c
    actual_cost = bin(cost).count("1")
    if actual_cost < min:
        min = actual_cost

print(min)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = list(input())
r = 3 * 10**5 + 1
for l in range(n):
  sm = 0
  for m in range(n):
    if m < l and s[m] == 'W': sm += 1
    if l < m and s[m] == 'E': sm += 1
  r = min(r, sm)

print(r)

Submission status: Time Limit Exceeded

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

r_count_ary = []

for x in range(N):   
    a = list(S[0:x])
    b = list(S[x + 1: N])

    change_count = (a.count('W') + b.count('E'))
    
    r_count_ary.append(change_count)

print(min(r_count_ary))

Submission status: Time Limit Exceeded

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

n_list = []

for i in range(N):
    num = 0
    for j in range(N):
        if (j == i):
            continue
        if (j < i and S[j] == "W"):
            num += 1
        elif (j > i and S[j] == "E"):
            num += 1
    n_list.append(num)

if (len(n_list) > 0):
    print(min(n_list))
else:
    print(0)