ZhenlongDai/ACPR huggingface dataset:
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
imosw = []
imose = []
imosw.append(0);
imose.append(0);
for i in s:
    if i=='W':
        imosw.append(imosw[-1]+1)
        imose.append(imose[-1])
    else:
        imosw.append(imosw[-1])
        imose.append(imose[-1]+1)
res = 10000000
for i in range(n):
    res = min(imose[i]+imosw[n]-imosw[i+1],res)
print(res)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
imosw = []
imose = []
imosw.append(0);
imose.append(0);
for i in range(n):
    if s[i]=='W':
        imosw.append(imosw[i]+1)
        imose.append(imose[i])
    else:
        imosw.append(imosw[i])
        imose.append(imose[i]+1)
res = 100000000000
for i in range(n):
    res = min(imosw[i]+imose[n]-imose[i+1],res)
print(res)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
t=s.count('E')
ans=10**8
e=0
w=0
for i in range(n):
  if s[i]=='E':
    e+=1
    ans=min(ans,t-e+w-1)
  elif s[i]=='W':
    w+=1
    ans=min(ans,t-e+w-1)
print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
t=s.count('E')
ans=10**9
e=0
w=0
for i in range(n):
  if s[i]=='E':
    e+=1
    ans=min(ans,t-e+w)
  elif s[i]=='W':
    w+=1
    ans=min(ans,t-e+w-1)
print(ans)

Problem: p03339
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
NN = int(input())
SS = str(input())

score = [0]*NN
for i in range(1,NN):
    if SS[i] == "E":
        score[0] += 1

for pos in range(1,NN-1):
    score[pos] = score[pos-1]
    if SS[pos-1] == "W":
        score[pos] += 1
    if SS[pos] == "E":
        score[pos] -= 1

score[NN-1] = score[NN-2]
if SS[NN-2] == "W":
    score[NN-1] += 1

print(score)
print(min(score))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 2, 1, 1, 2]
1


Fixed submission (verdict: Accepted):
NN = int(input())
SS = str(input())

score = [0]*NN
for i in range(1,NN):
    if SS[i] == "E":
        score[0] += 1

for pos in range(1,NN-1):
    score[pos] = score[pos-1]
    if SS[pos-1] == "W":
        score[pos] += 1
    if SS[pos] == "E":
        score[pos] -= 1

score[NN-1] = score[NN-2]
if SS[NN-2] == "W":
    score[NN-1] += 1
if SS[NN-1] == "E":
    score[NN-1] -= 1

print(min(score))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()

w = 0
e = s.count('E')
ans = w + e
for si in s:
  if s == 'E':
    e -= 1
  else:
    w += 1
  ans = min(ans, w + e)
print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

w = 0
e = s.count('E')
ans = w + e
for si in s:
  if si == 'E':
    e -= 1
  else:
    w += 1
  ans = min(ans, w + e)
print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
lst1=[0]*n
lst2=[0]*n
if s[0]=='W':
  lst1[0]=1
if s[0]=='E':
  lst2[0]=1
for i in range(1,n):
  if s[i]=='W':
    lst1[i]=lst1[i-1]+1
  if s[i]=='E':
    lst2[i]=lst2[i-1]+1
l=[]
l.append(lst2[n-1]-lst2[0])
for j in range(1,n-1):
  l.append(lst1[j-1]+lst2[n-1]-lst2[j])
l.append(lst1[n-2])

print(min(l))
  
  

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
-2


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
lst1=[0]*n
lst2=[0]*n
if s[0]=='W':
  lst1[0]=1
if s[0]=='E':
  lst2[0]=1
for i in range(1,n):
  if s[i]=='W':
    lst1[i]=lst1[i-1]+1
    lst2[i]=lst2[i-1]
  if s[i]=='E':
    lst2[i]=lst2[i-1]+1
    lst1[i]=lst1[i-1]
l=[]
l.append(lst2[n-1]-lst2[0])
for j in range(1,n-1):
  l.append(lst1[j-1]+lst2[n-1]-lst2[j])
l.append(lst1[n-2])

print(min(l))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
people=list(input())

Wlist=[0]*(N+1)
Elist=[0]*(N+1)
for i in range(N):
    Wlist[i+1]=Wlist[i]
    if people[i]=='W':
        Wlist[i+1]+=1
    Elist[i+1]=Elist[i]
    if people[i]=='E':
        Elist[i+1]+=1

print(Wlist)
print(Elist)

List=[]
for i in range(N):
    List.append(Wlist[i]+(Elist[N]-Elist[i+1]))

print(min(List))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 1, 1, 1, 2, 3]
[0, 0, 1, 2, 2, 2]
1


Fixed submission (verdict: Accepted):
N=int(input())
people=list(input())

Wlist=[0]*(N+1)
Elist=[0]*(N+1)
for i in range(N):
    Wlist[i+1]=Wlist[i]
    if people[i]=='W':
        Wlist[i+1]+=1
    Elist[i+1]=Elist[i]
    if people[i]=='E':
        Elist[i+1]+=1




List=[]
for i in range(N):
    List.append(Wlist[i]+(Elist[N]-Elist[i+1]))

print(min(List))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
S=str(input())
ans=S[1:].count('E')
cnt=ans
for i in range(1,N):
    if S[i-1]=='W':
        cnt+=1
    if S[i]=='E':
        cnt-=1
        
