Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

left = []
right = []
ans = 3*10**5
E = S.count("E")
W = len(S)-E
# print(E)
# print(W)

for i in range(N):
    left_count = 0
    right_count = 0
    left = S[0:i]
#     right = S[i+1:]

    left_count = left.count("W")
    if S[i]== "W":
        right_count = E - (i - left_count)
    else:
        right_count = E - 1 - (i - left_count)

#     print(left_count)
#     print(right_count)
    count = left_count + right_count
    ans = min(count, ans)
print(ans)


Fixed submission:
N = int(input())
S = list(input())

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

left = []
right = []
ans = 3*10**5
E = S.count("E")
W = S.count("W")
# print(E)
# print(W)

for i in range(N):
    left_count = 0
    right_count = 0
    left = S[0:i]
#     right = S[i+1:]

    left_count = left.count("W")
    if S[i]== "W":
        right_count = E - (i - left_count)
    else:
        right_count = E - 1 - (i - left_count)

#     print(left_count)
#     print(right_count)
    count = left_count + right_count
    ans = min(count, ans)
print(ans)


Fixed submission:
N = int(input())
S = list(input())

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

left = []
right = []
ans = 3*10**5

for i in range(N):
    left_count = 0
    right_count = 0
    left = S[0:i]
    right = S[i+1:]

    for l in left:
        if l == "W":
            left_count += 1

    for r in right:
        if r == "E":
            right_count += 1
            
    count = left_count + right_count
    ans = min(count, ans)
print(ans)

Fixed submission:
N = int(input())
S = list(input())

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# S = list(input())
S = input()

left = []
right = []
ans = 3*10**5

for i in range(N):
    left = S[0:i]
    right = S[i+1:]
#     print(list(left))
#     print(list(right))
    left_count = list(left).count("W")
#     print(left_count)
    right_count = list(right).count("E")
#     print(right_count)
    count = left_count + right_count
    ans = min(count, ans)
print(ans)


Fixed submission:
N = int(input())
S = list(input())

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数