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

#W=左
#E=右
ans=1000000000000
for i in range(N-1):
    count=0
    SL="".join(S[0:i])
    SR="".join(S[i+1:len(S)])
    #print(SL+"と"+SR)
    #print(SL.count("W"))
    #print(SR.count("E"))
    count=SL.count("W")+SR.count("E")
    ans=min(ans,count)

print(ans)

Submission status: Time Limit Exceeded

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

L = [0]*(N)
for i in range(N):
    SUM = A[:i].count("W")+A[i+1:].count("E")
    L[i] =SUM
print(min(L))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = min(s[1:].count("E"), s[:-1].count("W"))

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

print(ans)

Submission status: Time Limit Exceeded

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

ans=[]

for i in range(n):

    ans.append(s[0:i].count("W")+s[i+1:n].count("E"))
    
print(min(ans))

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:
N = int(input())
S = input()

A = []

for n in range(N):
    if n == 0:
        L = 0
        R = sum([s != 'W' for s in S[n+1:]])
    elif n == N-1:
        L = sum([s != 'E' for s in S[:n]])
        R = 0
    else:
        L = sum([s != 'E' for s in S[:n]])
        R = sum([s != 'W' for s in S[n+1:]])
    A.append(L+R)

print(min(A))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(0,N) :
    if i == 0 :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
    elif S[i-1] == "E" and S[i] == "E" :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
print(min(Q))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(0,N) :
    if i == 0 :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
    elif S[i-1] == "E" :
        A = S[0:i]
        B = S[i+1:N]
        Q.append(A.count("W")+B.count("E"))
print(min(Q))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(0,N) :
    A = S[0:i]
    B = S[i+1:N]
    for j in range(len(A)) :
        if A[j] == "W" :
            A[j] = 1
        else :
            A[j] = 0
    for k in range(len(B)) :
        if B[k] == "W" :
            B[k] = 0
        else :
            B[k] = 1
    Q.append(sum(A)+sum(B))
print(min(Q))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(0,N) :
    A = S[0:i]
    B = S[i+1:N]
    a = "".join(A)
    b = "".join(B)
    Q.append(A.count("W")+B.count("E"))
print(min(Q))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(N) :
    if i not in range(1,N) :
        Q.append(S.count("E"))
    else :
        A = S[0:i]
        B = S[i+1:N+1]
        Q.append(A.count("W")+B.count("E"))
print(min(Q))

Submission status: Time Limit Exceeded

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

answer = float('inf')
for i in range(N):
    lcount = 0 if i == 0 else S[:i].count('W')
    rcount = 0 if i == N-1 else S[i:].count('E')
    answer = min(answer, lcount+rcount)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
line = list(input())
cum_sum_w = [0]
cum_sum_e = [0]
for i in range(n):
    cum_sum_w.append(line[:i + 1].count('W'))
    cum_sum_e.append(line[:i + 1].count('E'))
count_list = []
for i in range(n):
    count = 0
    count += cum_sum_w[i]
    count += cum_sum_e[n] - cum_sum_e[i]
    count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
line = list(input())
count_list = []
for i in range(len(line)):
    count = line[:i].count('W') + line[i + 1:].count('E')
    count_list.append(count)