print(min(ans,cnt))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())
S=input()
ans=S[1:].count('E')
cnt=ans
for i in range(1,N):
    if S[i-1]=='W':
        cnt+=1
    if S[i]=='E':
        cnt-=1
    ans=min(ans,cnt)
    
print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = left + (1 - center)
    right = right + center
    center = s[i]
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):


n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = left + (1 - center)
    center = s[i]
    right = right - center
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
E = [0]*(N+1)
W = [0]*(N+1)
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'W':
        W[i+1] += W[i] + 1
for i in range(N)[1::-1]:
    if S[i] == 'E':
        E[i-1] += E[i] + 1
        
for i in range(N):
    ans = min(ans,E[i]+W[i]) 
    print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
1
1
0
0
0


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
E = [0]*N
W = [0]*N
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'W':
        W[i+1] += W[i] + 1
    else:
        W[i+1] = W[i]
for i in range(N)[:0:-1]:
    if S[i] == 'E':
        E[i-1] += E[i] + 1
    else:
        E[i-1] = E[i]
for i in range(N):
    ans = min(ans,E[i]+W[i])
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
ss = [0]*N
 
ss[0] += S[1:].count('E')
ss[N-1] += S[:N-1].count('W')
 
for i in range(1, N-1):
  ss[i] = ss[i-1] + (ss[i-1]=='W')
  
print(max(min(ss), 1))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

ss1 = S[1:].count('E')
ss = ss1

for i in range(1, N):
  ss1 = ss1 + (S[i-1]=='W') - (S[i]=='E')
  if ss1 < ss:
    ss = ss1
  
print(ss)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()

E = [0]*(N+2)
W = [0]*(N+2)
for i in range(1,N+1):
    if S[i-1] == 'E':
        E[i] = E[i-1] + 1
        W[i] = W[i-1]
    else:
        W[i] = W[i-1] + 1
        E[i] = E[i-1]
print(E)
print(W)
ans = 300000
for l in range(1,N+1):
    num = E[N] - E[l] + W[l-1] -W[0]
    print(num)
    if ans > num:
        ans = num

print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 0, 1, 2, 2, 2, 0]
[0, 1, 1, 1, 2, 3, 0]
2
2
1
1
2
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

E = [0]*(N+2)
W = [0]*(N+2)
for i in range(1,N+1):
    if S[i-1] == 'E':
        E[i] = E[i-1] + 1
        W[i] = W[i-1]
    else:
        W[i] = W[i-1] + 1
        E[i] = E[i-1]

ans = 300000
for L in range(1,N+1):
    num = E[N] - E[L] + W[L-1] -W[0]
    if ans > num:
        ans = num

print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

line = []
E = 0
W = 0
error = 0









E = S.count('E')
W = S.count('W')

counter = 0

for i in range(N):
    if(i==0):
        counter = E
    else:
        if(S[i]=='E'):
            counter -= 1
        elif(S[i-1]=='W'):
            counter += 1

    line.append(counter)

print(line)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 1, 0, 0, 1]


Fixed submission (verdict: Accepted):


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

line = []
E = 0
W = 0
error = 0

E = S.count('E')
W = S.count('W')

counter = 0

for i in range(N):
    if(i==0):
        if(S[i]=='E'):
            counter = E
            counter -= 1
        else:
            counter = E
    else:
        if(S[i]=='E'):
            counter -= 1
        if(S[i-1]=='W'):
            counter += 1

    line.append(counter)

print(min(line))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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):
  ans=num_list[N-1]+i+1-num_list[0]
  ans_list.append(ans)
print(ans_list)
print(min(ans_list))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[3, 4, 5, 6, 7]
3


Fixed submission (verdict: Accepted):
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))
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
E = [0]*(N+1)
W = [0]*(N+1)
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'E':
        W[i+1] += W[i] + 1
    else:
        E[i+1] += E[i] + 1
        
for i in range(N):
    ans = min(ans,E[i]+W[i]) 
    print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0
0
0
0
0


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
E = [0]*N
W = [0]*N
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'W':
        W[i+1] += W[i] + 1
    else:
        W[i+1] = W[i]
for i in range(N)[:0:-1]:
    if S[i] == 'E':
        E[i-1] += E[i] + 1
    else:
        E[i-1] = E[i]
for i in range(N):
    ans = min(ans,E[i]+W[i])
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
e_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt += 1
ans = e_cnt
w_cnt = 0
for i in range(n):
    ans = min(w_cnt + e_cnt - 1, ans)
    if s[i] == "W":
        w_cnt += 1
    else:
        e_cnt -= 1

print(ans)




Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
e_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt += 1
ans = e_cnt
w_cnt = 0
for i in range(n):
    if s[i] == "E":
        e_cnt -= 1
        
    ans = min(w_cnt + e_cnt, ans)
    if s[i] == "W":
        w_cnt += 1

print(ans)

Problem: p03339
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = input()
 
oE = S.count("E")
Wo = 0

L = []
for i in range(N):
    if i == 0:
        if S[i] == "E":
            oE -= 1
    else:
        if S[i-1] == "W":
            Wo += 1
        if S[i] == "E":
            oE -= 1
    L.append(Wo + oE)
    if Wo + oE == 1:
        break
print(L)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 2, 1]


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
 
oE = S.count("E")
Wo = 0

