Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(input())
ANS = []
L = ["-"] + L + ["-"]
for i in range(1,N+1) :
    p = L[(i+1):].count("E")
    q = L[:i].count("W")
    ANS.append(p+q)
print(min(ANS))


Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
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))



Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
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))



Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
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))



Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
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))



Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))

Buggy python submission (verdict: Time Limit Exceeded):
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))



Fixed submission:
N = int(input())
S = list(input())
ANS = []
ans = 0
for i in range(0,N) :
    if i == 0 :
        ans += S[1:].count("E")
        ANS.append(ans)
    elif S[i-1] == "E" and S[i] == "E" :
        ans -= 1
        ANS.append(ans)
    elif S[i-1] == "W" and S[i] == "W" :
        ans += 1
        ANS.append(ans)
print(min(ANS))