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:
import sys
input=sys.stdin.readline
N=int(input())
s=list(input())
num=10*6
for i in range(N):
    num1=s[:i].count("W")+s[i+1:].count("E")
    num=min(num,num1)
print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_li = list(input())
all_li = [[0,0]]
for s in s_li:
    if s == 'W':
        all_li.append([all_li[-1][0]+1,all_li[-1][1]])
    else:
        all_li.append([all_li[-1][0],all_li[-1][1]+1])
#print(all_li)
ans = float('inf')
for i,a in enumerate(all_li):
    if i == 0:
        continue
    tmp_count = 0
    hidari = all_li[:i]
    if len(hidari)>0:
        tmp_count += hidari[-1][0]
    migi = all_li[i+1:]
    if len(migi)>0:
        tmp_count += (migi[-1][1]-a[1])
    if tmp_count < ans:
        ans = tmp_count
    #print(i,a,tmp_count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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


def csum(lis):
      counter=[]

      for i,l in enumerate(lis):
          counter.append(lis[i+1:].count('E') + lis[:i].count('W'))

      return min(counter)

print(csum(S))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
we = []
e, w = "E", "W"
for i in range(n) :
    if i == 0 :
        we.append(s[i+1:].count(e))
    elif i >= 1 :
        we.append(s[0:i-1].count(w) + s[i+1:].count(e))
    elif i == n :
        we.append(s[0:i-1].couont(w))
else:
    print(min(we))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
L = list(input())
for i in range(n):
    if L[i] == "W":
        L[i] = 0
    else:
        L[i] = 1