L = []
for i in range(N):
    if i == 0:
        if S[i] == "E":
            oE -= 1
    else:
        if S[i-1] == "W":
            Wo += 1
        if S[i] == "E":
            oE -= 1
    L.append(Wo + oE)
    if Wo + oE == 0:
        break
print(min(L))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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):
  ans=num_list[N-1]-num_list[i]
  ans_list.append(ans)
print(min(ans_list))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
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))
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
direction = list(input())
change = [0]*N
change[0] = direction.count("E")
 
for i in range(1, N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    if direction[i] == "W":
        f_p = 1
    change[i] = change[i-1] - f_n + f_p
print(min(change))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
direction = list(input())
change = [0]*(N+1)

change[0] = direction.count("E")

for i in range(N):
    f_n = 0
    f_p = 0
    if direction[i] == "E":
        f_n = 1
    else:
        f_p = 1
    change[i+1] = change[i] - f_n + f_p

print(min(change))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
num = s[1:].count('E')
ans = [num]

for i in range(1,n):
    if s[i] == 'E':
        num -= 1
    elif s[i-1] == 'W':
        num += 1
    ans.append(num)
print(min(ans))



Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
num = s[1:].count('E')
ans = [num]

for i in range(1,n):
    if s[i] == 'E':
        num -= 1
    if s[i-1] == 'W':
        num += 1
    ans.append(num)
print(min(ans))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())

cnt_right = S[1:].count('E')
cnt_left = 0
ans = cnt_right + cnt_left

for ichi in range(len(S)-1):
    if S[ichi] == 'W':
        cnt_left += 1
    if S[ichi+1] == 'E':
        cnt_right -= 1
    ans = min(ans, cnt_right + cnt_left)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:

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

cnt_right = S[1:].count('E')
cnt_left = 0
ans = cnt_right + cnt_left

for ichi in range(len(S)-1):
    if S[ichi] == 'W':
        cnt_left += 1
    if S[ichi+1] == 'E':
        cnt_right -= 1
    ans = min(ans, cnt_right + cnt_left)
    
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i] == "W":
    l += 1
  if s[n - i] == "E":
    r -= 1
  result = min(result, l + r)
print(result)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i - 1] == "W":
    l += 1
  if s[i] == "E":
    r -= 1
  result = min(result, l + r)
print(result)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
lst1=[0]*n
lst2=[0]*n
if s[0]=='W':
  lst1[0]=1
if s[0]=='E':
  lst2[0]=1
for i in range(1,n):
  if s[i]=='W':
    lst1[i]=lst1[i-1]+1
  if s[i]=='E':
    lst2[i]=lst2[i-1]+1
l=[]
l.append(lst2[n-1]-lst2[0])
for j in range(1,n-1):
  l.append(lst1[j-1]+lst2[n-1]-lst2[j])
l.append(lst1[n-2])

print(min(l))
  
  


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
-2


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
lst1=[0]*n
lst2=[0]*n
if s[0]=='W':
  lst1[0]=1
if s[0]=='E':
  lst2[0]=1
for i in range(1,n):
  if s[i]=='W':
    lst1[i]=lst1[i-1]+1
    lst2[i]=lst2[i-1]
  if s[i]=='E':
    lst2[i]=lst2[i-1]+1
    lst1[i]=lst1[i-1]
l=[]
l.append(lst2[n-1]-lst2[0])
for j in range(1,n-1):
  l.append(lst1[j-1]+lst2[n-1]-lst2[j])
l.append(lst1[n-2])

print(min(l))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
m=n+5
w=0
e=0
for i in range(1,n):
    if s[i]=='E':
        e+=1
m=min(m,w+e)
for i in range(1,n):
    if s[i-1]=='W':
        w+=1
    if s[i]=='E':
        e-=1
    m=min(m,w+e)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
s=input()
m=n+5
w=0
e=0
for i in range(1,n):
    if s[i]=='E':
        e+=1
m=min(m,w+e)
for i in range(1,n):
    if s[i-1]=='W':
        w+=1
    if s[i]=='E':
        e-=1
    m=min(m,w+e)
print(m)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()


e = [0]
w = [0]

cnt_e = 0
cnt_w = 0
for i in range(n):
	if s[i] == "E" :
		cnt_e += 1
	else:
		cnt_w += 1

	e.append(cnt_e)
	w.append(cnt_w)

ans = n +1
for j in range(n):
	t = w[i]  + e[n] - e[ i +1 ]
	
	ans = min(ans,t)

print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()


e = [0]
w = [0]

cnt_e = 0
cnt_w = 0
for i in range(n):
	if s[i] == "E" :
		cnt_e += 1
	else:
		cnt_w += 1

	e.append(cnt_e)
	w.append(cnt_w)

ans = 10000000000
for j in range(n):
	t = w[j]  + e[n] - e[ j +1 ]
	
	ans = min(ans,t)

print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()

e = []
w = []
ek = 0
wk = 0
for i in range(n):
    if s[i] == "E":
        ek += 1
        e.append(ek)
        w.append(wk)
    if s[i] == "W":
        wk += 1
        e.append(ek)
        w.append(wk)

ma = e[n-1]-e[0]
print(e)
print(w)
for i in range(n):
    if i != n-1:
        cos = e[n-1]-e[i] + w[i]
    else:
        cos = w[n-2]
    ma = min(cos,ma)

