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: Wrong Answer

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

def calc(idx):
    a = s[:idx]
    b = s[idx+1:]
    return a.count('W') + b.count('E')


result = 3e5

for i in range(n):
    if result < calc(i):
        break
    else:
        result = calc(i)

print(result)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = input()
cw = [] # count W
cw.append(0)
for i, s in enumerate(S):
    i += 1
    if s == "W":
        cw.append(cw[i-1]+1)
    else:
        cw.append(cw[i-1])
#print(cw)

ans = 100000*3
for i in range(N):
    left = cw[i] # num of W
    right = (N-i)-(cw[N]-cw[i]) # num of E
    #print("left: %d, right: %d, %s, %s" % (left,right,S[0:i],S[i+1:N]))
    tmp = left+right
    if ans>tmp:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
str = s[1:]
a = 0
for i in str:
  if i == "E":
    a += 1
b = a

for i in range(n-2):
  if str[i] == "W":
    if str[i+1] == "E":
      continue
    else:
      a += 1 
  else:
    if str[i+1] == "E":
      a -= 1
      if b > a:
        b = a 
      else:
        continue
      
print(b)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
x=len([s for s in S[1:] if s=='E'])
x_min=x

for i in range(1,N):
	if S[i-1]=='W':
		x+=1
	if S[i]=='E':
		x-=1
	if x<x_min:
		x=x_min

