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

EW = [] # 「EW」となっている部分のEの座標
if S[0] == "W":
    EW.append(-1)
for i in range(N-1):
    if S[i]=="E" and S[i+1]=="W":
        EW.append(i)
if S[N-1] == "E":
    EW.append(N-1)

ans = 1000000
for ew in EW:
    cnt = 0
    for j in range(0, ew):
        if S[j] == "W":
            cnt += 1
    for k in range(ew+2, N):
        if S[k] == "E":
            cnt += 1
    if ans > cnt:
        ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:


def main():


   N = int(input())
   seList = input()
   ans = len(seList)
   tmp = ans

   for i in range(N):
      tmp = seList[:i].count('W')+seList[i:].count('E')
      if tmp < ans:
         ans = tmp
   print(ans)







if __name__== "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
res = 99999999999999999999999999999999

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

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

print(res)

Submission status: Time Limit Exceeded

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

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

print(min(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count = 3 * 10 ** 5
for i in range(N):
    count_tmp = 0
    count_tmp += S[:i].count("W")
    count_tmp += S[i+1:].count("E")
    count = min(count, count_tmp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
count = 3 * 10 ** 5
for i in range(N):
    count_tmp = 0
    for j in range(N):
        if j < i:
            if S[j] != "E":
                count_tmp += 1
        elif j > i:
            if S[j] != "W":
                count_tmp += 1
    count = min(count, count_tmp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
#ABC 098 C Attention

n = int(input())
s = input()
cnt = 0
cnt_list = []

for i in range(n):
    for j in range(i):
        if s[j] == "W":
            cnt += 1
    for k in range(i+1,n):
        if s[k] == "E":
            cnt +=1
    cnt_list.append(cnt)
    cnt = 0
print(min(cnt_list))

Submission status: Time Limit Exceeded

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


"""考え方
「右側のE」+「左側のW」の合計が一番小さくなるインデックスを探索する。
"""

ans = 10**6
## 西の端から東に向かって確認していく
for n in range(0,N):
  cnt = S[:n].count('W') + S[n:].count('E')
  ans = min(ans,cnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc098/tasks/arc098_a
# C - Attention
import collections

N = int(input().split()[0])
S = input().split()[0]
min_c = float('inf')
for i in range(N):
    w_side = S[:i]
    counter = collections.Counter(w_side)
    c = counter['W']

    if i < N - 1:
        e_side = S[i+1:]
        counter = collections.Counter(e_side)
        c += counter['E']
    min_c = min(min_c, c)

print(min_c)

Submission status: Time Limit Exceeded

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

ans = n
for i in range(1,n):
  w = s[:i - 1].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()
s = list(s)

for i in range(n):
  if s[i] == 'E':
    s[i] = 1
  else:
    s[i] = 0

count_max = 3*10**5
for i in range(n):
  count_temp = i - sum(s[:i])
  count_temp += sum(s[i+1:])
  if count_temp < count_max:
    count_max = count_temp
print(count_max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count_min = 3*10**5
for i in range(n):
  count = 0
  if i == 0:
    pass
  else:
    for j in range(i):
      if s[j] == 'W':
        count += 1
  if i == n:
    pass
  else:
    for j in range(i+1,n):
      if s[j] == 'E':
        count += 1
  if count < count_min:
    count_min = count
print(count_min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S = input()
ans = []
for i in range(N+1):
    ans.append(S[0:i].count('W') + S[i + 1:N + 1].count('E'))
print(str(min(ans)))

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
S = list(input())
ans = []
for i in range(N+1):
    ans.append(S[0:i].count('W') + S[i + 1:N + 1].count('E'))
print(str(min(ans)))

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
direct = list(input())
ary = [0 for i in range(nums)]

for i in range(nums):
    count = 0
    for x in range(nums):
        if x < i and direct[x] == "W":
            count += 1
        elif x > i and direct[x] == "E":
            count += 1
    ary[i] = count

print(min(ary))

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
direct = list(input())
max = 0

for i in range(nums):
    count = 0
    for x in range(nums):
        if x == i: continue
        if x < i  and direct[x] == "E":
            count += 1
        elif i < x and direct[x] == "W":
            count += 1

    if count > max:
        max = count
print(nums - max-1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
sum_w = s.count("W")
ans = n
for i in range(n):
    left_w = s[:i].count("W")
    right_e = (n-i-1)-(sum_w-left_w)
    if s[i] == "W":
        right_e += 1
    sum = left_w+right_e
    if sum < ans:
        ans = sum
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = []
for i in range(n):
    ans.append(s.count('W', 0, i) + s.count('E', i+1, n))
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+1:].count('E') )
print(sorted(ans)[0])

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    left = s[:i].count('W')
    right = s[i+1:].count('E')
    ans.append(left+right)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=['x']+list(input())+['x']
ans = 3*10**5
for i in range(1,n):
    s1=s[:i]
    s2=s[i+1:]
    cnt = s1.count('W')+s2.count('E')
    ans=min(ans,cnt)
print(ans)

Submission status: Time Limit Exceeded

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

P = []

for i in range(N):
    l = S[:i]
    if i+1 < N:
        r = S[i+1:]

    tmp = l.count('W') + r.count('E')
    P.append(tmp)

print(min(P))

Submission status: Time Limit Exceeded

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

    cnt = float('inf')
    for i in range(N):
        tmp = S[:i].count("W") + S[i+1:].count("E")
        if cnt > tmp:
            cnt = tmp

    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
import collections

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

ans = N
for i in range(1, len(S)):
  n = 0
  if (i == 1):
    right = collections.Counter(S[i:])
    if 'E' in dict(right).keys():
      n = dict(right)['E']
  elif (i > 1 and i < len(S)):
    left = collections.Counter(S[:i-1])
    right = collections.Counter(S[i:])
    if 'W' in dict(left).keys():
      n += dict(left)['W']
    if 'E' in dict(right).keys():
      n += dict(right)['E']
  else:
    left = collections.Counter(S[:i-1])
    if 'W' in dict(left).keys():
      n = dict(left)['W']
  if (n < ans):
    ans = n
print(ans)

Submission status: Time Limit Exceeded

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


for i in range(n):
	for j in range(n):   
		if s[i-1-j:i-j] == "W" and i-1-j>=0:
			count[i] += 1
		if s[i+1+j:i+2+j] == "E" and i+2+j<=n+1:
			count[i] += 1

print(min(count))

Submission status: Time Limit Exceeded

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

for i in range(n):
    num = S[:i].count('W') + S[i+1:].count('E')
    if num < ans:
        ans = num
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
s = input()
stransform = np.zeros(n)
for i in range(n):
    if s[i] == "E":
        stransform[i] = 1
    else:
        stransform[i] = -1

max_num = n-1
max_tmp = 0
for i in range(n):
    tmp = np.sum(stransform[0:i]) - np.sum(stransform[i+1:])
    if tmp > max_tmp:
        max_tmp = tmp
Out = int((max_num-max_tmp)/2)
print(Out)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
s = input()
stransform = np.zeros(n)
for i in range(n):
    if s[i] == "E":
        stransform[i] = 1
    else:
        stransform[i] = -1

max_num = n-1
max_tmp = 0
for i in range(n):
    tmp = sum(stransform[0:i]) - sum(stransform[i+1:])
    if tmp > max_tmp:
        max_tmp = tmp
Out = int((max_num-max_tmp)/2)
print(Out)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
stransform = [0]*n
for i in range(n):
    if s[i] == "E":
        stransform[i] = 1
    else:
        stransform[i] = -1

max_num = n-1
max_tmp = 0
for i in range(n):
    tmp = sum(stransform[0:i]) - sum(stransform[i+1:])
    if tmp > max_tmp:
        max_tmp = tmp
Out = int((max_num-max_tmp)/2)
print(Out)

Submission status: Time Limit Exceeded

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

ans = N
a = N

for i in range(0,N-1):
    X = S[:i]
    Y = S[i+1:]
    nW = Y.count('E')
    nE = X.count('W')
    
    a = nW + nE

    if a < ans:
        ans = a
    a = 0

print(ans)

Submission status: Time Limit Exceeded

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

ans = N
a = N

for i in range(0,N):
    X = S[:i]
    Y = S[i+1:]
    nW = Y.count('E')
    nE = X.count('W')
    
    a = nW + nE

    if a < ans:
        ans = a
    a = 0

print(ans)

Submission status: Time Limit Exceeded

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

ans = 3*10**5
for i in range(N):
    cnt = 0
    # 基準より左側の人
    for j in range(i):
        if S[j] == "W":
            cnt += 1
    # 基準より右側の人
    for k in range(1,N-i):
        if S[i+k] == "E":
            cnt += 1
    if ans > cnt:
        ans = cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = N+1
for i in range(1, N):
    pre = S[0:i-1]
    back = S[i:N]
    #print(pre,back)
    #print(list(pre_and_back))
    ans = min(ans,(pre.count('W') + back.count('E')))

print(ans)

Submission status: Time Limit Exceeded

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

s_list = list(s)

sum_list = []
for i in range(n):
    sum_list.append(s_list[:i].count('W') + s_list[i+1:].count('E'))

print(min(sum_list))

Submission status: Time Limit Exceeded

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

ans = 300001
for i in range(n):
    people = s[:i].count('W') + s[i+1:].count('E')
    if ans > people:
        ans = people

print(ans)

Submission status: Time Limit Exceeded

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

s_list = list(s)

ans = 300001
for i in range(n):
    people = s_list[:i].count('W') + s_list[i+1:].count('E')
    if ans > people:
        ans = people

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    people = input()
    return min([people[:i].count("W") + people[i + 1:].count("E") for i in range(n)])


if __name__ == "__main__":
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = n
for i in range(n):
    grp1 = s[:i]
    grp2 = s[i+1:]
    cnt = grp1.count('W') + grp2.count('E')
    if cnt < ans:
        ans = cnt
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

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

count = sys.maxsize

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

print(count)

Submission status: Time Limit Exceeded

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

# print(N, S)
ans = N

f = S[0]
s = S[1:]

nw = 0
ne = 0

for w in s:
    if w != 'W':
        ne += 1

ans = nw+ne
for i in range(1, N):
    # skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(i, f, l, s)
    # nw = f.count('W')
    # ne = s.count('E')
    # print(nw, ne)

    if S[i-1] != 'E':
        nw += 1

    if S[i] != 'W':
        ne -= 1
    # print(nw, ne)
    ans = min(ans, nw+ne)

print(ans)

Submission status: Time Limit Exceeded

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

# print(N, S)
ans = N

f = S[0]
s = S[1:]

nw = 0
ne = 0

for w in s:
    if w != 'W':
        ne += 1

for i, h in enumerate(range(N)):
    skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(f, l, s)
    # nw = f.count('W')
    # ne = s.count('E')
    # print(nw, ne)

    if i-1 >= 0:
        if S[i-1] != 'E':
            nw += 1

    if S[i] != 'W':
        ne -= 1
    # print(nw+ne)
    ans = min(ans, nw+ne)

print(ans)

Submission status: Time Limit Exceeded

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

# print(N, S)
ans = N

for i, h in enumerate(range(N)):
    skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(f, l, s)
    nw = 0
    ne = 0
    # nw = f.count('W')
    # ne = s.count('E')
    # print(nw, ne)
    for r in f:
        if r != 'E':
            nw += 1
            if nw >= ans:
                skipflg = True
                break
            # print('not e')

    if skipflg:
        # print('break 1')
        continue

    for w in s:
        if w != 'W':
            ne += 1
            if nw+ne >= ans:
                skipflg = True
                break
            # print('not w')

    if skipflg:
        # print('break 2')
        continue

    ans = min(ans, nw+ne)

print(ans)

Submission status: Time Limit Exceeded

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

# print(N, S)
ans = N

for i, h in enumerate(range(N)):
    skipflg = False
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(f, l, s)
    nw = 0
    ne = 0
    nw = f.count('W')
    ne = s.count('E')
    # print(nw, ne)
    # for r in f:
    #     if r != 'E':
    #         nw += 1
    #         if nw >= ans:
    #             skipflg = True
    #             break
    #         # print('not e')

    # if skipflg:
    #     break

    # for w in s:
    #     if w != 'W':
    #         ne += 1
    #         if nw+ne >= ans:
    #             skipflg = True
    #             break
    #         # print('not w')

    # if skipflg:
    #     break

    ans = min(ans, nw+ne)

print(ans)

Submission status: Time Limit Exceeded

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

# print(N, S)
ans = N
for i, h in enumerate(range(N)):
    f = S[0: i]
    l = S[i]
    s = S[i+1:]
    # print(f, l,  s)
    nw = 0
    ne = 0
    for r in f:
        if r != 'E':
            nw += 1
            # print('not e')

    for w in s:
        if w != 'W':
            ne += 1
            # print('not w')

    ans = min(ans, nw+ne)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 10 ** 6

for i in range(n-1):
    left = s[: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 = [i for i in input()]

ans = 10 ** 6

for i in range(n-1):
    left = s[: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 = str(input())
ans = N
for i in range(N):
    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 = 10**6
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 = 0

for i in range(1,n+1):
    west_count=s[i:].count("E")
    east_count=s[:i-1].count("W")
    if west_count+east_count < ans or ans == 0:
        ans = west_count+east_count
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

S = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

cnt = []
cnt.append(s[1:].count("E"))
cnt.append(s[:n].count("W"))
for i in range(1, n-1):
    a = s[:i].count("W")
    b = s[i+1:].count("E")
    cnt.append(a+b)
print(min(cnt))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

cnt = []
for i in range(1, n-1):
    if i <= 1:
        a = s[i:].count("E")
    elif i+1 >= n:
        a = s[:i+1].count("W")
    else:
        a = s[:i].count("W")+s[i+1:].count("E")
    cnt.append(a)
print(min(cnt))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 1e6
for i in range(len(s)):
    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()
res = []
for i in range(N):
    count = S[:i].count("W")
    count += S[i+1:].count("E")
    res.append(count)
print(min(res))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 99999999

for i in range(N):
    cnt_w = 0
    cnt_e = 0
    for j in range(i):
        if S[j] == 'W':
            cnt_w += 1
    for j in range(i,N):
        if S[j] == 'E':
            cnt_e += 1
    ans = min(ans, cnt_w + cnt_e)
print(ans)

Submission status: Time Limit Exceeded

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

ans = 99999999

for i in range(N):
    # print(S[:i].count('W'))
    # print(S[i:].count('E'))
    # print("---------")
    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()

sum_list = []

for i in range(n):
    if i == 0:
        sum_list.append(s[i + 1:].count('E'))
    elif i == n - 1:
        sum_list.append(s[:i].count('W'))
    else:
        sum_list.append(s[:i].count('W') + s[i + 1:].count('E'))

print(min(sum_list))

Submission status: Time Limit Exceeded

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


w = S.count('W')
e = N-w
ans = 10**9
for i in range(N):
    tmp = S[0:i].count('W')
    ans = min(e+2*tmp+(S[i]=='W')*1-i-1, ans)
    
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
S = np.array([0 if a == 'E' else 1 for a in input()])

ans = N
for i in range(N):
    ans = min(ans, np.count_nonzero(S[:i]) + np.count_nonzero(S[i+1:]-1))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n  = int(input())

st = input()
num  = []
for i in st:
  if i == "E":
    num.append(1)
  else:
    num.append(0)

mans = 100000000
for i in range(n):
  tmp = i  - sum(num[0:i]) + sum(num[i+1:n])
  
  if tmp<mans:
    mans = tmp
print(mans)
  







"""
upper_bound = n
lower_bound = 0

while upper_bound - lower_bound > 0:
  middle = (upper_bound+ lower_bound) // 2
"""

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i>0 and i< n-1:
        m = s[:i+1].count("W") + s[i+1:].count("E")
    elif i == 0:
        m = s[1:].count("E")
    elif i == n-1:
        m = s[:n-2].count("W")
    ans = min(ans,m)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
count = []
for i in range(n):
  c = 0
  for j in range(n):
    if j < i:
      if s[j] == "W":
        c += 1
    elif i < j:
      if s[j] == "E":
        c += 1
  count.append(c)
print(min(count))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=n
for i in range(n):
    #i番目（0〜N-1）の人をリーダーにする
    
    #リーダの左で向きを変える人数(もともと西を向いてて、東に向き直らなければいけない人数)
    left_num=s[:i].count("W")
    
    #リーダの右で向きを変える人数(もともと東を向いてて、西に向き直らなければいけない人数）
    right_num=s[i+1:].count("E")
    
    num=left_num+right_num
    
    #ansを更新
    ans=min(ans,num)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC98 C

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

x = [1 if s[i] == 'W' else 0 for i in range(n)]
y = [1 if s[i] == 'E' else 0 for i in range(n)]

mi = float('inf')
for i in range(n):
    a = sum(x[:i])
    b = sum(y[i+1:])
    mi = min(mi,a+b)
print(mi)

Submission status: Time Limit Exceeded

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

for i in range(n):
    ans[i] = s[:i].count('W') + s[i:].count('E')

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 10**9 + 10

for i in range(n):
    west = s[:i].count('W')
    east = s[i:].count('E')
    if west + east < ans:
        ans = west + east

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
result=3*(10**5)
for i in range(n-1):
	result=min(result,s[:i].count('W')+s[(i+1):].count('E'))
print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

tmp = N
for i in range(N):
    count_E = Counter(S[: i])['W']
    count_W = Counter(S[i + 1:])['E']
    if count_E + count_W < tmp:
        tmp = count_E + count_W
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

ans_list = [0] * N
for i in range(N):
    count_E = Counter(S[: i])['W']
    count_W = Counter(S[i + 1:])['E']
    ans_list[i] = count_E + count_W
print(min(ans_list))

Submission status: Time Limit Exceeded

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

    ans = 10e6
    calc = 0
    for i in range(N):
        s = S[i]
        calc = S[:i].count('W') + S[i+1:].count('E')
        if calc < ans:
            ans = calc
    print(ans)

resolve()

Submission status: Time Limit Exceeded

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

min = n
for i in range(n):
    count = 0
    for j in range(n):
        if j == i:
            continue
        elif ((j < i and s[j] != "E")
            or (j > i and s[j] != "W")):
            count += 1
        if count > min:
            break
    if count < min:
        min = count

print(min)

Submission status: Time Limit Exceeded

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

min = n
for i in range(n):
    count = 0
    for j in range(n):
        if j == i:
            continue
        elif ((j < i and s[j] != "E")
            or (j > i and s[j] != "W")):
            count += 1
    if count < min:
        min = count

print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


n = int(input())
s = "z" + input() + "z"


ans = float("INF")
for i in range(1, n+1):
    leader = s[i]
    w = list(s[1:i])
    e = list(s[i+1::])
    cnt_w2e = Counter(w)
    cnt_e2w = Counter(e)
    change = cnt_w2e["W"] + cnt_e2w["E"]
    ans = min(change, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
d = []  # l,r詰める
sum = []

for i in range(n):
    left = 0
    right = 0
    for j in range(n):
        if j == i:
            continue
        elif j < i and s[j] == 'W':
            left += 1
        elif j > i and s[j] == 'E':
            right += 1
            
    d.append([left, right])
    sum.append(left+right)

print(min(sum))

Submission status: Time Limit Exceeded

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

ans=10**6
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 = str(input())
lst_ans=[]
lst_e = []
lst_w = []
for i in range(n):
    lst_e.append(s[:i+1].count("E"))
    lst_w.append(s[:i+1].count("W"))
for i in range(n):
    if i == 0:ans = lst_e[n-1]
    else:ans = (lst_w[i-1]+lst_e[n-1]-lst_e[i])
    lst_ans.append(ans)
print(min(lst_ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = float('inf')
for i in range(len(S)):
    cnt = 0
    Right = S[i+1:]
    Left = S[:i]
    cnt += Right.count('E')  #右にいて東を向いている人の数
    cnt += Left.count('W')  #左にいて西を向いている人の数
    if cnt >= ans:
        continue
    
    ans = cnt

print(ans)

Submission status: Time Limit Exceeded

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

ans = float('inf')
for i in range(len(S)):
    cnt = 0
    Right = S[i+1:]
    Left = S[:i]
    cnt += Right.count('E')  #右にいて東を向いている人の数
    cnt += Left.count('W')  #左にいて西を向いている人の数
    
    ans = min(ans, cnt)

print(ans)

Submission status: Time Limit Exceeded

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

countlist = []
for leader in range(n):
  count = 0

  for l in s[:leader]:
    if l == "W" :
      r = "E"
      count += 1
  for r in s[leader+1:]:
    if r == "E" :
      r = "W"
      count += 1
  countlist.append(count)  

print(min(countlist))

Submission status: Time Limit Exceeded

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

left = 0
right = 0

countlist = []
for leader in range(n):
    count = 0
   # print(s[num])
    for l in s[:leader]:
        if l == "W" :
            r = "E"
            count += 1
    for r in s[leader+1:]:
        if r == "E" :
            r = "W"
            count += 1
    #print(leader, count)
    countlist.append(count)  

print(min(countlist))

Submission status: Time Limit Exceeded

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

countlist = []

for i in range(n):
  count1 = S[:i].count("W")
  count2 = S[i+1:].count("E")
  count_tem = count1+count2
  countlist.append(count_tem)
  
an = min(countlist)
print(an)

Submission status: Time Limit Exceeded

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

countlist = []

for i in range(n):
  count1 = S[:i].count("W")
  count2 = S[i+1:].count("E")
  count_tem = count1+count2
  countlist.append(count_tem)
  
an = min(countlist)
print(an)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n=int(input())
    s=list(input())
    mn=n
    for i in range(n):
        lw=s[:i]
        le=s[i+1:]
        turn=lw.count('W')+le.count('E')
        mn=min(mn,turn)

    print(mn)
resolve()

Submission status: Time Limit Exceeded

Solution code:
# 入力
N = input()

A1 = input()

total = float('INF')
for i in range(int(N)):
    tmpW = A1[:i].count('W')
    tmpE = A1[i+1:].count('E')
    tmp = tmpW + tmpE
    if(total > tmp):
        total = tmp
print(total)

Submission status: Time Limit Exceeded

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

ans = N
for i in range(N):
    cnt = len([1 for d in S[: max(i-1, 0)] if not d == 'E']) + len([1 for d in S[min(i+1, N-1):] if not d == 'W'])
    if ans > cnt: ans = cnt
print(ans)

Submission status: Time Limit Exceeded

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

ans = 300000
lst = []
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 = input()

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

Submission status: Time Limit Exceeded

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

li = []

for i in range(len(s)):
    li.append(s[:i].count("W")+s[i+1:].count("E"))

print(min(li))