print(ma)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 1, 2, 2, 2]
[1, 1, 1, 2, 3]
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

e = []
w = []
ek = 0
wk = 0
for i in range(n):
    if s[i] == "E":
        ek += 1
        e.append(ek)
        w.append(wk)
    if s[i] == "W":
        wk += 1
        e.append(ek)
        w.append(wk)

ma = e[n-1]-e[0]
for i in range(n):
    if i != n-1:
        cos = e[n-1]-e[i] + w[i]
    else:
        cos = w[n-2]
    ma = min(cos,ma)

print(ma)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()

original_w = []
prev = 0
for i in range(N):
    if S[i] == 'W':
        prev += 1
    original_w.append(prev)

original_e = []
prev = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'E':
        prev += 1
    original_e.insert(0, prev)




Failing test case input:
5
WEEWW

Expected output:
1

Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
S = input()

original_w = []
prev = 0
for i in range(N):
    if S[i] == 'W':
        prev += 1
    original_w.append(prev)

original_e = []
prev = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'E':
        prev += 1
    original_e.append(prev)

ans = min(original_e[N - 1], original_w[N - 2])
for i in range(1, N - 1):
    ans = min(ans, original_w[i - 1] + original_e[N - (i + 1)])
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
S=str(input())


ans=[]
count=0

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


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

    ans.append(count)

print(min(ans))


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input())
S=str(input())


ans=[]
count=0

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


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

    ans.append(count)

print(min(ans))
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        e_east -= 1
    else:
        w_west += 1
    tmp = w_west + e_east - bool(s_i == "E")
    if tmp < min_num:
        min_num = tmp
print(min_num)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

min_num = 300000
w_west = 0
e_east = s.count("E")
for s_i in s:
    if s_i == "E":
        e_east -= 1
    else:
        w_west += 1
    tmp = w_west + e_east - bool(s_i == "W")
    if tmp < min_num:
        min_num = tmp
print(min_num)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
E = [0]*(N+1)
W = [0]*(N+1)
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'E':
        E[i+1] += E[i] + 1
    else:
        W[i+1] += W[i] + 1
        
for i in range(N):
    ans = min(ans,E[i]+W[i]) 
    print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0
0
0
0
0


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
E = [0]*N
W = [0]*N
ans = 10000*10000
for i in range(N-1):
    if S[i] == 'W':
        W[i+1] += W[i] + 1
    else:
        W[i+1] = W[i]
for i in range(N)[:0:-1]:
    if S[i] == 'E':
        E[i-1] += E[i] + 1
    else:
        E[i-1] = E[i]
for i in range(N):
    ans = min(ans,E[i]+W[i])
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()

answer = prev = S[1:].count('E')
print(S.replace('E', 'R').replace('W', 'L'))
print('0', answer)
for i in range(1, N):
    _answer = prev if S[i-1] == 'E' else prev+1
    if S[i] == 'E':
        _answer -= 1
    answer = min(answer, _answer)
    prev = _answer

print(answer)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
LRRLL
0 2
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

answer = prev = S[1:].count('E')
for i in range(1, N):
    _answer = prev if S[i-1] == 'E' else prev+1
    if S[i] == 'E':
        _answer -= 1
    answer = min(answer, _answer)
    prev = _answer

print(answer)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A=input()
R=[0]
for i in range(N):
    R.append(R[i]+(A[i]=="W"))
min([R[i]+(N-i-1)-(R[-1]-R[i+1]) for i in range(N)])

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:

Fixed submission (verdict: Accepted):
N=int(input())
A=input()
R=[0]
for i in range(N):
    R.append(R[i]+(A[i]=="W"))
print(min([R[i]+(N-i-1)-(R[-1]-R[i+1]) for i in range(N)]))
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()

ruiseki_w = [0]
ruiseki = 0
for i in s[1:]:
    if i == 'W':
        ruiseki += 1
        ruiseki_w.append(ruiseki)
    else:
        ruiseki_w.append(ruiseki)

ruiseki_e = [s.count('E')]
ruiseki = s.count('E')
for i in s[1:]:
    if i == 'E':
        ruiseki -= 1
        ruiseki_e.append(ruiseki)
    else:
        ruiseki_e.append(ruiseki)
        
ninzu = [ruiseki_w[i] + ruiseki_e[i] for i in range(n)]
print(min(ninzu))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

ruiseki_w = [0]
ruiseki = 0
for i in s[:-1]:
    if i == 'W':
        ruiseki += 1
        ruiseki_w.append(ruiseki)
    else:
        ruiseki_w.append(ruiseki)

ruiseki_e = [0]
ruiseki = 0
for i in s[::-1][:-1]:
    if i == 'E':
        ruiseki += 1
        ruiseki_e.append(ruiseki)
    else:
        ruiseki_e.append(ruiseki)
ruiseki_e.reverse()
        
ninzu = [ruiseki_w[i] + ruiseki_e[i] for i in range(n)]
print(min(ninzu))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
left_attention = [0 for i in range(n)]
right_attention = [0 for i in range(n)]

for i in range(1,n):
    left_attention[i]=left_attention[i-1]
    if(s[i-1]=='W'):
        left_attention[i]+=1

print(left_attention)

for i in range(n-2,-1,-1):
    right_attention[i]=right_attention[i+1]
    if(s[i+1]=='E'):
        right_attention[i]+=1

print(right_attention)