print(min(count_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

m = float("inf")
for i in range(N):
    cnt = 0
    for j in range(N):
        if i == j:
            continue
        elif i > j:
            if S[j] =='W':
                cnt += 1
        elif i < j:
            if S[j] == 'E':
                cnt += 1
    if m > cnt:
        m = cnt

print(m)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
S = input()
res = []
for i, n_ban in enumerate(S):
    # Westからn_ban目の人をリーダーとしたときに何人を変える必要があるか
    # n_banについて全探索
    # 自分よりEast側かつEastを向いてる人の人数と
    # 自分よりWest側かつWestを向いてる人の人数の合計
    E_cnt = 0
    W_cnt = 0
    E_line = S[i:]
    W_line = S[:i]
    E_cnt = E_line.count('E')
    W_cnt = W_line.count('W')
    if n_ban == 'E':
        E_cnt -= 1
    res.append(E_cnt+W_cnt)

print(min(res))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
res = []
for i, n_ban in enumerate(S):
    # Westからn_ban目の人をリーダーとしたときに何人を変える必要があるか
    # n_banについて全探索
    # 自分よりEast側かつEastを向いてる人の人数と
    # 自分よりWest側かつWestを向いてる人の人数の合計
    E_cnt = 0
    W_cnt = 0

    for ii, target in enumerate(S):
        if i < ii:
            if target == "E":
                E_cnt += 1
        elif ii < i:
            if target == "W":
                W_cnt += 1
    
    res.append(E_cnt+W_cnt)

print(min(res))

Submission status: Time Limit Exceeded

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

ans = float("inf")
E = S.count("E")
W = S.count("W")
for i, v in enumerate(S):
    left = S[:i]
    left_E = left.count("E")
    left_W = left.count("W")
    if v == "E":
        right_E = E - left_E - 1
    else:
        right_E = E - left_E
    ans = min(ans, left_W + right_E)


print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    search_range = s[:i+1]
    W_list.append(search_range.count("W"))
    E_list.append(search_range.count("E"))
min = n
for i in range(n):
    if i == 0:
        change_man = E_list[-1] - E_list[0]
        if min > change_man:
            min = change_man
            continue
    left_range = W_list[i-1]
    right_range = E_list[-1] - E_list[i]
    change_man = left_range + right_range
    if min > change_man:
        min = change_man
print(min)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 10**6

for i in range(n):
    s1 = s[0:i]
    s2 = s[i+1:n]
    sum = s1.count("W") + s2.count("E")
    if sum < ans:
        ans = sum
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def count(s, c):
    cnt = 0
    for i in s:
        if i == c:
            cnt += 1
    return cnt

def main():
    #入力
    N = int(input())
    S = input()

    min_cnt = 300000
    ew = ['E', 'W']

    for i in range(N):
        first_str = S[:i]
        last_str = S[i+1:]

        cnt = 0
        cnt_too_much_flag = 0

        for j in first_str:
            if j == 'W':
                cnt += 1
            elif cnt_too_much_flag == 1:
                break
            elif cnt > min_cnt:
                cnt_too_much_flag = 1
        for j in last_str:
            if j == 'E':
                cnt += 1
            elif cnt_too_much_flag == 1:
                break
            elif cnt > min_cnt:
                cnt_too_much_flag = 1

        if cnt < min_cnt:
            min_cnt = cnt
        #print(first_str, last_str, cnt)
    
    
    print(min_cnt)
            

        


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def count(s, c):
    cnt = 0
    for i in s:
        if i == c:
            cnt += 1
    return cnt

def main():
    #入力
    N = int(input())
    S = input()

    min_cnt = 300000
    ew = ['E', 'W']

    for i in range(N):
        first_str = S[:i]
        last_str = S[i+1:]

        cnt = 0
        cnt += count(first_str, 'W')
        cnt += count(last_str, 'E')
        if cnt < min_cnt:
            min_cnt = cnt
        #print(first_str, last_str, cnt)
    
    
    print(min_cnt)
            

        


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

# 累積和を使う方法
W_ruiseki = []
E_ruiseki = []
# 0地点を含めたN+1パターンを予め用意しておく
for i in range(N+1):
    W_ruiseki.append(S[:i].count("W"))
    E_ruiseki.append(i - W_ruiseki[i])

ans = float("inf")
for i in range(N):
    cnt = 0
    cnt += W_ruiseki[i]
    cnt += E_ruiseki[N] - E_ruiseki[i+1]
    ans = min(ans, cnt)

print(ans)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
N=int(input())
s=list(input())
a = [0]*N
for i in range(0,N):
	if s[i]=='E':
		for j in range(0,i):
			a[j] = a[j]+1
	else:
		for j in range(i+1,N):
			a[j] = a[j]+1

print(min(a))

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
N=int(input())
s=list(input())
a = []

for i in range(1,N):
	b =s[:i:].count('W')
	c=s[i+1::].count('E')
	a.append(b+c)
a.append(s[1::].count('E'))
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = list(input())
ans = N
for i in range(N):
    L = Counter(S[:i])
    R = Counter(S[i+1:])
    ans = min(ans,L['W']+R['E'])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
check = set([0, n-1])
for i in range(n-1):
    if s[i] != s[i+1]: check = check | set([i, i+1])
ans = n
for i in check:
    tmp = 0
    for j in range(0, i):
        if s[j] == "W": tmp += 1
    for k in range(i+1, n):
        if s[k] == "E": tmp += 1
    ans = min(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = float("inf")

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()

npans = np.zeros(N,dtype = int)
for i,s in enumerate(S):
    if s == 'W':
        npans[i+1:] += 1
    else:
        npans[:i] += 1
print(np.min(npans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
row = list(input())
cou = []
for i in range(N):
  if i == 0:
    l = []
  else:
    l = row[:i-N]
  if i == N-1:
    r = []
  else:
    r = row[i+1:]
  s = l.count("W") + r.count("E")
  cou.append(s)
cou.sort()
print(cou[0])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
minimum=3*pow(10, 5)
east=[]
for i in range(N):
    east.append([S[:i].count('E'), S[i+1:].count('E')])
for i in range(N):
    X=S[:i]
    Y=S[i+1:]
    candidate = len(X)-east[i][0]+east[i][1]
    minimum = min(candidate, minimum)
print(minimum)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
minimum=3*pow(10, 5)
for i in range(N):
    X=S[:i]
    Y=S[i+1:]
    if S[i]=='E':
        candidate = (len(X)-X.count(S[i]))+Y.count(S[i])
    else:
        candidate = X.count(S[i])+(len(Y)-Y.count(S[i]))
    minimum = min(candidate, minimum)
print(minimum)

Submission status: Time Limit Exceeded

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

ans = N

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

    # count = BF.count('W') + AF.count('E')
    if (BF+AF) < ans:
        ans = BF + AF

print(ans)

Submission status: Time Limit Exceeded

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

ans = N-1
for i in range(N):
    cnt = 0
    for j in range(i):
        if S[j] == "W":
            cnt += 1
    for k in range(i+1, N):
        if S[k] == "E":
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Submission status: Time Limit Exceeded

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

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

    if (BF+AF) < ans:
        ans = BF + AF

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
count = 0
ans = N

for i in range(N):
    BF = S[:i]
    AF = S[i+1:]

    count = BF.count('W') + AF.count('E')
    if count < ans:
        ans = count

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = input()
m = 10000000000000000
for i in range(0, n):
    a = s[:i]
    b = s[i+1:]
    cnt = Counter(a)['W'] + Counter(b)['E']
    m = min(m, cnt)

print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
m = 10000000000000000
for i in range(0, n):
    a = s[:i]
    # print(a)
    b = s[i+1:]
    # print(b)
    cnt = a.count('W') + b.count('E')
    # print(cnt)
    m = min(m, cnt)

print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input()) 
result_list = []
for i in range(N):
    counter = 0
    for j in S[:i]:
        if j == "W":
            counter += 1
    for k in S[i+1:]:
        if k =="E":
            counter += 1
    result_list.append(counter)
print(min(result_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
Count = n
for i in range(n):
    f = s[:i]
    r = s[(i+1):]
    count = f.count("W")+r.count("E")
    if Count > count:
        Count = count
print(Count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
x=[]
y=list(s)
m=999999
for i in range(n):
    del y[0]
    xn=x.count('W')
    yn=y.count('E')
    z=xn+yn
    m=min(m,z)
    x.append(s[i])
print(m)

Submission status: Time Limit Exceeded

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


min_ct = 1000000000
for i in range(N):
    ct = 0
    j = 0
    k = N-1
    while k > i:
        if ct > min_ct: break
        if S[k] == "E":
            ct += 1
        k -= 1
    while j < i:
        if ct > min_ct: break
        if S[j] == "W":
            ct += 1
        j += 1

    if min_ct > ct:
        min_ct = ct

print(min_ct)

Submission status: Time Limit Exceeded

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


min_ct = 1000000000
for i in range(N):
    ct = 0
    j = 0
    k = N-1
    while j < i:
        if ct > min_ct: break
        if S[j] == "W":
            ct += 1
        j += 1
    while k > i:
        if ct > min_ct: break
        if S[k] == "E":
            ct += 1
        k -= 1
    if min_ct > ct:
        min_ct = ct

print(min_ct)

Submission status: Time Limit Exceeded

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


min_ct = 1000000000
for i in range(N):
    ct = 0
    j = 0
    k = N-1
    while j < i:
        if S[j] == "W":
            ct += 1
        j += 1
    while k > i:
        if S[k] == "E":
            ct += 1
        k -= 1
    if min_ct > ct:
        min_ct = ct


print(min_ct)

Submission status: Time Limit Exceeded

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


min_ct = 1000000000
for i in range(N):
    ct = 0
    num_W = S[0:i+1].count("W")
    num_E = S[i:N].count("E")
    ct += num_W + num_E
    if min_ct > ct:
        min_ct = ct


print(min_ct-1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
minnum = 300000
for i in range(N):
    num = 0
    for j in range(N):
        if i !=j:
            if i < j and S[j] == 'E':
                num += 1
            elif i > j and S[j] == 'W':
                num += 1
    if num < minnum:
        minnum = num
print(minnum)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
# -*- coding:utf-8 -*-

if __name__ == "__main__":
    N = int(input())
    S = input()
    dp = [[0 for i in range(N+1)] for j in range(N+1)]
    # dp[left][right] := 正しい方向の数
    # まずはdp[0][N]を考える
    for s in S:
        if s == "W":
            dp[0][N] += 1
    maxv = dp[0][N]
    # dpを埋める
    # dp[1][N-1], dp[2][N-2], ...
    for i in range(1, N+1):
        if S[i-1] == "E":
            diff = 1
        else:
            diff = -1
        dp[i][N-i] = dp[i-1][N-i+1] + diff
        if dp[i][N-i] >= maxv:
            maxv = dp[i][N-i]
    print(N - maxv)

Submission status: Time Limit Exceeded

Solution code:
input()
S=input()
N=len(S)
turn_min=N
for i in range(1,N-1):
    s1,s2=S[0:i-1],S[i:N]
    turn_sum=s1.count('W')+s2.count('E')
    if turn_min>turn_sum:
        turn_min=turn_sum
print(turn_min)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = input()

    res = float('inf')
    for i in range(N):
        temp = 0
        for j in range(N):
            if i > j and S[j] == 'W':
                temp += 1
            elif i < j and S[j] == 'E':
                temp += 1
        if res > temp:
            res = temp

    print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [x[:1] for x in input()]
ans = 0
count = 0

#1番西
SC1,SE1 = S[0],S[1:]
count = SE1.count("E")

ans = count
#print(ans)

#2番目からN-1番目まで
for i in range(1,len(S) - 1):
    SW,SC,SE  = S[0:i], S[i], S[i:len(S)]
    count = SW.count("W") + SE.count("E")
    if count <= ans:
        ans = count

    #print(SW,SC,SE,count,ans)


#N番目
SWN,SCN,count = S[:len(S) - 2], S[len(S) - 1], 0
count = SWN.count("W")
if count <= ans:
    ans = count

print(ans)

Submission status: Time Limit Exceeded

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

m = S.count('W')
x = 0

for i in range(N):
    x = S.count('E')
    if x < m:
        m = x

    if S[i] == 'W':
        S[i] = 'E'
    else:
        S[i] = 'W'

print(m)

Submission status: Time Limit Exceeded

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

rtn = N 

def count_change(func, s): 
    return len(list(filter(func, s)))

for i in range(N):
    west_change = count_change(lambda x: x=="W", S[:i]) 
    east_change = count_change(lambda x:x=="E", S[i+1:])
    change_num = west_change + east_change
    if change_num < rtn and change_num!=0:    
        rtn = change_num

print(rtn)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
def count_change(string, wrong_dir):
    # count number of people that need to change to specified direction
    return string.count(wrong_dir)

change_counts = list()
for i in range(len(S)):
    # strings west and east of leader, excluding the leader
    west_string = S[:i]
    east_string = S[i+1:]
    total_changes = count_change(west_string,'W') + count_change(east_string, 'E')
    change_counts.append(total_changes)
    
print(min(change_counts))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(0,N-1):
    strl2 = S[0:i]
    strr2 = S[i+1:N]
    cutstrl2 = strl2.replace("E","")
    cutstrr2 = strr2.replace("W","")
    lst.append(len(cutstrl2)+len(cutstrr2))
print (min(lst))

Submission status: Time Limit Exceeded

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

max_c = 100000000

for i in range(0,n):
    l_count = 0
    r_count = 0
    for j in range(0, i):
        if a[j] == 'W':
            l_count += 1
    for j in range(i, n):
        if a[j] == 'E':
            r_count += 1
    if max_c > l_count + r_count:
        max_c = l_count + r_count

print(max_c)

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()
min_change = min([S[0:n].count("W") + S[n+1:N].count("E") for n in range(N)])
print(min_change)

Submission status: Time Limit Exceeded

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

def nof_change(n, S):
    M = sum(1 if S[i] != "E" else 0 for i in range(n))
    M += sum(1 if S[i] != "W" else 0 for i in range(n+1,N))
    return M

min_change = min([nof_change(n, S) for n in range(N)])
print(min_change)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
min_change = N
for n in range(N):
    goal = "E"*(n+1) + "W"*(N-n)
    M = sum(1 if S[i] != goal[i] else 0 for i in range(n))
    M += sum(1 if S[i] != goal[i] else 0 for i in range(n+1,N))
    min_change = min(min_change, M)
print(min_change)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
num = [0 for i in range(n)]
for i in range(n):
    for j in range(0, i):
        if s[j] == "W":
            num[i] += 1
    for j in range(i+1, n):
        if s[j] == "E":
            num[i] += 1
    # print(num[i])
print(min(num))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

min = -1

for i in range(n-1):
    turn = s[0:i].count("W") + s[i+1:n].count("E")
    if min == -1 or min >= turn:
        min = turn
        
    

print(min)

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'))
    if ans == 0:
      break
print(ans)

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=input()
ans=3*10^5
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 = input()
ans = N
E = [0] * N
W = [0] * N
for i in range(N):
    if S[i] == 'E': E[i] = 1
    else: W[i] = 1
for i in range(N):
    LR = sum(W[:i]) + sum(E[i+1:])
    if LR < ans: ans = LR
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import collections

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

n = int(input().rstrip())

line = input().rstrip()

min_change_count = float('inf')

for i in range(n):
    w_line = line[0:i]
    e_line = line[i+1:] if i < n else []

    change_count = 0
    change_count += collections.Counter(w_line)[W]
    change_count += collections.Counter(e_line)[E]

    min_change_count = change_count if change_count < min_change_count else min_change_count


print(min_change_count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
s=input()
count=[]
west=[]
east=[]
for i in range(N):
    west.append(0)
    east.append(0)
    if(s[i]=='W'):
        west[i]=1
    else:
        east[i]=1
eastsum=np.zeros(N)
westsum=np.zeros(N)
for i in range(N):
    eastsum[i]=sum(east[i:])-east[i]
    westsum[i]=sum(west[:i])
print(int(np.min(eastsum+westsum)))

Submission status: Time Limit Exceeded

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

ans = float('inf')

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=input()
count=[]
for i in range(N):
    count.append(0)
    for k in range(i-1):
        if(s[k]=='W'):
            count[i]=count[i]+1
    for j in range(1,N-i):
        if(s[i+j]=='E'):
            count[i]=count[i]+1
print(min(count))

Submission status: Time Limit Exceeded

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

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

for n in range(1, N-1):
    S1  = S[:(n-1)]
    S2  = S[(n+1):]
    num = S1.count("W") + S2[:(N-1)].count("E")
    if num < res:
        res = num

print(res)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
change_min=N
for leader in range(N):
    S_west=S[:leader]
    S_east=S[leader+1:N]
    change=S_west.count("W")+S_east.count("E")
    if change<=change_min:
        change_min=change
print(change_min)

Submission status: Time Limit Exceeded

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

w = [0 for i in range(n)]
ac = 0
for i in range(n):
    if s[i] == 'W':
        ac += 1
    w[i] = ac

e = [i + 1 - w[i] for i in range(n)]

for i in range(n):
    if s[i] == 'W':
        acW = w[i] - 1
        racE = s.count('E') - e[i]
        minChange = min(minChange, acW + racE)
    else:
        acW = w[i]
        racE = s.count('E') - e[i]
        minChange = min(minChange, acW + racE)

print(minChange)

Submission status: Time Limit Exceeded

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

w = []
tempW = 0
for i in range(n):
    if s[i] == 'W':
        tempW += 1
    w.append(tempW)

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

for i in range(n):
    if s[i] == 'W':
        acW = w[i] - 1
        racE = s.count('E') - e[i]
        minChange = min(minChange, acW + racE)
    else:
        acW = w[i]
        racE = s.count('E') - e[i]
        minChange = min(minChange, acW + racE)

print(minChange)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
min = 3*10**5
for i in range(N):
    tmp = S[i+1:].count('E')+S[:i].count('W')
    if tmp < min:
        min = tmp
print(min)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a = s[:i].count("W")
    b = s[i+1:].count("E")
    if turn > a+b:
        turn = a+b
print(turn)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a = s[:i]
    b = s[i+1:]
    stock = a.count("W")+b.count("E")
    if turn > stock:
        turn = stock
print(turn)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a = s[:i]
    b = s[i+1:]
    if turn > a.count("W")+b.count("E"):
        turn = a.count("W")+b.count("E")
print(turn)

Submission status: Time Limit Exceeded

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

for i in range(n):
    res1 = s[0:i].count('W') + s[i+1:n].count('E')
    if res1 < res:
        res = res1

print(res)

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

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

for i in range(n):
    s1 = s[0:i]
    s2 = s[i]
    s3 = s[i+1:n]
    res1 = s1.count('W') + s3.count('E')
    res = min(res,res1)

print(res)

Submission status: Time Limit Exceeded

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

for i in range(n):
    s1 = s[0:i]
    s2 = s[i]
    s3 = s[i+1:n]
    res1 = s1.count('W') + s3.count('E')
    res = min(res,res1)

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
m = n
for i in range(n):
    w = s[:i]
    e = s[i + 1:]
    count = w.count('W') + e.count('E')
    if m > count:
        m = count
print(m)