Buggy python submission (verdict: Runtime Error):
N = int(input())
str = input()
str_list=list(str)
pre_list=[]
length_list=[]
answer_list=[]
answer_first=0
answer_second=0
for i in range (N-1):
  if str_list[i] != str_list[i+1]:
    pre_list.append(i)
    if pre_list == []:
      print("0")
      sys.exit()
    lenlen=len(pre_list)
for i in range (lenlen-1):
  length_list.append(pre_list[i+1]-pre_list[i])
  if lenlen=1:
    for i in range (N):
      if str_list[i] == "E":
        seki = -1
        else:
          seki = 1
          point = (i-pre_list[0])*seki
          if point<0:
            answer_first = answer_first+1
    print(answer_first)
    sys.exit()
basyo = length_list.index(max(length_list))
basyo2_kouho1 = pre_list[basyo]
basyo2_kouho2 = pre_list[basyo+1]
for i in range (N):
  if str_list[i] == "E":
    seki = -1
  else:
    seki = 1
  point = (i-basyo2_kouho1)*seki
  if point<0:
    answer_first = answer_first+1
for i in range (N):
  if str_list[i] == "E":
    seki = -1
  else:
    seki = 1
  point = (i-basyo2_kouho2)*seki
  if point<0:
    answer_second = answer_second+1
if answer_first>=answer_second:
  print(answer_second)
else:
  print(answer_first)
    

Fixed submission:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range (N):
  if i==0:
    ans=num_list[N-1]-num_list[i]
    ans_list.append(ans)
  else:
    ans=num_list[N-1]-num_list[i]+i-num_list[i-1]
    ans_list.append(ans)

print(min(ans_list))

Buggy python submission (verdict: Runtime Error):
N = int(input())
str = input()
str_list=list(str)
pre_list=[]
length_list=[]
answer_list=[]
answer_first=0
answer_second=0
for i in range (N-1):
  if str_list[i] != str_list[i+1]:
    pre_list.append(i)
    lenlen=len(pre_list)
for i in range (lenlen-1):
  length_list.append(pre_list[i+1]-pre_list[i])
basyo = length_list.index(max(length_list))
basyo2_kouho1 = pre_list[basyo]
basyo2_kouho2 = pre_list[basyo+1]
for i in range (N):
  if str_list[i] == "E":
    seki = -1
  else:
    seki = 1
  point = (i-basyo2_kouho1)*seki
  if point<0:
    answer_first = answer_first+1
for i in range (N):
  if str_list[i] == "E":
    seki = -1
  else:
    seki = 1
  point = (i-basyo2_kouho2)*seki
  if point<0:
    answer_second = answer_second+1
if answer_first>=answer_second:
  print(answer_second)
else:
  print(answer_first)

Fixed submission:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range (N):
  if i==0:
    ans=num_list[N-1]-num_list[i]
    ans_list.append(ans)
  else:
    ans=num_list[N-1]-num_list[i]+i-num_list[i-1]
    ans_list.append(ans)

print(min(ans_list))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
str = input()
str_list=list(str)
answer_list=[]
for i in range (N):
  answer=0
  for j in range (N):
    if str_list[j] == "E":
      seki = -1
    else:
      seki = 1
    point = (j-i)*seki
    if point<0:
      answer = answer+1
  answer_list.append(answer)
print(min(answer_list))

Fixed submission:
N = int(input())
str = input()
str_list=list(str)
num_list=[]
ans_list=[]
num=0
for i in range (N):
  if str_list[i]=="E":
    num=num+1
    num_list.append(num)
  else:
    num_list.append(num)
   
for i in range (N):
  if i==0:
    ans=num_list[N-1]-num_list[i]
    ans_list.append(ans)
  else:
    ans=num_list[N-1]-num_list[i]+i-num_list[i-1]
    ans_list.append(ans)

print(min(ans_list))