ans=n
for i in range(n):
    ans = min(ans, left_attention[i]+right_attention[i])


print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 1, 1, 1, 2]
[2, 1, 0, 0, 0]
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
left_attention = [0 for i in range(n)]
right_attention = [0 for i in range(n)]

for i in range(1,n):
    left_attention[i]=left_attention[i-1]
    if(s[i-1]=='W'):
        left_attention[i]+=1


for i in range(n-2,-1,-1):
    right_attention[i]=right_attention[i+1]
    if(s[i+1]=='E'):
        right_attention[i]+=1


ans=n
for i in range(n):
    ans = min(ans, left_attention[i]+right_attention[i])


print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
min_num = 10**6
west_num = [0]
east_num = [0]

for i in range(0, N): 
    if S[i] == 'W':
        west_num.append(1 + max(west_num))
        east_num.append(max(east_num))
    else:
        west_num.append(max(west_num))
        east_num.append(1 + max(east_num))

for i in range(0, N):
    num = 0
    num = west_num[i] + east_num[-1] - east_num[i]
    if num < min_num:
        min_num = num
        
print(min_num)
print(west_num)
print(east_num)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
1
[0, 1, 1, 1, 2, 3]
[0, 0, 1, 2, 2, 2]


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
min_num = 10**7
west_num = [0]
east_num = [0]
w_max = 0
e_max = 0
for i in range(0, N): 
    if S[i] == 'W':
        w_max += 1
    else:
        e_max += 1
        
    west_num.append(w_max)
    east_num.append(e_max)

for i in range(0, N):
    num = west_num[i] + east_num[-1] - east_num[i+1]
    if num < min_num:
        min_num = num
        
print(min_num)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()

ans = float('inf')
sum_E = [0]
sum_W = [0]
cnt_e = 0
cnt_w = 0

for i in range(N):
	if S[i] == 'E':
		cnt_e += 1
	else:
		cnt_w += 1
	sum_E.append(cnt_e)
	sum_W.append(cnt_w)

print(sum_E,sum_W)


for i in range(N):
	ans = min(ans, sum_W[i] + sum_E[-1] - sum_E[i+1])

print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 0, 1, 2, 2, 2] [0, 1, 1, 1, 2, 3]
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()

ans = float('inf')
sum_E = [0]
sum_W = [0]
cnt_e = 0
cnt_w = 0

for i in range(N):
	if S[i] == 'E':
		cnt_e += 1
	else:
		cnt_w += 1
	sum_E.append(cnt_e)
	sum_W.append(cnt_w)

for i in range(N):
	ans = min(ans, sum_W[i] + sum_E[-1] - sum_E[i+1])

print(ans)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(map(lambda x: x, inputs[0]))
    N = len(persons)
    counts = []
    for leader, _ in enumerate(persons):
        count = 0
        for p in range(0, leader):
            if persons[p] == "W":
                count += 1
        for p in range(leader + 1, N):
            if persons[p] == "E":
                count += 1
        counts.append(count)
    min = counts[0]
    for count in counts:
        if min > count:
            min = count

    return min


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = list(inputs[0])

    count = [persons[1:].count("E")]

    for i in range(1, len(persons)):
        if i == 0:
            continue

        tmp = count[-1]
        if persons[i - 1] == 'W':
            tmp += 1
        if persons[i] == 'E':
            tmp -= 1
        count.append(tmp)

    return min(count)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
min_num = 10**7
west_num = [0]
east_num = [0]
w_max = 0
e_max = 0
for i in range(0, N): 
    if S[i] == 'W':
        w_max += 1
    else:
        e_max += 1
        
    west_num.append(w_max)
    east_num.append(e_max)

for i in range(0, N):
    num = west_num[i] + east_num[-1] - east_num[i+1]
    if num < min_num:
        min_num = num
        
print(west_num)
print(east_num)
print(min_num)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[0, 1, 1, 1, 2, 3]
[0, 0, 1, 2, 2, 2]
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
min_num = 10**7
west_num = [0]
east_num = [0]
w_max = 0
e_max = 0
for i in range(0, N): 
    if S[i] == 'W':
        w_max += 1
    else:
        e_max += 1
        
    west_num.append(w_max)
    east_num.append(e_max)

for i in range(0, N):
    num = west_num[i] + east_num[-1] - east_num[i+1]
    if num < min_num:
        min_num = num
        
print(min_num)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=list(input())
n=len(s)
e_count=s.count("E")
w_count=n-e_count
w_left=0
e_right=e_count
c=[]
for i in range(n):
    if s[i]=='W':
        c+=[w_left+e_right]
        w_left+=1
    else:
        e_right-=1
        c+=[w_left+e_right]
print(min(c))
        

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
s=list(input())
e_count=s.count("E")
w_count=n-e_count
w_left=0
e_right=e_count
c=[]
for i in range(n):
    if s[i]=='W':
        c+=[w_left+e_right]
        w_left+=1
    else:
        e_right-=1
        c+=[w_left+e_right]
print(min(c))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()

ans = 3*(10**5)
to_east = 0
to_west = s.count('E', 1)
for i in range(1, n):
  if s[i]=='W':
    to_east += 1
  if s[n-i]=='E':
    to_west -= 1
  ans = to_east+to_west if ans>to_east+to_west else ans
  
print(ans)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()

