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=input()
min=300000
for i in range(n):
    left=s[:i:].count("W")
    right=s[i+1:].count("E")
    if min>left+right:
        min=left+right
print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
cost = [0 for _ in range(n + 1)]
lin = 0
rin = n
for i in range(n + 1):
	cost[i] = s[0:i].count('W') + s[i + 1:n].count('E')
print(min(cost))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s = [s[i:i+1] for i in range(n)]
mcost = 10 ** 9
for i in range(n):
  cost = s[0:i].count('W')
  cost += s[i + 1:n].count('E')
  if mcost > cost:
    mcost = cost
print(mcost)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
pp = list(input())
cnt = 0
lis = []
for i in range(n):
    for j in range(i):
        if pp[j] == "W":
            cnt += 1
    for k in range(i+1,n):
        if pp[k] =="E":
            cnt += 1
    lis.append(cnt) 
    cnt = 0
print(min(lis))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input();a=input();print(min(a[:s].count("W")+a[s+1:].count("E")for s in range(len(a))))

Submission status: Time Limit Exceeded

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

l = []

for i in range(N):
    l.append((S[:i].count('W')) + (S[i+1:].count('E')))

print(min(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
slist = list(S)
MIN=N
for i in range(N):
    change=0
    change+=slist[:i].count("W")
    change+=slist[i+1:].count("E")
    MIN=min(MIN,change)
print(MIN)

Submission status: Time Limit Exceeded

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

for i in range(n):
    L = s[:i]
    R = s[i+1:]
    turn = L.count("W") + R.count("E")
    if turn < ans:
        ans = turn

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    list.append(s[i])

for j in range(n):
    L = list[:j]
    R = list[j+1:]
    turn = L.count("W") + R.count("E")
    if turn < ans:
        ans = turn

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
line=str(input())
line=line.replace('E','0')
line=line.replace('W','1')
line=list(map(int,line))
v=n
for i in range(n):
  a1=line[0:i]
  a2=line[i+1:n]
  q=a1.count(1)+a2.count(0)
  if q<v:
    v=q
print(v)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
line=str(input())
line=line.replace('E','0')
line=line.replace('W','1')
line=list(map(int,line))
def turn_e(x):
  count=0
  for i in range(x):
    if line[i]==1:
      count+=1
  return count
def turn_w(x):
  count=0
  for i in range(x+1,n):
    if line[i]==0:
      count+=1
  return count
v=n
for i in range(n):
  if (turn_e(i)+turn_w(i))<v:
    v=turn_e(i)+turn_w(i)
print(v)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
line=list(str(input()))
def turn_e(x):
  count=0
  for i in range(x):
    if line[i]=='W':
      count+=1
  return count
def turn_w(x):
  count=0
  for i in range(x+1,n):
    if line[i]=='E':
      count+=1
  return count
v=n
for i in range(n):
  if (turn_e(i)+turn_w(i))<v:
    v=turn_e(i)+turn_w(i)
print(v)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
x = 10000000
for i in range(n):
  a = s[:i]
  b = s[i+1:]
  c = a.count("W")+b.count("E")
  if x>c:
    x = c
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
big_num = 10 ** 6

for i in range(n):
    west = s[:i].count("W")
    east = s[i+1:].count("E")
    if big_num > west + east:
        big_num = west + east
        
print(big_num)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

s=' '+input()+' '
ans=n
for i in range(1,n+1):
    s1=s[:i]
    s2=s[i+1:]
    sum_count=s1.count('W')+s2.count('E')
    if ans>=sum_count:
        ans=sum_count
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=str(input())
b=[]
for i in range(N):
    L=a[:i-1]
    R=a[i-1:]
    b.append(L.count('W')+R.count('E'))
b.sort()
print(b[0])

Submission status: Time Limit Exceeded

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

ans = n
for i in range(n):
  ans = min(ans, s[0:i].count('W') + s[i + 1:n].count('E'))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# TODO:累積和を使った手法

int_n = int(input())
str_s = input()

changes = 999999

for i in range(int_n):
    member_left = str_s[:i]
    member_right = str_s[i + 1:]
    # print(i)
    # print("left:" + member_left, "right:" + member_right)

    this_change = (member_left.count("W") + member_right.count("E"))

    changes = this_change if (changes >= this_change) else changes

print(changes)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
min=3*100000

for i in range(len(s)):
    left=s[0:i]
    right=s[i::]
    leftcount=left.count('W')
    rightcount=right.count('E')
    if leftcount+rightcount<min:
        min=leftcount+rightcount

print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S += "x"
cnt = []
for i in range(N):
    tmp = 0
    for j in range(i):
        if S[j] == "W":
            tmp += 1
    for j in range(i+1, N):
        if S[j+1] == "E":
            tmp += 1
    cnt.append(tmp)

print(min(cnt))

Submission status: Time Limit Exceeded

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

SL = []
TL = []
for i in range(len(S)):
    SL.append(S[i])
    TL.append(S[i])

A = []

for i in range(len(SL)):
    for j in range(len(SL)):
        if j < i:
            TL[j] = "E"
        elif j > i:
            TL[j] = "W"
    count = 0
    for k in range(len(S)):
        if TL[k] != SL[k]:
            count += 1
    A.append(count)

print(min(A))

Submission status: Time Limit Exceeded

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

for x in range(0,N):
    a = S[:x]
    if not x == N-1:
        b = S[x+1:]
    anum = a.count('W')
    bnum = b.count('E')
    num = anum + bnum
    answer = min(answer,num)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
List = [0 for x in range(0,N)]
answer = N

for x in range(0,N):
    a = S[:x]
    if not x == N-1:
        b = S[x+1:]
    anum = a.count('W')
    bnum = b.count('E')
    num = anum + bnum
    answer = min(answer,num)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = list(input())
m = []
n = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = 0
for i in range(1, N):
    ls = sum(S[:i-1])
    rs = sum(S[i+1:])
    n.append(i-1-ls+rs)
print(min(n))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = list(input())
m = []
for i in range(N):
    if S[i] == 'E':
        S[i] = 1
    else:
        S[i] = -1
for i in range(1, N):
    l = S[:i-1].count(-1)
    r = S[i+1:].count(1)
    m.append(l+r)
print(min(m))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
num_s=[]
value=[]
for f_s in s:
    if(f_s=="E"):
        num_s.append(0)
    else:
        num_s.append(1)
for n in range(len(s)):
    value.append(sum(num_s[:n])+abs(sum(num_s[n:])-len(num_s[n:])))
print(min(value))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    S = lines.pop(0)
    RS = S[::-1]
    S = 'x' + S
    RS = 'x' + RS
    slist = []
    rslist = []
    ss = 0
    rss = 0
    for i in range(N):
        if S[i] == 'W':
            ss += 1
        if RS[i] == 'E':
            rss += 1
        slist.append(ss)
        rslist.insert(0,rss)
    #print(S)
    #print(RS)
    #print(list( zip(slist, rslist)))
    print(min([s + r for s, r in zip(slist, rslist)]))

#
# main
#
# 2. use stdin

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 3*10**5+1
res = 0
for i in range(1,n-1):
    l1 = s[:i-1]
    l2 = s[i+1:]
    res = l1.count("W")+l2.count("E")
    ans = min(ans,res)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
res = []
for i in range(1,n-1):
    l1 = s[:i-1]
    l2 = s[i+1:]
    res.append(l1.count("W")+l2.count("E"))
print(min(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
east_side = list(input())
west_side = []
ans = []
for i in range(len(east_side)):
    WE_sum = east_side.count("E") + west_side.count("W")
    ans.append(WE_sum)
    west_side.append(east_side[0])
    east_side.pop(0)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
east_side = list(input())
west_side = []
ans = 300000
for i in range(len(east_side)):
    WE_sum = east_side.count("E") + west_side.count("W")
    if(WE_sum < ans):
        ans = WE_sum
    west_side.append(east_side[0])
    east_side.pop(0)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
s = np.array([True if i=='E' else False for i in input()])
w = 0
e = np.sum(s[1:])
ans = w+e
for i in range(1,n):
  w = w + (not s[i-1])
  e = e - s[i]
  ans = min(ans,w+e)
print(ans)

Submission status: Time Limit Exceeded

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

cnt_min = N

for i in range(N):
    L = S[:i]
    R = S[i+1:]
    cnt = L.count('W') + R.count('E')
    cnt_min = min(cnt_min, cnt)

print(cnt_min)

Submission status: Time Limit Exceeded

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

cnt_min = 100

for i in range(N):
    L = S[:i]
    R = S[i+1:]
    cnt = L.count('W') + R.count('E')
    cnt_min = min(cnt_min, cnt)

print(cnt_min)

Submission status: Time Limit Exceeded

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

s = []
for S_ in S:
    if S_ == 'W':
        s.append(0)
    else:
        s.append(1)

ans = N
s_total = sum(s)
for i,s_ in enumerate(s):
    diff = i - sum(s[:i])*2 - s_ + s_total
    if ans > diff:
        ans = diff

print(ans)

Submission status: Time Limit Exceeded

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

s = []
for S_ in S:
    if S_ == 'W':
        s.append(0)
    else:
        s.append(1)

ans = N
for i in range(len(s)):
    diff = i - sum(s[:i]) + sum(s[i+1:])
    if ans > diff:
        ans = diff

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
R = [S[:i].count('W') + S[i:].count('E') for i in range(N)]

print(min(R))

Submission status: Time Limit Exceeded

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

for i in range(N):
    R.append(S[:i].count('W') + S[i:].count('E'))

print(min(R))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    s = input()
    line = [0 for _ in range(n)]

    for i, c in enumerate(s):
        if c == 'E':
            line = list(map(lambda x: x[1]+1 if x[0] < i else x[1], enumerate(line)))
            
        elif c == 'W':
            line = list(map(lambda x: x[1] + 1 if x[0] > i else x[1], enumerate(line)))
    
    mini = min(line)
    print(mini)
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
numS = [0 for i in range(N)]
for i in range(N):
    if S[i] == 'E':
        numS[i] = 0
    else:
        numS[i] = 1
# print(numS)
minS = N
for i in range(N):
    numT = [0 for j in range(i)] + [numS[i]] + [1 for j in range(i+1,N)]
    # print(numT)
    minS = min(minS,sum([abs(numT[i]-numS[i]) for i in range(N)]))

print(minS)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = list(input())
min = n+1
for i in range(0, n):
    ans = S[:i].count('W')
    ans2 = S[i:].count('E')
    answer = ans + ans2
    if(answer < min):
        min = answer
print(min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input()
m = n
for i in range(n):
    if m > a[:i].count("W")+a[i:].count("E"):
        m = a[:i].count("W")+a[i:].count("E")
print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list(input())
ans = [0]*(N)
for i in range(N):
    L = []
    R = []
    if (i >= 1) and (i <= N-2):
        L = s[:i]
        R = s[i+1:]
    elif (i == 0):
        R = s[1:]
    else:
        L = s[:N-1]
    ans[i] = L.count('W') + R.count('E')

print(min(ans))

Submission status: Time Limit Exceeded

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

cnt = float('inf')
for i in range(N):
    W = S[:i].count('W')
    E = S[i + 1:].count('E')
    cnt = min(E + W, cnt)
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=[]
for i in range(1,n):
    w=s[:i-1]
    e=s[i:]
    wc=w.count('W')
    ec=e.count('E')
    cnt.append(wc+ec)

print(min(cnt))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=[]
for i in range(n):
  x=s[:i].count('W')+s[i+1:].count('E')
  l.append(x)
print(min(l))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
l = [i for i in S]
ew = [0]
ans = min(l.count("W"),l.count("E"))

i = 0
while True:
    num = S.find("EW",i+1)
    if num != -1:
      ew.append(num)
      i = num
    else:
      break
      
for i in ew:
  ans = min(ans,l[:i+1].count("W") + l[i+1:].count("E"))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
l = [i for i in S]
ans = min(l.count("W"),l.count("E"))

for i in range(N):
  a = S.find("EW",i)+1
  if a == -1:
    break
  else:
    ans = min(ans,l[:a].count("W") + l[a:].count("E"))

print(ans)

Submission status: Time Limit Exceeded

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


ans = 4000000
for l in range(N):#Leader
    changecount = 0
    for i in range(N):
        if(i<l and S[i] == "W") or (i>l and S[i] == "E"):
            changecount+=1
    ans = min(ans,changecount)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(input())
sumC = []

for i in range(n):
    countW = 0
    countE = 0
    for j in range(0, i):
        if A[j] == 'W':
            countW += 1
    for k in range(i + 1, n):
        if A[k] == 'E':
            countE += 1
    sumC.append(countW + countE)

print(min(sumC))

Submission status: Time Limit Exceeded

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

output=min(S[1:].count("E"),S[:N-1].count("W"))

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [1 if x == 'W' else 0 for x in list(input())]
print(min([sum(s[:i]) + (n-i-1) - sum(s[i+1:]) for i in range(n)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = []
for i in range(N):
  cnt = S[0:i].count('W')
  cnt += S[i+1:N+1].count('E')
  ans.append(cnt)
print(min(ans))

Submission status: Time Limit Exceeded

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

l = len(s)
ans = l
for i in range(l):
  l_we = s[0:i] if(i >= 0)else None
  l_ea = s[i+1:l] if(i+1 <= l) else None
  tmp = 0
  tmp += l_we.count('W')
  tmp += l_ea.count('E')
  ans = min(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = list(input())
cr = []
for i in range(a):
    count = 0
    count += b[0:i].count("W")
    count += b[i+1:a].count("E")
    cr.append(count)
print(min(cr))

Submission status: Time Limit Exceeded

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

for i in range(N):
    left = S[0:i]
    right = S[i+1:N]
    count = left.count('W') + right.count('E')
    if ans > count:
        ans = count
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
we = list(S)
i = 0
min = N
while i < N:
  west = we[0:i]
  east = we[i+1:N]
  wcount = west.count("W")
  ecount = east.count("E")
  if min >= wcount+ecount:
    min = wcount+ecount
  i+=1
print(min)

Submission status: Time Limit Exceeded

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

score = N + 1
a = [S[:i].count('W') + S[i+1:].count('E') for i in range(N)]
print(min(a))

Submission status: Time Limit Exceeded

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

score = N + 1
for i in range(N):
    l = S[:i]
    r = S[i+1:]
    score = min(score, l.count('W') + r.count('E'))

print(score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
for i, s in enumerate(S[:]):
    if s == 'W':
        S[i] = 0
    else:
        S[i] = 1

ans = N
for i in range(N):
    left = S[:i]
    right = S[i + 1:]
    ans = min(ans, len(left) - sum(left) + sum(right) )
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = N
for i in range(N):
    left = S[:i]
    right = S[i + 1:]
    if left.count('W') + right.count('E') < ans:
        ans = left.count('W') + right.count('E')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
S = list(input())
ans = []

for i in range(N):
  A = S[:i].count('W') + S[i+1:].count('E')
  if A == 0:
    print(0)
    sys.exit()
  else:
    ans.append(A)
print(min(ans))

Submission status: Time Limit Exceeded

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

for i in range(N):
  ans.append(S[:i].count('W') + S[i:].count('E'))
  
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = n
for i in range(n):
    if i == 0:
        nin = s[1:n].count("E")
    elif i == n - 1:
        nin = s[0:n-1].count("W")
    else:
        nin = s[0:i].count("W") + s[i+1:n].count("E")
    if nin < ans:
        ans = nin
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = int(input().replace('W', '1').replace('E', '0'), 2)
print(min([bin(S ^ 2 ** i - 1).count('1') for i in range(N + 1)]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = float('inf')
for i in range(n):
    tmp = s[:i].count('W') + s[i+1:].count('E')
    ans = min(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input().split()[0])
min = N

for i in range(N):
  cnt = 0
  for j in range(N):
    if j < i and S[j] == 'W':
      cnt += 1
    if i < j and S[j] == 'E':
      cnt += 1
  if min > cnt: min = cnt 

print(min)

Submission status: Time Limit Exceeded

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

res = n

for i in range(n):
    if i == 0:
        res = min(res, sum([e != "W" for e in s[1:]]))
    elif i == n:
        res = min(res, sum([e != "E" for e in s[:i]]))
    else:
        f = sum([e != "E" for e in s[:i]])
        b = sum([e != "W" for e in s[i+1:]])
        res = min(res, f+b)

print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
s1=[]
s2=[]
for i in s:
    if i=='W':
        s1.append(0)
    else:
        s1.append(1)
#print(s1)
for i in range(n):
    tmp1=i-sum(s1[0:i])
    tmp2=abs(0-sum(s1[i+1:n]))
    #print("tmp1:{} tmp2:{}".format(tmp1,tmp2))
    s2.append(tmp1+tmp2)
print(min(s2))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=n
for i in range(n):
    cntE = s[:i].count('W')
    cntW = s[i+1:].count('E')
    cnt = min(cnt,cntE+cntW)
print(cnt)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(N):
    ans.append(S[:i].count('W') + S[i+1:].count('E'))

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(input())
ANS = []
L = ["-"] + L + ["-"]
for i in range(1,N+1) :
    p = L[(i+1):].count("E")
    q = L[:i].count("W")
    ANS.append(p+q)
print(min(ANS))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
num_E = []
num_W = []
num_All = []

for i in range(N):
  num_E.append(S[i+1:].count('E'))
  num_W.append(S[:i].count('W'))

num_All = [x + y for (x, y) in zip(num_E, num_W)]
print(min(num_All))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
S = S.replace('W', '1')
S = S.replace('E', '0')
S = list(map(int, list(S)))
ans = min([ sum(S[:i]) + len(S[i+1:]) - sum(S[i+1:]) for i in range(N) ])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = min([ S[:i].count('W') + S[i+1:].count('E')  for i in range(N) ])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = []
for i in range(N):
    S_s = sum([ 1 for x in S[:i] if x == 'W' ])
    S_e = sum([ 1 for x in S[i+1:] if x == 'E']) 
    ans.append(S_s+S_e)
print(min(ans))

Submission status: Time Limit Exceeded

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

ans = []
for i in range(N):
    count = 0
    for j in range(N):
        if i > j:
            if S[j] == 'W':
                count += 1
        elif i < j: 
            if S[j] == 'E':
                count +=1
        else:
            pass
    ans.append(count)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = N
for i in range(N):
    x = S[:i].count('W') + S[i + 1:].count('E')
    if x < ans:
        ans = x
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    if i == 0:
        East = []
    else:
        East = S[:i]

    if i == N:
        West = []
    else:
        West = S[(i+1):]
    num.append(East.count("W")+West.count("E"))
print(min(num))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
l = []
for i in range(n):
  eastern = list(s[:i])
  western = list(s[i+1:])
  #print(eastern)
  #print(western)
  nume = eastern.count('W')
  numw = western.count('E')
  #print(nume + numw)
  l.append(nume + numw)
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=n
for i in range(n):
  x=(s[0:i].count('W')+s[i+1:n].count('E'))
  if l>x:l=x
print(l)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
l=[]
for i in range(n):
  l.append(s[0:i].count('W')+s[i:n].count('E'))
print(min(l))

Submission status: Time Limit Exceeded

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

minc = 100000000

for i in range(len(s)):
  minc = min(minc,(s[0:i].count('W')+s[i:].count('E')))

print(minc)

Submission status: Time Limit Exceeded

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

minc = 100000000

for i in range(len(s)):
  left_wrong = s[0:i].count('W')
  right_wrong = s[i:].count('E')
  minc = min(minc,(left_wrong+right_wrong))

print(minc)

Submission status: Time Limit Exceeded

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

c = s.count("W")

mi = n
for i in range(n-1):
    he = 0
    for j in range(i,n):
        if s[j] == "W":
            he += 1
    a = c - he
    b = (n - 1 - i) + 1 - he
    if s[i] == "E":
        b -= 1
    x = a + b
    if mi > x:
        mi = x
print(mi)

Submission status: Time Limit Exceeded

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

mi = n
for i in range(n):
    c = 0
    for j in range(n):
        if j < i:
            if s[j] == "W":
                c += 1
        if j > i:
            if s[j] == "E":
                c += 1
    if mi > c:
        mi = c
print(mi)

Submission status: Time Limit Exceeded

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

mi = n
for i in range(n):
    c = s[:i].count("W") + s[i+1:].count("E")
    if c < mi:
        mi = c

print(mi)

Submission status: Time Limit Exceeded

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

m = n

for i in range(n):
	t = 0
	for j in range(n):
		if (j<i and s[j]=="W") or (j>i and s[j]=="E"):
			t += 1
		if t>m:
			break

	m = min(m,t)
print(m)

Submission status: Time Limit Exceeded

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

m = n

for i in range(n):
	t = 0
	for j in range(n):
		if (j<i and s[j]=="W") or (j>i and s[j]=="E"):
			t += 1
	m = min(m,t)
print(m)

Submission status: Time Limit Exceeded

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

for i in range(n):
    w_to_e = s[0:i].count('W')
    e_to_w = s[i+1:n].count('E')
    if w_to_e + e_to_w < ans:
        ans = w_to_e + e_to_w
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#encoding utf-8

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

reverse = 3*10**5+1
for i in range(n):
    if i == 0:
        point = s[i+1:].count("E")
    elif i == n-1:
        point = s[:i-1].count("W")
    else:
        point = s[i+1:].count("E")+s[:i].count("W")
    # print(point)
    reverse = min(point, reverse)

print(reverse)

Submission status: Time Limit Exceeded

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

cnt = []
count = 0

for i in range(len(S)):
    count = 0
    for j in range(len(S)):
        if i > j and S[j] == "W":
            count += 1
        if i < j and S[j] == "E":
            count += 1
    cnt.append(count)
print(min(cnt))

Submission status: Time Limit Exceeded

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

m = n
for i in range(n):
    c = s[0:i].count("W") + s[i+1:n].count("E")
    if c < m:
        m = c

print(m)

Submission status: Time Limit Exceeded

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

m = n
for i in range(n):
    c = 0
    for j in range(n):
        if j < i:
            if s[j] == "W":
                c += 1
        if i < j:
            if s[j] == "E":
                c += 1
    if c < m:
        m = c

print(m)

Submission status: Time Limit Exceeded

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

a=0
min=300100

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = float("inf")
for i in range(n):
    move = 0
    for j in range(n):
        if j < i and s[j] == "W":
            move += 1
        elif j > i and s[j] == "E":
            move += 1
    ans = min(ans, move)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 3 * 10**5
if S[0] =='W':
    left = 1
else:
    left = 0
for index, num in enumerate(S):
    ans = min(ans, S[index+1:].count('E')+S[:index].count('W'))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
min = 3*10**5
for i in range(n):
    if s[i:].count("E") + s[:i].count("W") < min:
        min = s[i:].count("E") + s[:i].count("W")
print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 3 * 10 ** 5

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
    
N=int(input())
S=str(input())
#W=左
#E=右
ans=[]
for i in range(1,N-1):        
    c1=collections.Counter(S[0:i-1])
    c2=collections.Counter(S[i:N])
    ans.append(c1["W"]+c2["E"])
     
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
#W=左
#E=右
ans=[]
for i in range(1,N-1):
    count=0
    ans.append(S[0:i-1].count("W")+S[i:N].count("E"))


print(min(ans))