ans = 3*(10**5)
for i in range(1,n-1):
    Ll = np.array(L[:i])
    Lr = np.array(L[i+1:])
    Ll = np.cumsum(Ll)
    Lr = np.cumsum(Lr)
    if L[i] == 0:
        ans = min(ans,Ll[-1]+Lr[-1])
    elif L[i] == 1:
        ans = min(ans,len(Ll)-Ll[-1]+len(Lr)-Lr[-1])
    ans = min(ans,len(Ll)-Ll[-1]+Lr[-1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
s=input()
ans = np.array([0]*N)
for n,i in enumerate(s):
    if i=="W":
        ans += np.array([0]*(n+1)+[1]*(N-n-1))
    else:
        ans += np.array([1]*(n+1)+[0]*(N-n-1))
print(min(ans))

Submission status: Time Limit Exceeded

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

ans = 10 ** 9

cum_sum = [10 ** 7] * N

for i in range(1,N):
  left = S[:i]
  right = S[i:]
  turn = left.count("W")+ right.count("E")
  if S[i - 1] == "W":
    turn -= 1
  cum_sum[i - 1] = turn
    
print(min(cum_sum))

Submission status: Time Limit Exceeded

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

center = N // 2

ans = 10 ** 9

for i in range(1,N):
  left = S[:i]
  right = S[i:]

  turn = left.count("W")+ right.count("E")
  if S[i - 1] == "W":
    turn -= 1
  if ans >= turn:
    ans = turn
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
c = 10**6
for i in range(len(s)):
	c =  min((s[:i].count("W") + s[i+1:].count("E")),c)
print (c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = list(input())
Sr = list(reversed(S))
a_E = []
a_W = []
ans = N
for i in range(N):
    s = 0
    if S[i] == 'W':
        s = 1
    a_E.append(s)
    
for i in range(N):
    sr = 0
    if Sr[i] == 'E':
        sr = 1
    a_W.append(sr)
    
for i in range(N):
    ans = min(sum(a_E[:i]+a_W[:N-i]),ans)
     
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))
#print(B)
ans = float('Inf')
for i in range(0,n):
    #w = s[:i].count("W")
    ##W = sum(tt[:i])
    w = B[i]
    #print(W,w)
    #e = s[i:].count("E")
    E = len(tt[i:]) - sum(tt[i:])
    e = n - i - B[-1] + B[i]
    #print(E,e)
    #ans = min(ans,W+E)
    ans = min(ans,w+e)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
for i in range(len(S)):
    S[i]=-1 if S[i]=="W" else 1
data=[0 for i in range(N)]

for i in range(N):
    data[i]=-1*sum([S[m] for m in range(0,i) if S[m]==-1])+sum([S[m] for m in range(i+1,N) if S[m]==1])
print(min(data))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
ans = float('Inf')
for i in range(0,n):
    #w = s[:i].count("W")
    W = sum(tt[:i])
    #e = s[i:].count("E")
    E = len(tt[i:]) - sum(tt[i:])
    ans = min(ans,W+E)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
ans = float('Inf')
for i in range(n):
    w = s[:i].count("W")
    e = s[i:].count("E")
    ans = min(ans,w+e)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
ans = float('Inf')
for i in range(n):
    w = s[:i].count("W")
    e = s[i:].count("E")
    ans = min(ans,w+e)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

counter = len(S)
 
for i in range(len(S)):
  cost = S[:i].count('W') + S[i+1:].count('E')
  if cost < counter:
    counter = cost
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
W = S.count('W')
E = S.count('E')
counter = len(S)

for i in range(len(S)):
  cost = S[:i].count('W') + S[i+1:].count('E')
  if cost < counter:
    counter = cost
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
X=[]
for i in range(N):
    s=0
    for j in range(N):
        if i!=j:
            if j<i:
                if S[j]=="W":
                    s+=1
            if i<j:
                if S[j]=="E":
                    s+=1
    X.append(s)
print(min(X))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
X=[]
for i in range(N):
    s=0
    for j in range(N):
        if i!=j:
            if j<i:
                if S[j]=="W":
                    s+=1
            if i<j:
                if S[j]=="E":
                    s+=1
    X.append(s)
print(min(X))

Submission status: Time Limit Exceeded

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

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

print(min_n)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count_e = [0] * N
count_w = [0] * N
for i in range(N):
    if S[i] == "E":
        count_e[i] = 1
    else:
        count_w[i] = 1
ans = float('inf')
for i in range(N):
    ans = min(ans, sum(count_w[:i]) + sum(count_e[i:]))
print(ans)

Submission status: Time Limit Exceeded

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

s = [0]*N

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

print(min(s))

Submission status: Time Limit Exceeded

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


ans=10**100
for i in range(n):
    a=s.count('W',0,i)
    b=s.count('E',i+1,n)
    if a+b<=ans:
        ans=a+b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=['*']+list(input())+['*']

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [i for i in input()]

count_r = 0
counter = 0

for i in range(n):
    leader = i
    for j in range(0, i):
        if s[j] == "E":
            counter += 1#向かなくていい人の数
    if i != n-1:
        for j in range(i+1, n):
            if s[j] == "W":
                counter += 1

    if counter > count_r:
         count_r = counter
         ans = n-1-count_r
    counter = 0

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = N + 1

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

first = S[0:].count('E')
end = S[:N - 1].count('W')
ans = min(ans, first, end)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [s for s in input()]
ans = float('inf')
for i in range(n):
    #print(S[:i],S[i+1:])
    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=input()
left_count=0
right_count=0
ans=N
for i in range(N):
    right_count=S[i+1:].count('E')
    ans=min(ans, right_count+left_count)
    if S[i]=='W':
        left_count+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from copy import deepcopy

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

L = np.zeros(N)
L[0] = 1*(S[0] == 'W')

for i in range(N-1):
  L[i+1] = L[i] + (S[i+1] == 'W')
  
solve = []
solve.append(S[1:].count('E')) # i=0
for i in range(1,N-1): # i=1~(N-2)
  cost = N - L[N-1] - (i+1) + L[i-1] + L[i]
  solve.append(cost)
solve.append(S[:-2].count('W')) # i=N-1
  
ans = int(min(solve))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = input()

c = [S.count('E',1,N)]

for i in range(1,N):
  c.append(S.count('E',i+1,N)+S.count('W',0,i-1))
            
print(min(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from copy import deepcopy

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

L = np.zeros(N)
L[0] = (S[0] == 'W')

for i in range(N-1):
  L[i+1] = L[i] + (S[i+1] == 'W')
  
solve = []
for i in range(N):
  if i == 0:
    cost = S[1:].count('E')
  elif i == N-1:
    cost = S[:-2].count('W')
  else:
    cost = N - L[N-1] - (i+1) + L[i-1] + L[i]
  solve.append(cost)
  
ans = int(min(solve))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int, input().split()
S = input()
res = 10 ** 9
for i in range(len(S)):
    tmp = S[:i].count("W") + S[i+1:].count("E")
    res = tmp if tmp < res else res
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
ans = 1000000
for i in range(N):
    tmp = S[0:i].count("W")+S[i:].count("E")
    if ans >= tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Max = 0
for i in range(N):
    if i == 0:
        Max = S[1:].count('W')
    elif i < N-1:
        ct = S[:i].count('E') + S[i+1:].count('W')
        Max = max(Max, ct)
    else:
        Max = max(Max, S[:-1].count('E'))

ans = N-1 - Max

print(ans)

Submission status: Time Limit Exceeded

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

nums = []
if S[0] == 'W':
    nums.append(0)

count = 0
d = S[0]
for i in range(N):
    if S[i] == d:
        count+=1
    else:
        nums.append(count)
        d = S[i]
        count = 1
nums.append(count)

min = 3 * 10**5
ans = 0
for i in range(len(nums)):
    if nums[i] == 0:
        continue
    
    ans += sum(nums[1:i:2])
    if i % 2== 0:
        ans += sum(nums[i+2::2])
    else:
        ans += sum(nums[i+1::2])
    if min > ans:
        min = ans
    ans = 0

print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#098 C
N =int(input())
S = input()
ans = []
for i in range(N+1):
    ans.append(S[0:i].count("W")+S[i+1:].count("E"))
    
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
#098 C
N =int(input())
S = input()
ans = N
for i in range(N+1):
    cnt =S[0:i].count("W")+S[i+1:].count("E")
    if ans >=cnt:
        ans = cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from numpy import array
n=int(input())
s=input()
t=s.count("E")
r=s.count("W")
dp =[r-(s[-1]=="W")]+[0 for i in range(n-1)]
dp2=[t-(s[0 ]=="E")]+[0 for i in range(n-1)]

for i in range(1,n):
    if s[i]=="W":
        dp2[i]=dp2[i-1]
    else:
        dp2[i]=dp2[i-1]-1
    if s[::-1][i]=="E":
        dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1]-1
print(min(array(dp[::-1])+array(dp2)))

Submission status: Time Limit Exceeded

Solution code:
from numpy import array
n=int(input())
s=input()
t=s.count("E")
r=s.count("W")
dp =[r-(s[-1]=="W")]+[0 for i in range(n-1)]
dp2=[t-(s[0 ]=="E")]+[0 for i in range(n-1)]
for i in range(1,n):
    if s[::-1][i]=="E":
        dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1]-1

for i in range(1,n):
    if s[i]=="W":
        dp2[i]=dp2[i-1]
    else:
        dp2[i]=dp2[i-1]-1

print(min(array(dp[::-1])+array(dp2)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
best = 3 * 10 ** 5

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

print(best)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(input())
br = []
for i in range(a):
    count = 0
    wr = ar[0:i]
    er = ar[i:a]
    count += wr.count("W")
    count += er.count("E")
    br.append(count)
print(min(br))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N=int(input())
S=input()
w=[0]
e=[0]
a=0
b=0
c=N
de=deque(e)
for i in range(len(S)-1):
    if S[i]=="W":
        a+=1   
    w.append(a)
    if S[-(i+1)]=="E":
        b+=1
    de.appendleft(b)
for i in range(N):
    if w[i]+de[i]<c:
        c=w[i]+de[i]
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=int(input())
N=input()
a=S
for i in range(S):
    if i==0:
        if a>N[1:].count("E"):
            a=N[1:].count("E")
    elif i==len(N)-1:
        if a>N[:len(N)].count("W"):
            a=N[:len(N)].count("W")
    else:
        if a>N[:i].count("W")+N[i+1:].count("E"):
            a=N[:i].count("W")+N[i+1:].count("E")
print(a)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
nummin = 3e5
for i in range(N):
	num = 0
	for j in range(i):
		if S[j] == 'W':
			num += 1
	for j in range(i+1,N):
		if S[j] == 'E':
			num += 1
	if nummin > num:
		nummin = num
print(nummin)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count_list = []
camu_west = []
for i in range(1,N+1):
  look_west = len([S[j] for j in range(i) if S[j] == "W"])
  camu_west.append(look_west)
for i in range(N):
  count_l = camu_west[i-1]
  if i == 0:
    count_l = 0
  count_r = N-1-i-(camu_west[N-1]-camu_west[i])
  if i == N:
    count_r = 0
  count = count_l + count_r 
  count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count_list = []
for i in range(N):
  S_l = S[:i]
  S_r = S[i+1:]
  count = S_l.count("W") + S_r.count("E")
  count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count_list = []
for i in range(N):
  count1 = len([S[j] for j in range(N) if j < i and S[j] == "W" ])
  count2 = len([S[i] for j in range(N) if i < j and S[j] == "E"])
  count = count1 + count2
  count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count_list = []
for i in range(N):
  count = 0
  for j in range(N):
#   leader = i
    if j < i and S[j] == "W":
      count += 1
    elif i < j and S[j] == "E":
      count += 1
  count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

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

ret = 10**10

for leader in range(len(S)):
    leftW = S[0:leader].count("W")
    rightE = S[leader+1:len(S)].count("E")
    # print("{}, {}".format(leftW, rightE))
    sum = leftW + rightE
    ret = min(ret, sum)

print(ret)

Submission status: Time Limit Exceeded

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

for i in range(N):
  t = 0
  
  for j in range(N):
    if (j < i and S[j] == "W") or (i < j and S[j] == "E"):
      t += 1

  ts.append(t)
  
print(min(ts))

Submission status: Time Limit Exceeded

Solution code:
debug = True

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

    minCnt=N

    for i in range(N):
        if i==0:
            minCnt=min(minCnt,S[1:].count('E'))
        elif i == N-1:
            minCnt=min(minCnt,S[:N-2].count('W'))
        else:
            minCnt=min(minCnt,S[:i-1].count('W')+S[i+1:].count('E'))

    print(minCnt)
    return

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = [N]
for k in range(N):
  w = S[:k].count('W')
  e = S[k:].count('E')
  if (w+e <= L[0]):
    del L[0]
    L.append(w+e)
print(L[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = []
for k in range(N):
  w = S[:k].count('W')
  e = S[k:].count('E')
  L.append(w+e)
print(min(L))

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
s = arr_data[1][0]

cnt=n

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

Submission status: Time Limit Exceeded

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
s = arr_data[1][0]

cnt=n

for i in range(n):
    
    num=0
    if s[i]=="W":
        
        num+=s[:i].count("W")
        num+=s[i+1:].count("E")
        
    elif s[i]=="E":
        
        num+=s[:i].count("W")
        num+=s[i+1:].count("E")
        
    cnt=min(num,cnt)
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input()
arr=input()
arr=[sum(x=="W" for x in arr[:i])+sum(x=="E" for x in arr[i+1:]) for i,n in enumerate(arr)]
print(min(arr))

Submission status: Time Limit Exceeded

Solution code:
# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention.py

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

#e = [0 for i in range(N)]
#w = [0 for i in range(N)]
d = [0 for i in range(N)]
#print("累積和")

for i in range(N):
    # そこからE側の人で、Wを向くべきなのにEを向いている人
    if S[i] == "E":
        for j in range(0, i):
            #e[j]+=1
            d[j]+=1
    # そこからW側の人で、Eを向くべきなのにWを向いている人
    else:
        for j in range(i+1, N):
            #w[j]+=1
            d[j]+=1
    #print("i:", i)
    #print("w:", w)
    #print("e:", e)
    #print("")

#w[0] = 0
#e[-1] = 0

#print("w:", w)
#print("e:", e)
min = 10 ** 6

for i in range(N):
    if d[i] < min:
        min = d[i]
print(min)

Submission status: Time Limit Exceeded

Solution code:
# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention.py

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

e = [0 for i in range(N)]
w = [0 for i in range(N)]

#print("累積和")

for i in range(N):
    # そこからE側の人で、Wを向くべきなのにEを向いている人
    if S[i] == "E":
        for j in range(0, i):
            e[j]+=1
    # そこからW側の人で、Eを向くべきなのにWを向いている人
    elif S[i] == "W":
        for j in range(i+1, N):
            w[j]+=1
    #print("i:", i)
    #print("w:", w)
    #print("e:", e)
    #print("")

#w[0] = 0
#e[-1] = 0

#print("w:", w)
#print("e:", e)
min = 10 ** 6

for i in range(N):
    total = e[i]+w[i]
    if total < min:
        min = total
print(min)

Submission status: Time Limit Exceeded

Solution code:
n =int( input())
a = input()
S = [a[i:i+1] for i in range(len(a))]
left = []
right = []
answer = n
 
for i in range(n):
    an = 0
    left = S[:i]
    right = S[i+1:]
    an += left.count("W")
    an += right.count("E")
    
    if answer > an : answer = an
print(answer)

Submission status: Time Limit Exceeded

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

ans = N
for i in range(N):
 west = line[:i]
 tmp = west.count('W')
 east = line[i+1:]
 tmp += east.count('E')
 if ans>tmp:
  ans = tmp


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
k=n
for i in range(n):
    a=s[:i]
    b=s[i+1:]
    l=0
    for j in range(i):
        if a[j]=="W":
            l+=1
    for j in range(n-i-1):
        if b[j]=="E":
            l+=1
    if l<k:
        k=l
print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
k=n
for i in range(n):
    a=s[:i]
    b=s[i+1:]
    l=a.count("W")+b.count("E")
    if l<k:
        k=l
print(k)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

E = "E"  # ->
W = "W"  # <-


class Line:

    def __init__(self, people):
        self.people = people

    def get_change_count(self, leader):
        leader_i = leader - 1
        count = 0
        for i in range(len(self.people)):
            if i == leader_i:
                continue
            elif i < leader_i:
                if self.people[i] == W:
                    count += 1
            elif leader_i < i:
                if self.people[i] == E:
                    count += 1
            else:
                assert ()
        return count


def main():
    people_count = int(input().rstrip())

    people = input().rstrip()
    line = Line(people)

    min_leader_no = None
    min_change_count = float('inf')

    for i in range(1, people_count + 1):
        change_count = line.get_change_count(i)
        if change_count < min_change_count:
            min_leader_no = i
            min_change_count = change_count

        if min_change_count <= 1:
            break

    print(min_change_count)


main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

E = "E"  # ->
W = "W"  # <-


class Line:

    def __init__(self, people):
        self.people = people

    def get_change_count(self, leader):
        leader_i = leader - 1
        count = 0
        for i in range(len(self.people)):
            if i == leader_i:
                continue
            elif i < leader_i:
                if self.people[i] == W:
                    count += 1
            elif leader_i < i:
                if self.people[i] == E:
                    count += 1
            else:
                assert ()
        return count


def main():
    people_count = int(input().rstrip())

    people = input().rstrip()
    line = Line(people)

    min_leader_no = None
    min_change_count = float('inf')

    for i in range(1, people_count + 1):
        change_count = line.get_change_count(i)
        if change_count < min_change_count:
            min_leader_no = i
            min_change_count = change_count

    print(min_change_count)


main()

Submission status: Time Limit Exceeded

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

minIndex = 0
maxIndex = len(s)
minimum = len(s)
while True:
    i = int((maxIndex - minIndex) / 2) + minIndex
    cnt = s[:i].count('W') + s[i + 1:].count('E')
    if cnt < minimum:
        minimum = cnt
    iv = int((maxIndex - minIndex) / 4)
    if iv == 0:
        iv = 1
    i1 = i - iv
    i2 = i + iv
    if i1 < minIndex:
        i1 = minIndex
    if i2 > maxIndex:
        i2 = maxIndex
    cnt1 = s[:i1].count('W') + s[i1 + 1:].count('E')
    cnt2 = s[:i2].count('W') + s[i2 + 1:].count('E')
    if cnt1 < cnt2:
        if cnt1 <= minimum:
            minimum = cnt1
            maxIndex = i
    elif cnt1 > cnt2:
        if cnt2 <= minimum:
            minimum = cnt2
            minIndex = i
    else:
        if cnt1 == cnt2:
            break
print(minimum)

Submission status: Time Limit Exceeded

Solution code:
n = input()
s = input()
m = len(s)
for i in range(len(s)):
    c = s[:i].count('W') + s[i + 1:].count('E')
    if c < m:
        m = c
print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

position_L = []
position_R = []
for s in S:
    if s == 'W':
        position_L.append(1)
        position_R.append(0)
    else:
        position_L.append(0)
        position_R.append(1)
i = 0
flips = N + 1
while i < N:
    flips_temp = 0
    j  = 0
    flips_temp = sum(position_L[:i]) + sum(position_R[i+1:])
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

Submission status: Time Limit Exceeded

Solution code:
input()
s = input()

def f(i):
  return s[0:i].count('W') + s[i:].count('E')

x = len(s)

for i in range(len(s)):
  x = min(x, f(i))

print(x)

Submission status: Time Limit Exceeded

Solution code:
input()
s = input()

def f(i):
  return s[0:i].count('W') + s[i:].count('E')

arr = []

for i in range(len(s)):
  arr.append(f(i))

print(min(arr))

Submission status: Time Limit Exceeded

Solution code:
input()
s = input()

def f(i):
  return s[0:i].count('W') + s[i:].count('E')

arr = map(f, range(len(s)))

print(min(arr))

Submission status: Time Limit Exceeded

Solution code:
input()
s = input()

def f(i):
  x = 0

  for n in range(len(s)):
    if n < i and s[n] == 'W':
      x += 1
    elif n > i and s[n] == 'E':
      x += 1
  
  return x

arr = map(f, range(len(s)))

print(min(arr))

Submission status: Time Limit Exceeded

Solution code:
input()
s = input()

def f(i):
  w = s[0:i]
  e = s[i:]

  wl = filter(lambda c: c == 'W', w)
  el = filter(lambda e: e == 'E', e)

  return len(list(wl) + list(el))

l = map(f, range(len(s)))

print(min(list(l)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
 
ans = len(S) - 1
left = 0 # リーダーより左
right = 0 # リーダーより右

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
dir_change = [0] * N
for i in range(N):
	for j in range(N):
		if i < j and S[j] == "E":
			dir_change[i] += 1
		if i > j and S[j] == "W":
			dir_change[i] += 1
print(min(dir_change))

Submission status: Time Limit Exceeded

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

change = n
for i in range(n):
    cnt = 0
    if i > 0:
        cnt += string[:i].count("W")
    if i < n-1:
        cnt += string[i+1:].count("E")

    change = min(change, cnt)
print(change)

Submission status: Time Limit Exceeded

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

min_num = 300000
left = 0

for i in range(len(S)):

  if i > 0:
    left += int(S[i - 1] == "W")

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

  if left + right < min_num:
    min_num = left + right

print(min_num)

Submission status: Time Limit Exceeded

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

min_num = 300000

for i in range(len(S)):

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

  if left + right < min_num:
    min_num = left + right

print(min_num)

Submission status: Time Limit Exceeded

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

turns_num_list = list()

for i in range(len(S)):

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

  turns_num_list.append(left+right)

print(min(turns_num_list))

Submission status: Time Limit Exceeded

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

turns_num_list = list()

for i in range(len(S)):

  left = [s == "W" for s in S[: i]].count(True)
  right = [s == "E" for s in S[i+1: ]].count(True)

  turns_num_list.append(left+right)

print(min(turns_num_list))