to_east = 0
to_west = s.count('E', 1)
ans = to_east+to_west

for i in range(1, n):
  if s[i-1]=='W':
    to_east += 1
  if s[i]=='E':
    to_west -= 1
  ans = to_east+to_west if ans>to_east+to_west else ans
  
print(ans)

Problem: p03339
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
S=input()
ans=S.count("W")
for i in range(N):
  if S[i]=="W":
    ans-=1
  if i!=0:
    if S[i-1]=="E":
      ans+=1
  if i!=0:
    ans1=max(ans,ans1)
  else:
    ans1=ans
  print(ans)
print(N-1-ans1)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2
2
3
3
2
1


Fixed submission (verdict: Accepted):
N=int(input())
S=input()
ans=S.count("W")
ans1=-10
for i in range(N):
  if S[i]=="W":
    ans-=1
  if i!=0:
    if S[i-1]=="E":
      ans+=1
  ans1=max(ans,ans1)
print(N-1-ans1)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
m=list(input())
p=m.count("E")
s=p
for i in m:
    if i=="E":
        p-=1
    else:
        p+=1
    s=min(s,p)
    print(s)    



Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2
2
1
1
1


Fixed submission (verdict: Accepted):
n=int(input())
m=list(input())
p=m.count("E")
s=p
for i in m:
    if i=="E":
        p-=1
    else:
        p+=1
    s=min(s,p)
print(s)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
num = [0 for _ in range(N)]

for i in range(1, N):
  if S[i] == 'E':
    num[0] += 1

for i in range(1, N):
  if S[i-1] == 'W':
    num[i] = num[i-1] + 1
  if S[i] == 'E':
    num[i] = num[i-1] + 1
    
print(min(num))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
num = [0 for _ in range(N)]

for i in range(1, N):
  if S[i] == 'E':
    num[0] += 1

for i in range(1, N):
  diff = 0
  if S[i-1] == 'W':
    diff += 1
  if S[i] == 'E':
    diff -= 1
  num[i] = num[i-1] + diff
  
print(min(num))
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
w,e=0,s.count('E')
for i in range(n):
    if i =='W':
        n=min(n,w+e)
        w+=1
    else:
        e-=1
        n=min(n,w+e)
print(n)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
-3


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
w,e=0,s.count('E')
for i in s:
    if i =='W':
        n=min(n,w+e)
        w+=1
    else:
        e-=1
        n=min(n,w+e)
print(n)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
r=len([i for i in range(1,n) if s[i]=='E'])
l=0
print(l,r)
i=1
x=n
while i<=n-1:
    if s[i]=='E' and s[i-1]=='E':
        r=r-1
        l=l
    elif s[i]=='W' and s[i-1]=='W':
        r=r
        l=l+1
    elif s[i]=='W' and s[i-1]=='E':
        r=r
        l=l
    elif s[i]=='E' and s[i-1]=='W':
        r=r-1
        l=l+1
    x=min(l+r,x)
    i+=1
print(x)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0 2
1


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
r=len([i for i in range(1,n) if s[i]=='E'])
l=0
i=1
x=r+l
while i<=n-1:
    if s[i]=='E' and s[i-1]=='E':
        r=r-1
        l=l
    elif s[i]=='W' and s[i-1]=='W':
        r=r
        l=l+1
    elif s[i]=='W' and s[i-1]=='E':
        r=r
        l=l
    elif s[i]=='E' and s[i-1]=='W':
        r=r-1
        l=l+1
    x=min(l+r,x)
    i+=1
print(x)

Problem: p03339
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = list(input())
cnt = 0
ans_list = [0]
e_cnt = int()

for i in range(1,n):
    if s[i-1] == "E":
        cnt -= 1
    if s[i-1] == 'W':
        cnt += 1
    ans_list.append(cnt)

if s[n-1] == 'E':
    e_cnt = (ans_list[n-1] - 1 - n) 
else:
    e_cnt = (ans_list[n-1] - n) 

print(min(ans_list) + e_cnt)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
-6


Fixed submission (verdict: Accepted):
n = int(input())
s = list(input())
cnt = 0
ans_list = [0]
e_cnt = 0

for i in range(1,n):
    if s[i-1] == "E" and s[i] == "E":
        cnt -= 1
        e_cnt += 1
    if s[i-1] == "E" and s[i] == "W":
        cnt -= 0
    if s[i-1] == "W" and s[i] == "E":
        cnt += 0
        e_cnt += 1
    if s[i-1] == "W" and s[i] == "W":
        cnt += 1
    ans_list.append(cnt)

print(min(ans_list) + e_cnt)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = input()
m = mi= a.count("E")
for i in range(n):
    if a[i] == "W" : m+=1
    else : m-=1
    mi = min(mi,m) 
print(m)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
a = input()
m = mi= a.count("E")
for i in range(n):
    if a[i] == "W" : m+=1
    else : m-=1
    mi = min(mi,m) 
print(mi)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = int(input())
    s = list(input())
    w = 0
    e = 0
    r = [0]*n
    r[0] = s[1:].count('E')
    for i in range(n-1):
        r[i+1] = r[i]
        if s[i] == 'W':
            r[i+1] += 1
        if s[i] == 'E':
            r[i+1] -= 1
        print(r[i+1], i+1)
    print(min(r))