print(x_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
cnt = 10E6

if S[:int(N/2)].count("E") > S[int(N/2):].count("W"):
    for i in range(0, int(N/2)):
        w = S[:i].count("W")
        e = S[i:].count("E")
        if cnt > w+e:
            cnt = w+e
else:
    for i in range(int(N/2), N):
        w = S[:i].count("W")
        e = S[i:].count("E")
        if cnt > w+e:
            cnt = w+e

print(cnt)

Submission status: Wrong Answer

Solution code:
def calc(s, i, n):
    tmp = ""
    for j in range(i):
        tmp += s[j]
    ct = 0
    if i != 0:
        for j in tmp:
            if j == 'W':
                ct += 1

    for j in range(i+1, n):
        if s[j] == 'E':
            ct += 1

    return ct

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

ans = calc(S, N//2, N)

for i in reversed(range(N//2)):

    ct = calc(S, i, N)

    if ans > ct:
        ans = ct
    else:
        break

for i in range(N//2 + 1, N):
    ct = calc(S, i, N)
    if ans > ct:
        ans = ct
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
n = input()
nl = list(n)
w = [0 for i in range(len(n))]
e = [0 for i in range(len(n))]
w[0] = 1 if nl[0] == "W" else 0
e[0] = 1 if nl[0] == "E" else 0
for i in range(len(n)-1):
    w[i+1] = w[i] + 1 if nl[i+1] == "W" else w[i]
    e[i+1] = e[i] + 1 if nl[i+1] == "E" else e[i]
wr = [0 for i in range(len(n))]
er = [0 for i in range(len(n))]
ans = [0 for i in range(len(n))]
for i in range(len(n)):
    wr[i] = w[len(n)-1] - w[i]
    er[i] = e[len(n)-1] - e[i]
for i in range(len(n)):
    temp = w[i] - 1 if w[i] > 0 else 0
    ans[i] = temp + er[i]
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = int()
c = list()
#print(n, s)
for ew in s:
  count = 0
  sidx = s.index(ew)
  for i in range(0, sidx):
    if s[i] == 'W':
      count += 1
  for i in range(sidx, n-sidx-1):
    if s[i] != "W":
      count += 1
  c.append(count-1)

print(min(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
str = s[1:]
a = 0
for i in str:
  if i == "E":
    a += 1
b = a

for i in range(len(s)-2):
  if str[i] == "W":
    if str[i+1] == "E":
      continue
    else:
      a += 1 
  else:
    if str[i+1] == "E":
      a -= 1
      if b > a:
        b = a 
      else:
        continue
      
print(b)

Submission status: Wrong Answer

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


def calc(idx):
    a = s[:idx]
    b = s[idx+1:]
    return a.count('W') + b.count('E')


leader = n//2
right = n - 1
left = 0

score = calc(leader)

while True:


    leader = (right + left)//2

    r_score = calc((leader+right)//2)
    l_score = calc((leader+left)//2)

    if r_score <= score:
        score = r_score
        left = leader

    elif l_score <= score:
        score = l_score
        right = leader

    else:
        break

    if right - left <= 1:
        break

print(score)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
x=0
for s in S[1:]:
	if s=='E':
		x+=1

for i in range(1,N):
	newx=x
	if S[i-1]=='W':
		newx+=1
	if S[i]=='E':
		newx+= -1
	if newx<x:
		x=newx

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
direction = list(input())
change = [0]*N
change[0] = direction.count("E")
 
for i in range(1, N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    if direction[i-1] == "W":
        f_p = 1
    change[i] = change[i-1] - f_n + f_p
print(min(change))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = input()
r = dict(Counter(s))
if 'W' not in r:
    r['W'] = 0
if 'E' not in r:
    r['E'] = 0
l = {'W': 0, 'E': 0}
a = 999999
for c in s:
    if c == 'W' and r['W'] > 0:
        l['W'] += 1
        r['W'] -= 1
    if c == 'E' and r['E'] > 0:
        l['E'] += 1
        r['E'] -= 1
    l[c] -= 1
    a = max(1, min(a, l['W'] + r['E']))
    l[c] += 1
print(a)

Submission status: Wrong Answer

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

nswe_count = {"N": 0, "S": 0, "W": 0, "E": 0, }

for nswe in s:
    nswe_count[nswe] += 1

print(nswe_count[min(nswe_count)])

Submission status: Wrong Answer

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

max_num = S[1:].count('W')
pre_num = max_num

for i in range(1, N-1):
    num = pre_num
    if S[i-1] == 'E':
        num += 1
    if S[i] == "W":
        num -= 1

    if num > max_num:
        max_num = num
    pre_num = num

print(N - max_num - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
f = 0
l = 0
fs = s[: int(n / 2)]
ls = s[int(n / 2) + 1:]
mid = s[int(n / 2)]

for i in fs:
    if i == "W":
        f += 1

for i in ls:
    if i == "E":
        l += 1


fres = f + l
for i in reversed(range(0, int(n / 2))):
    tmp = fres
    if mid == "E":
        tmp += 1
    mid = fs.pop(i)
    if mid == "W":
        tmp -= 1
    if tmp > fres:
        break
    fres = tmp

fs = s[: int(n / 2)]
ls = s[int(n / 2) + 1:]
mid = s[int(n / 2)]
lres = f + l
for i in ls:
    tmp = lres
    if mid == "W":
        tmp += 1
    mid = ls.pop(0)
    if mid == "E":
        tmp -= 1
    if tmp > lres:
        break
    lres = tmp

print(min([fres, lres]))

Submission status: Wrong Answer

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

ans = 3 * 10**5
w = [0]
e = [0]

for i, a in enumerate(s):
    if a == 'W':
        w.append(w[-1]+1)
    else:
        w.append(w[-1])

for i, a in enumerate(s[::-1]):
    if a == 'E':
        e.append(e[-1]+1)
    else:
        e.append(e[-1])

e.reverse()

for i in range(n):
    ans = min(ans, w[i]+e[i])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from numpy import cumsum
n = int(input())
s = input()
def conv(i):
    if i == 'E': return 0
    return 1
s2 = [conv(i) for i in s]
cum = cumsum(s2)
ans = 0
for i in range(n):
    a = cum[i]
    b = cum[-1]
    ans = max(ans,b-a)
print(ans-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 10**3
for i in range(n):
	if s[i] == "W":
		count = 0
		a = s[:i]
		b = s[i:]
		ac = a.count("W")
		bc = b.count("E")
		count = ac + bc
		if count <= ans:
			ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
direction = list(input())
change = [0]*N
change[0] = direction.count("E")
 
for i in range(1, N):
    f_n = 0
    f_p = 0
    if direction[i] == "W":
        f_n = 1
    if direction[i-1] == "E":
        f_p = 1
    change[i] = change[i-1] + f_n - f_p
    # print(left,right)
print(min(change))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    w = 0
    e = 0
    r = [0]*n
    r[0] = s[1:].count('E')
    for i in range(n-1):
        r[i+1] = r[i]
        if s[i] == 'W':
            r[i+1] += 1
        if s[i] == 'E':
            r[i+1] -= 1
    print(min(r))
main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = list(input())
    w = 0
    e = 0
    r = [0]*n
    r[0] = s[1:].count('E')
    for i in range(n-1):
        r[i+1] = r[i]
        if s[i] == 'W':
            r[i+1] += 1
        if s[i] == 'E':
            r[i+1] -= 1
        print(r[i+1], i+1)
    print(min(r))
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
num = S.count('E')
min_num = num
for i in range(N-1):
    if S[i]=='W':
        num += 1
    if S[i+1]=='E':
        num -= 1
    min_num = num if min_num > num else min_num
print(min_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
num = S.count('E')
min_num = num
for i in range(N-1):
    if S[i]=='W':
        num += 1
    if S[i+1]=='E':
        num -= 1
    min_num = num if min_num > num else min_num
    print(i, num)
print(min_num)

Submission status: Wrong Answer

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

S = S.rstrip('W')
S = S.lstrip('E')

res = len(S)
for i in range(1, len(S)):
    cnt = S[:i - 1].count('W')
    cnt += S[i:].count('E')
    if cnt < res:
        res = cnt

print(res)

Submission status: Wrong Answer

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


print(abc098_c())

Submission status: Wrong Answer

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

e_count = S.count('E')
w_count = S.count('W')

# print(e_count)
# print(w_count)


left_w = 0
right_e = e_count
min_cost = len(S)-1

for i in range(len(S)):
    if i > 0:
        if S[i-1] == 'W':
            left_w += 1
        else:
            right_e -= 1
    cost = left_w + right_e
    if cost < min_cost:
        min_cost = cost

print(min_cost)

Submission status: Wrong Answer

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

for i in range(n):
   if i == 0:
      cnt = n - s.count(s[i])
#      print(cnt)
   if i == n -1:
      cnt = n - s.count(s[i])
#      print(cnt)
   else: 
      a = s[:i]
      b = s[i:]
      a_cnt = a.count(s[i])
      b_cnt = len(b) - b.count(s[i])
      cnt = a_cnt + b_cnt
#      print(cnt)
   min_c = min(min_c, cnt)

print(min_c)

Submission status: Wrong Answer

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

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	elif i!=0:
		num-=1
	score_list.append(num)
	
print min(score_list)

Submission status: Wrong Answer

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

a = []
count = 0

for i in range(n):
    if s[i] == "W":
        a.append(count)
    else:
        count += 1
        a.append(count)

num = 10**6

for i in range(n):
    if i == 0:
        num = a[n-1] - a[0]
    else:
        num = min(num, (a[n - 1] - a[i]) + (i - (a[i - 1] - a[0])))


print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
w = 0
e = 0

lw = 0
le = 0

for i in range(len(S)):
    if S[i] == "W":
        w+= 1
    else:
        e+= 1

min = 100000000
for i in range(len(S)):
    temp = 0
    if S[i] == "W":
        temp = lw+e
        lw+=1
        w-=1
    else:
        temp = lw+e
        le +=1
        e -= 1
    if temp<min:
        min = temp


print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(input())
X = 100000000
for i in range(N):
    x = (P[:i].count("W")+P[i+1:].count("E"))
    if x < X:
        X = x
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(input())
X = 0
for i in range(N):
    x = (P[:i].count("W")+P[i+1:].count("E"))
    if x > X:
        X = x
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
w = 0
e = 0

lw = 0
le = 0

for i in range(len(S)):
    if S[i] == "W":
        w+= 1
    else:
        e+= 1

min = 1000000
for i in range(len(S)):
    temp = 0
    if S[i] == "W":
        temp = lw+e
        lw+=1
        w-=1
    else:
        temp = lw+e
        le +=1
        e -= 1
    if temp<min:
        min = temp


print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
res = 1000000
prev_W = 0
prev_E = S.count('E')
for c in S:
    prev_W += c.count('W')
    prev_E -= c.count('E')
    res = min(res,prev_W + prev_E)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
w = 0
e = 0

lw = 0
le = 0

for i in range(len(S)):
    if S[i] == "W":
        w+= 1
    else:
        e+= 1

min = 1000000
for i in range(len(S)):
    temp = 0
    if S[i] == "W":
        temp = lw+e
        lw+=1
        w-=1
    else:
        temp = lw+e
        le +=1
        e -= 1
    if temp<min and temp!= 0:
        min = temp

print(min)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
q = raw_input()

etow = []
wtoe = []

nowe = 0
noew = 0

for a in range( len(q) ):
  etow.append(noew)
  wtoe.append(nowe)
  if q[a] == "W":
    nowe += 1
  if q[len(q) - 1 - a] == "E":
    noew += 1

wtoe = wtoe[::-1]
mi = 99999

for a in range( len(q) ):
  if etow[a] + wtoe[a] < mi:
    mi = etow[a] + wtoe[a]
print mi

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
min_num = 3e5
for i in range(N):
    num = S[:i].count('W') + S[i:].count('E')
    min_num = num if min_num > num else min_num
    print(i, num)
print(min_num)

Submission status: Wrong Answer

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

sum = 0
for i in range(len(S)):
    if S[i] == 'E':
        sum += 1
min = sum

for i in range(1,len(S)):
    if S[i] == 'E':
        sum -= 1
    if S[i-1] == 'W':
        sum += 1
    if min > sum:
        min = sum
print(min)

Submission status: Wrong Answer

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

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	else:
		num-=1
	score_list.append(num)
print min(score_list)

Submission status: Wrong Answer

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

count_E = [0]
count_W = [0]

for s in S:
    if s == 'E':
        count_E.append(count_E[-1] + 1)
        count_W.append(count_W[-1])
    else:
        count_E.append(count_E[-1])
        count_W.append(count_W[-1] + 1)

ans = 10**6

for i in range(N):
    rotate_left = count_W[i]
    rotate_right = count_E[-1] - count_E[i]
    total = rotate_left + rotate_right
    if total < ans:
        ans = total

print(ans)

Submission status: Wrong Answer

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

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-2):
	if S[i+1]=='W':
		num+=1
	else:
		num-=1
	score_list.append(num)
print min(score_list)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
w = 0
e = 0

lw = 0
le = 0

for i in range(len(S)):
    if S[i] == "W":
        w+= 1
    else:
        e+= 1

min = 1000000
for i in range(len(S)):
    temp = 0
    if S[i] == "W":
        temp = lw+e
        lw+=1
        w-=1
    else:
        temp = le+w
        le +=1
        e-=1
    if temp<min:
        min = temp

print(min)

Submission status: Wrong Answer

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

num = S.count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	else:
		num-=1
	score_list.append(num)
print min(score_list)

Submission status: Wrong Answer

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

num = float("inf")
for i in range(n):
    if i == 0:
        num = min(num, E[n - 1] - E[i + 1])
    elif i == n - 1:
        num = min(num, W[i - 1])
    else:
        num = min(num, E[n - 1] - E[i + 1] + W[i - 1])

print(num)

Submission status: Wrong Answer

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

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

print(min_ans)

Submission status: Wrong Answer

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

ans = n

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

Submission status: Wrong Answer

Solution code:
N = int(input())

s = input()

e = s.count('E')
w = s.count('W')

if e > w:
  num = w - 1
else:
  num = e - 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l = [0]*n
for i in range(n):
  if s[i] == "E":
    for j in range(i+1,n):
      l[j] += 1
  else:
    for j in range(0,i):
      l[j] += 1
c = max(l)
index = l[c]
ans = s[0:index].count("W") + s[index+1:n].count("E")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def turn(curr, A, B):
  count = 0
  count += A.count('W')
  count += B.count('E')
  
  return count

N = int(input())
S = list(input())
res = []
for i in range(0, N):
  A = S[:i]
  B = S[i + 1:]
  curr = S[i]
  res.append(turn(curr, A, B))

print(min(res))

Submission status: Time Limit Exceeded

Solution code:
def turn(curr, A, B):
  count = 0
  for a in A:
    if a != 'E':
      count += 1
  
  for b in B:
    if b != 'W':
      count += 1
  
  return count

N = int(input())
S = list(input())
res = []
for i in range(0, N):
  A = S[:i]
  B = S[i + 1:]
  curr = S[i]
  res.append(turn(curr, A, B))

print(min(res))

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:
import collections
n = int(input())
s = input()
s_list = list(s)
ans_list = []

for i in range(n):
    before_list = s[:i]
    after_list = s[i+1:]
    cnt_before = collections.Counter(before_list)
    cnt_after = collections.Counter(after_list)
    ans_list.append(cnt_before['W'] + cnt_after['E'])

print(min(ans_list))

Submission status: Time Limit Exceeded

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

for _ in range(n):
    if s[_] == "E":
        s[_] = -1
    else:
        s[_] = 1

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

print(min(ans_list) + (sum(s)-n)//(-2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
e_count = s[1:].count('E')
ans_list = []

for _ in range(n):
    if s[_] == "E":
        s[_] = -1
    else:
        s[_] = 1

for i in range(n):
    ans_list.append(sum(s[:i])+e_count)

print(min(ans_list))

Submission status: Time Limit Exceeded

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

for i in range(n):
    ce = s[i+1:].count('E')
    cw = s[:i].count('W')
    cnt = ce + cw
    list_count.append(cnt)

print(min(list_count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
a = "q"
b = 0
 
for i in range(n):
    e = s.count('W', 0, i)
    w = s.count('E', i+1)
    b = e + w
    if a == "q":
      a = b
    else:
      pass
    if a > b:
      a = b
    else:
      pass
    
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
a = 300000
b = 0
 
for i in range(n):
    e = s.count('W', 0, i)
    w = s.count('E', i+1)
    b = e + w
    if a > b:
      a = b
    else:
      pass
    
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
a = 3 * (10**5)
b = 0

for i in range(n):
    e = s.count('W', 0, i)
    w = s.count('E', i+1)
    b = e + w
    if a > b:
      a = b
    else:
      pass
    
print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
mn=N
for i in range(N):
    lw=s[:i].count("W")
    re=s[i+1:].count("E")
    sm=lw+re
    if mn>sm:
        mn=sm
print(mn)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
mn=N
for i in range(N):
    lw=s[:i].count("W")
    re=s[i+1:].count("E")
    sm=lw+re
    if mn>sm:
        mn=sm
print(mn)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
mn=N
for i in range(N):
    lw=s[:i].count("W")
    re=s[i+1:].count("E")
    sm=lw+re
    mn=min(mn,sm)

print(mn)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    for i in range(N):
        cnt = S[:i].count("W") + S[i + 1:].count("E")
        if cnt < ans:
            ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#
# abc096 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
WEEWW"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """12
WEWEWEEEWWWE"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
WWWWWEEE"""
        output = """3"""
        self.assertIO(input, output)


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

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

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=list(s)
li=[]
for i in l:
    if i=="W":
        li.append(1)
    else:
        li.append(0)
out=n
for i in range(n):
    o=0
    o+=sum(li[:i])
    o+=len(li[i+1:])-sum(li[i+1:])
    if o< out :
        out=o
print(out)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = []
for i in range(n):
  res = 0
  if 1<=i<=n-2:
    for j in range(i):
      if s[j] == 'W':
        res += 1
    for k in range(i+1, n):
      if s[k] == 'E':
        res += 1
    ans.append(res)
    
  
  elif i == 0:
    if s[0] == 'E':
      res = s.count('E')-1
    else:
      res = s.count('E')
    ans.append(res)
      
  elif i == n-1:
    if s[n-1] == 'W':
      res = s.count('W')-1
    else:
      res = s.count('W')
    ans.append(res)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
left = s[0]
ans = 10**6
for i in range(1,n):
    right = s[i:]
    count_w = 0
    for j in range(i-1):
        if s[j]=='W':
            count_w += 1
    count_e = 0
    for j in range(len(right)):
        if right[j]=='E':
            count_e += 1
    #print(i,count_w,count_e)
    ans = min(ans,count_w+count_e)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = input()
ans = float('inf')
e = int(s.count('E'))

for i in range(n):
    a = Counter(s[:i])['W']
    b = e - (i-a)

    ans = min(ans, a + b)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = input()
ans = float('inf')

for i in range(n):
    a = Counter(s[:i])
    b = Counter(s[i+1:])

    ans = min(ans, a['W'] + b['E'])

print(ans)

Submission status: Time Limit Exceeded

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

ans = N

for n in range(N):
  if n == 0:
    ans = min(ans,S[1:].count("E"))
  elif n == N-1:
    ans = min(ans,S[:n].count("W"))
  else:
    left_W = S[:n].count("W")
    right_E = S[n:].count("E")
    ans = min(ans,left_W + right_E)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

counts = []
for i in range(N):
    count = 0
    for j in range(i):
        if S[j] != "E":
            count += 1
    for j in range(i+1, N):
        if S[j] != "W":
            count += 1
    counts.append(count)

print(min(counts))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = 'E' + input() + 'W'
res, point= N, 0

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

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
s = list(input())
l, r = [], []
ans = math.inf
for i in range(n):
    l = s[:i]
    r = s[i + 1 :]
    ans = min(ans, l.count("W") + r.count("E"))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
ans = 10 ** 10
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())
a = list(input())
cnt,box = 0,[]
for i in range(n):
  l = a[:i]
  r = a[i+1:]
  cnt = l.count("W") + r.count("E")
  box.append(cnt)
print(min(box))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mi = 10000000
for i in range(N):
    f1 = S[0:i]
    f2 = S[i+1:]
    K = f1.count('W')+f2.count('E')
    if K <= mi:mi=K
print(mi)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,S=open(0).read().split()
N=int(N)
ans=N
for i in range(N):
    change=S[:i].count('W')
    change+=S[i+1:].count('E')
    if ans>change:
        ans=change
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,S=open(0).read().split()
clist=[]
for i in range(int(N)):
    change=S[:i].count('W')
    change+=S[i+1:].count('E')
    clist.append(change)
print(min(clist))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()

ans = n

for i in range(n):
    #Lより西にいて西を向いている人の数
    w = s[: i].count("W")

    #Lより東にいて東を向いている人の数
    e = s[i + 1 :].count("E")

    ans = min(ans, w + e)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
List = [0]*N
for i in range(N):
  if S[i]=="E":
    for j in range(i):
      List[j] += 1
  else:
    for j in range(i+1, N):
      List[j] += 1
print(min(List))

Submission status: Time Limit Exceeded

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