Buggy python submission (verdict: Runtime Error):
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
S = None

def main():
    global S

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

    if N == 2:
        if S == "WE":
            print(1)
        else:
            print(0)
        sys.exit()

    E, W = [], []
    e, w = 0, 0

    for s in S:
        if s == "E":
            e += 1
        else:
            w += 1
        E.append(e)
        W.append(w)

    ans = min(ans, E[-1] - E[0 + 1])
    for leader in range(1, N):
        if leader == N - 1:
            ans = min(ans, W[leader - 1])
        else:
            ans = min(ans, W[leader - 1] + E[-1] - E[leader + 1])

    print(ans)


main()


Fixed submission:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

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

    ans = S[1:].count("E")
    A = []
    A.append(ans)

    for i in range(1, N):
        if S[i - 1] == "W":
            ans += 1
        if S[i] == "E":
            ans -= 1
        A.append(ans)

    print(min(A))



main()

Buggy python submission (verdict: Runtime Error):
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None
S = None

def main():
    global S

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

    if N == 2:
        if S == "WE":
            print(1)
        else:
            print(0)
        sys.exit()

    E, W = [], []
    e, w = 0, 0

    for s in S:
        if s == "E":
            e += 1
        else:
            w += 1
        E.append(e)
        W.append(w)

    ans = min(ans, E[-1] - E[0 + 1])
    for leader in range(1, N):
        elif leader == N - 1:
            ans = min(ans, W[leader - 1])
        else:
            ans = min(ans, W[leader - 1] + E[-1] - E[leader + 1])

    print(ans)


main()


Fixed submission:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

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

    ans = S[1:].count("E")
    A = []
    A.append(ans)

    for i in range(1, N):
        if S[i - 1] == "W":
            ans += 1
        if S[i] == "E":
            ans -= 1
        A.append(ans)

    print(min(A))



main()