main()


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
3 1
2 2
1 3
2 4
1


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    s = list(input())
    w = 0
    e = 0
    r = [0]*n
    r[0] = s[1:].count('E')
    for i in range(n-1):
        r[i+1] = r[i]
        if s[i] == 'W':
            r[i+1] += 1
        if s[i+1] == 'E':
            r[i+1] -= 1
    print(min(r))
main()

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=input()
ans=n+1
l=[0]*(n+1)
for i in range(n):
  if l[i]=='E':
    l[i+1]=l[i]+1
ans=n+1
for i in range(n):
  ans=min(ans,i-l[i-1]+l[n]-l[i])
print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
s=input()
ans=n+1
l=[0]*(n+1)
for i in range(n):
  if s[i]=='E':
    l[i+1]=l[i]+1
  else:
    l[i+1]=l[i]
ans=n+1
for i in range(n):
  ans=min(ans,i-l[i]+l[n]-l[i+1])
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
leader = [0] * (N)
sum_e = 0
sum_w = 0
for i in range(N):
  leader[i] += sum_e
  leader[N-i-1] += sum_w
  if S[i] == 'E':
    sum_e += 1
  if S[N-i-1] == 'W':
    sum_w += 1

print(N-max(leader))
  

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
leader = [0] * (N)
sum_e = 0
sum_w = 0
for i in range(N):
  leader[i] += sum_e
  leader[N-i-1] += sum_w
  if S[i] == 'E':
    sum_e += 1
  if S[N-i-1] == 'W':
    sum_w += 1
print(N-max(leader)-1)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
S = input()

w = [0]*N
e = [0]*N
if S[0] == 'W':
    w[0] += 1
if S[N-1] == 'E':
    e[N-1] += 1
for i in range(1,N):
    w[i] = w[i-1]
    e[N-i-1] = e[N-i]
    if S[i] == 'W':
        w[i] += 1
    if S[N-i-1] == 'E':
        e[N-i-1] += 1

print(w,e)
m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    print(w[i],e[i])
    if cnt < m:
        m = cnt
print(m)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[1, 1, 1, 2, 3] [2, 2, 1, 0, 0]
1 2
1 2
1 1
2 0
3 0
1


Fixed submission (verdict: Accepted):
import math
N = int(input())
S = input()

w = [0]*N
e = [0]*N
if S[0] == 'W':
    w[0] += 1
if S[N-1] == 'E':
    e[N-1] += 1
for i in range(1,N):
    w[i] = w[i-1]
    e[N-i-1] = e[N-i]
    if S[i] == 'W':
        w[i] += 1
    if S[N-i-1] == 'E':
        e[N-i-1] += 1

m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    if cnt < m:
        m = cnt
print(m)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
int_n = int(input())
str_s = input()

li_west = [0] * int_n
for i in range(int_n - 1):
    if str_s[i] == 'W':
        li_west[i + 1] = li_west[i] + 1
    else:
        li_west[i + 1] = li_west[i]
li_east = [0] * int_n

for i in range(int_n - 1, 0, -1):
    print(i)
    if str_s[i] == 'E':
        li_east[i - 1] = li_east[i] + 1
    else:
        li_east[i - 1] = li_east[i]

minimum = 999999
for i in range(int_n):
    int_w = li_west[i] + li_east[i]
    minimum = min(minimum, int_w)

print(minimum)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
4
3
2
1
1


Fixed submission (verdict: Accepted):
int_n = int(input())
str_s = input()

li_west = [0] * int_n
for i in range(int_n - 1):
    if str_s[i] == 'W':
        li_west[i + 1] = li_west[i] + 1
    else:
        li_west[i + 1] = li_west[i]
li_east = [0] * int_n

for i in range(int_n - 1, 0, -1):
    if str_s[i] == 'E':
        li_east[i - 1] = li_east[i] + 1
    else:
        li_east[i - 1] = li_east[i]

minimum = 999999
for i in range(int_n):
    int_w = li_west[i] + li_east[i]
    minimum = min(minimum, int_w)

print(minimum)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
S = input()

w = [0]*N
e = [0]*N
if S[0] == 'W':
    w[0] += 1
if S[N-1] == 'E':
    e[N-1] += 1
for i in range(1,N):
    w[i] = w[i-1]
    e[N-i-1] = e[N-i]
    if S[i] == 'W':
        w[i] += 1
    if S[N-i-1] == 'E':
        e[N-i-1] += 1

print(w,e)
m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    if cnt < m:
        m = cnt
print(m)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[1, 1, 1, 2, 3] [2, 2, 1, 0, 0]
1


Fixed submission (verdict: Accepted):
import math
N = int(input())
S = input()

w = [0]*N
e = [0]*N
if S[0] == 'W':
    w[0] += 1
if S[N-1] == 'E':
    e[N-1] += 1
for i in range(1,N):
    w[i] = w[i-1]
    e[N-i-1] = e[N-i]
    if S[i] == 'W':
        w[i] += 1
    if S[N-i-1] == 'E':
        e[N-i-1] += 1

m = float("inf")
for i in range(N):
    cnt = w[i] + e[i] - 1
    if cnt < m:
        m = cnt
print(m)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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):
  ans=num_list[N-1]-num_list[i]+i+1+num_list[0]-num_list[i]
  ans_list.append(ans)
print(ans_list)
print(min(ans_list))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[3, 2, 1, 2, 3]
1


Fixed submission (verdict: Accepted):
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))
Problem: p03339
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
S = list(input())


