Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ww = [0]*n
ee = [0]*n
ww[-1] = s.count('W')
ee[-1] = s.count('E')
for i in range(n-1):
  ww[i] = s[:i+1].count('W')
  ee[i] = s[:i+1].count('E')
      
l = [0]*n
l[0] = ee[-1]
l[-1] = ww[-2]
for i in range(1,n-1):
  l[i] = ww[i-1] + ee[-1] - ee[i]
    
  
print(min(l))


Fixed submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ww = [0]*n
ee = [0]*n

for i in range(n):
  for j in range(0, i+1):
    if s[j] == 'W':
      ww[i] += 1
    else:
      ee[i] += 1
      
l = [0]*n
l[0] = ee[-1]
l[-1] = ww[-2]
for i in range(1,n-1):
  l[i] = ww[i-1] + ee[-1] - ee[i]
    
  
print(min(l))


Fixed submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

ww = [0]*n
ee = [0]*n

for i in range(n):
  for j in range(0, i+1):
    if s[j] == 'W':
      ww[i] += 1
    else:
      ee[i] += 1
      
l = [0]*n
l[0] = max(ee[1:])
l[n-1] = max(ww[:n-1])
for i in range(1,n-1):
  l[i] = ww[i-1] + ee[-1] - ee[i]
    
  
print(min(l))


Fixed submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

for i in range(n):
  if s[i] == 'W':
    s[i] = 0
  else:
    s[i] = 1
    
l = [0]*n
l[n-1] = n - 1 - sum(s[:n-1])

for i in range(n-1):
  w_side = len(s[:i]) - sum(s[:i])
  e_side = sum(s[i+1:])
  l[i] = w_side + e_side
  
print(min(l))


Fixed submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

l = [0]*n
l[n-1] = s[:n-1].count('W')
for i in range(n-1):
  w_side = s[:i].count('W')
  e_side = s[i+1:].count('E')
  l[i] = w_side + e_side
  
print(min(l))


Fixed submission:
import sys

n, s = sys.stdin.read().split()

def main():
    cnt = s.count('E')
    cur = 'E'
    res = [cnt]
    for c in s:
        if cur == 'W': cnt += 1
        if c == 'E': cnt -= 1
        res.append(cnt)
        cur = c
    print(min(res))
    
if __name__ ==  '__main__':
    main()