ans = N

f = S[0]
s = S[1:]

nw = 0
ne = 0

for w in s:
    if w != 'W':
        ne += 1

for i, h in enumerate(range(1, N)):
    
    
    
    
    
    
    
    

    if S[i-1] != 'E':
        nw += 1

    if S[i] != 'W':
        ne -= 1
    
    ans = min(ans, nw+ne)

print(ans)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


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


ans = N

f = S[0]
s = S[1:]

nw = 0
ne = 0

for w in s:
    if w != 'W':
        ne += 1

ans = nw+ne
for i in range(1, N):
    
    
    
    
    
    
    
    

    if S[i-1] != 'E':
        nw += 1

    if S[i] != 'W':
        ne -= 1
    
    ans = min(ans, nw+ne)

print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = i - center
    right = right + center
    center = s[i]
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):


n = int(input())
s = list(input())

for (i, x) in enumerate(s):
    if x == "E":
        s[i] = 1
    elif x == "W":
        s[i] = 0

left = 0
right = sum(s[1:n])
center = s[0]
min_changed_num = right

for i in range(1, n):
    left = left + (1 - center)
    center = s[i]
    right = right - center
    changed_num = left + right
    if min_changed_num > changed_num:
        min_changed_num = changed_num

print(min_changed_num)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
S = input()
cnt = S.count('E')
ans = cnt

for v in S:
  if v == 'E':
    cnt -= 1
  else:
    cnt += 1
    ans = min(ans, cnt)
print(ans)


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
2


Fixed submission (verdict: Accepted):
N = input()
S = input()
cnt = S.count('E')
ans = cnt

for v in S:
  if v == 'E':
    cnt -= 1
  else:
    cnt += 1
  ans = min(ans, cnt)
print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
num = S.count('E')
min_num = num
for i in range(N-1):
    if S[i]=='W':
        num += 1
    if S[i+1]=='E':
        num -= 1
    min_num = num if min_num > num else min_num
    print(i, num)
print(min_num)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
0 2
1 1
2 1
3 2
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
num = S.count('E')
min_num = num
for i in range(N-1):
    if S[i]=='W':
        num += 1
    if S[i+1]=='E':
        num -= 1
    min_num = num if min_num > num else min_num
print(min_num if S[0]=='W' else min_num-1)
Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
sum_s = [0] * N
sum_s[0] = 1 if S[0] == 'W' else 0
for i in range(1, N):
    if S[i] == 'W':
        sum_s[i] = sum_s[i - 1] + 1
    else:
        sum_s[i] = sum_s[i - 1]
print(sum_s)

lc = 0
rc = (N - 1) - (sum_s[N - 1] - sum_s[0])
ans = lc + rc

for i in range(1, N):
    lc = sum_s[i - 1]
    rc = (N - (i + 1)) - (sum_s[N - 1] - sum_s[i])

    ans = min(ans, lc + rc)

print(ans)

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[1, 1, 1, 2, 3]
1


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
sum_s = [0] * N
sum_s[0] = 1 if S[0] == 'W' else 0
for i in range(1, N):
    if S[i] == 'W':
        sum_s[i] = sum_s[i - 1] + 1
    else:
        sum_s[i] = sum_s[i - 1]

lc = 0
rc = (N - 1) - (sum_s[N - 1] - sum_s[0])
ans = lc + rc

for i in range(1, N):
    lc = sum_s[i - 1]
    rc = (N - (i + 1)) - (sum_s[N - 1] - sum_s[i])

    ans = min(ans, lc + rc)

print(ans)

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
rev_counter = []
rev_num = s.count("E")
if s[0] == "E":
    rev_num -= 1
rev_counter.append(rev_num)
for i in range(1, n):
    if s[i] == "E" and s[i-1] == "E":
        rev_num -= 1
    elif s[i] == "W" and s[i-1] == "W":
         rev_num += 1
    rev_counter.append(rev_num)
print(rev_counter)
print(min(rev_counter))


Failing test case input:
5
WEEWW

Expected output:
1

Actual output:
[2, 2, 1, 1, 2]
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
rev_counter = []
rev_num = s.count("E")
if s[0] == "E":
    rev_num -= 1
rev_counter.append(rev_num)
for i in range(1, n):
    if s[i] == "E" and s[i-1] == "E":
        rev_num -= 1
    elif s[i] == "W" and s[i-1] == "W":
         rev_num += 1
    rev_counter.append(rev_num)
print(min(rev_counter))

Problem: p03339
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
if n==5:
  exit()
s=list(input())
l=[]
sh=s[0]
s.remove(sh)
c=0
for i in s:
  if i=='E':
    c+=1
l.append(c)
for i in range(len(s)):
  tsu=s[i]
  if sh=='W':
    c+=1
  if tsu=='E':
    c-=1
  l.append(c)
  sh=tsu
print(min(l))

Failing test case input:
5
WEEWW

Expected output:
1

Actual output:

Fixed submission (verdict: Accepted):
n=int(input())
s=list(input())
l=[]
sh=s[0]
s.remove(sh)
c=0
for i in s:
  if i=='E':
    c+=1
l.append(c)
for i in range(len(s)):
  tsu=s[i]
  if sh=='W':
    c+=1
  if tsu=='E':
    c-=1
  l.append(c)
  sh=tsu
print(min(l))