ZhenlongDai/ACPR huggingface dataset:
Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,A,B = map(int,input().split())

x = N * B
if x < B:
    print(B)
else:
    print(x)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
840


Fixed submission (verdict: Accepted):
N,A,B = map(int,input().split())

x = N * A
if x < B:
    print(x)
else:
    print(B)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C = list(map(int,input().split()))
if A*B > C:
  print(A*B)
else:
  print(C)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
A,B,C = list(map(int,input().split()))
if A*B < C:
  print(A*B)
else:
  print(C)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int, input().split())

if n * a > b:
    print (n*a)
else:
    print (b)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n,a,b = map(int, input().split())

if n * a < b:
    print (n*a)
else:
    print (b)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int, input().split())
print(max(n*a,b))

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n,a,b = map(int, input().split())
print(min(n*a,b))

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,t,i=input().split()
a=int(a)
t=int(t)
x=a*t
i=int(i)
c=min(x,i)

Failing test case input:
7 17 120

Expected output:
119

Actual output:

Fixed submission (verdict: Accepted):
a,t,i=input().split()
a=int(a)
t=int(t)
x=a*t
i=int(i)
c=min(x,i)
print(c)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b=map(int,input().split())
print(max(a*n,b))

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n,a,b=map(int,input().split())
print(min(a*n,b))

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, a, b = map(int, input().split())
print(max(a*n, b))

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n, a, b = map(int, input().split())
print(min(a*n, b))

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int, input().split())

if n * a >= b:
    print (n*a)
else:
    print (b)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n,a,b = map(int, input().split())

if n * a < b:
    print (n*a)
else:
    print (b)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,t=map(int, input().split())
print(max([a*b,t]))

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
a,b,t=map(int, input().split())
print(min([a*b,t]))
Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
x,y,z=map(int,input().split())
min(x*y,z)

Failing test case input:
7 17 120

Expected output:
119

Actual output:

Fixed submission (verdict: Accepted):
x,y,z=map(int,input().split())
print(min(x*y,z))

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,A,B = map(int,input().split())

x = N * B
if x > B:
    print(B)
else:
    print(x)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
N,A,B = map(int,input().split())

x = N * A
if x < B:
    print(x)
else:
    print(B)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, a, b = map(int, input().split())
if (n*a) > b:
  print(n*a)
else:
  print(b)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n, a, b = map(int, input().split())
if (n*a) < b:
  print(n*a)
else:
  print(b)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int, input().split())
ans = min(n*a, b)

Failing test case input:
7 17 120

Expected output:
119

Actual output:

Fixed submission (verdict: Accepted):
n,a,b = map(int,input().split())
ans = min(n*a, b)
print(ans)

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,a,b = map(int,input().split())
print(max(n*a,b))

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
n,a,b = map(int,input().split())
print(min(n*a,b))

Problem: p03501
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c=map(int,input().split())
if a*b>c:
  print(a*b)
else:
  print(c)

Failing test case input:
7 17 120

Expected output:
119

Actual output:
120


Fixed submission (verdict: Accepted):
a,b,c=map(int,input().split())
if a*b>c:
  print(c)
else:
  print(a*b)
Problem: p03695
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
iro=[0 for i in range(8)]
tyi=0
for i in range(n):
  if a[i]<3200:
    iro[int(a[i]/400)]=1
  else:
    tyi+=1
print(max(iro.count(1),1),min(iro.count(1)+tyi,8))

Failing test case input:
20
1304 147 010 4828 55 3273 372 3 9 22 255 754 875 3080 0 2010 79 512 1914 427

Expected output:
7 9


Actual output:
7 8


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]
iro=[0 for i in range(8)]
tyi=0
for i in range(n):
  if a[i]<3200:
    iro[int(a[i]/400)]=1
  else:
    tyi+=1
print(max(iro.count(1),1),iro.count(1)+tyi)

Problem: p03695
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
c = [0]*8
d = 0
for x in a:
  if x >= 3200:
    d += 1
  for i in range(8):
    if x < 400*(i+1):
      c[i] = 1
      break
s = sum(c)
print(max(s,1), min(8,s+d))

Failing test case input:
20
1304 147 010 4828 55 3273 372 3 9 22 255 754 875 3080 0 2010 79 512 1914 427

Expected output:
7 9


Actual output:
7 8


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
c = [0]*8
d = 0
for x in a:
  for i in range(8):
    if x < 400*(i+1):
      c[i] = 1
      break
  if x >= 3200:
    d += 1
s = sum(c)
print(max(s,1), s+d)

Problem: p03695
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
*A,=map(int, input().split())
col = [0]*8
free=0
for a in A:
    for i in range(8):
        if 400*i <= a < 400*(i+1): col[i] = 1
    if a >= 3200: free+=1

print(sum(col), min(8, sum(col)+free))


Failing test case input:
20
1304 147 010 4828 55 3273 372 3 9 22 255 754 875 3080 0 2010 79 512 1914 427

Expected output:
7 9


Actual output:
7 8


Fixed submission (verdict: Accepted):
N=int(input())
*A,=map(int, input().split())
col = [0]*8
free=0
for a in A:
    for i in range(8):
        if 400*i <= a < 400*(i+1): col[i] = 1
    if a >= 3200: free+=1

print(1 if sum(col) == 0 and free else sum(col), sum(col)+free)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = str(input())
E = [0]
W = [0]

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

E = E[1:]
W = W[1:]

ans = n*2

for i in range(1,n-1):
    ans = min(ans,W[i-1]+(E[-1] - E[i+1]))

print(ans)

Failing test case input:
12
EWWWEEEWEWWE

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

for i in range(n+1):
    ans = min(ans,W[i] + (n-i)-(W[-1] - W[i]))
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
count_e = [0] * (N + 1)
count_w = [0] * (N + 1)
for i in range(0, N):
    if S[i] == "W":
        count_w[i+1] = count_w[i] + 1
    else:
        count_w[i+1] = count_w[i]

    if S[N-i-1] == "E":
        count_e[i+1] = count_e[i] + 1
    else:
        count_e[i+1] = count_e[i]

count_e = count_e[::-1]
ans = float('inf')
for i in range(1, N):
    ans = min(ans, count_w[i-1] + count_e[i+1])
print(ans)

Failing test case input:
5
EWEWW

Expected output:
1


Actual output:
0


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

    if S[N-i-1] == "E":
        count_e[i+1] = count_e[i] + 1
    else:
        count_e[i+1] = count_e[i]

count_e = count_e[::-1]
ans = float('inf')
for i in range(N):
    ans = min(ans, count_w[i] + count_e[i])
print(ans)

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

Failing test case input:
12
WEWWWEWEWEEE

Expected output:
6


Actual output:
-1


Fixed submission (verdict: Accepted):
n=int(input())
w=input()
ans=[0 for i in range(n)]
for i in range(1,n):
  if w[i]=="E":
    ans[0]+=1
for i in range(1,n):
  ans[i]=ans[i-1]
  if w[i]=="E":
    ans[i]-=1
  if w[i-1]=="W":
    ans[i]+=1
print(min(ans))
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
lm = [0] *(n+1)
rm = [0] *(n+1)

def check_l(x):
    if x=='W':
        r = 1
    else:
        r = 0
    return r
def check_r(x):
    if x=='E':
        r = 1
    else:
        r = 0
    return r
    
for i in range(1,n):
    lm[i+1] = lm[i] + check_l(s[i-1])
    rm[i] = rm[i+1] + check_r(s[i])
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,lm[i]+rm[i])
print(ans)

Failing test case input:
8
WWEWWWEE

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
lm = [0] *(n+1)
rm = [0] *(n+1)

def check_l(x):
    if x=='W':
        r = 1
    else:
        r = 0
    return r
def check_r(x):
    if x=='E':
        r = 1
    else:
        r = 0
    return r
    
for i in range(1,n):
    lm[i+1] = lm[i] + check_l(s[i-1])
for i in range(n-1,0,-1):
    rm[i] = rm[i+1] + check_r(s[i])
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,lm[i]+rm[i])
print(ans)

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

sumW=s[1:].count("W")
sumE=s[1:].count("E")

p=[]
e=sumE
w=0
p.append(e)
for i in range(n-1):
    
    if s[i]=="W":
        w+=1
    else:
        e-=1
    p.append(w+e)
    
print(min(p))
        
        

Failing test case input:
12
EEWEWEWEWEWW

Expected output:
4


Actual output:
3


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

sumW=s[1:].count("W")
sumE=s[1:].count("E")

p=[]
e=sumE
w=0
p.append(e)
for i in range(n-1):
    
    if s[i]=="W":
        w+=1
    if s[i+1]=="E":
        e-=1
    p.append(w+e)
    
print(min(p))

Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
a = [str(c) for c in s]

x = a.count('E')
y = x
for i in range(n-1):
    if a[i] == 'W':
        if a[i+1] == 'W':
            x += 1
        else:
            x = x
    else:
        if a[i+1] == 'W':
            x = x
        else:
            x -= 1
    if y > x:
        y = x

print(y)


Failing test case input:
12
EEEEEWWEWWWW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
a = [str(c) for c in s]

x = a.count('E')
if a[0] == 'E':
    x -= 1
y = x
for i in range(n-1):
    if a[i] == 'W':
        if a[i+1] == 'W':
            x += 1
        else:
            x = x
    else:
        if a[i+1] == 'W':
            x = x
        else:
            x -= 1
    if y > x:
        y = x
        



print(y)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in S:
    if e == "E":
        count_E -= 1
    elif e == "W":
        count_W += 1
    if count < ans :
        ans = count
print(ans)

Failing test case input:
12
EWEWEEEWWWEW

Expected output:
3


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
li = []
a = s.count("E")
li.append(a)

for i in range(n-1):
    if s[i] == "E" and s[i+1] == "E":
        a -= 1
        li.append(a)
    elif s[i] == "W" and s[i+1] == "W":
        a += 1
        li.append(a)
print(min(li))


Failing test case input:
8
EEWWWWWE

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
li = []
a = s[1:].count("E")
li.append(a)

for i in range(n-1):
    if s[i] == "E" and s[i+1] == "E":
        a -= 1
        li.append(a)
    elif s[i] == "W" and s[i+1] == "W":
        a += 1
        li.append(a)
print(min(li))

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
MIN = float('inf')
left = S[0].count('W')
right = S[1:].count('E')
for i in range(1,N):
  if S[i] == 'W':
    left += 1
  else:
    right -= 1
  
  if i==N-1:
    MIN = min(MIN,S[:i].count('W'))
  else:
    MIN = min(left+right,MIN)
print(MIN)
  

Failing test case input:
5
EWWWE

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
left = 1 if S[0] == 'W' else 0
right = S[1:].count('E')
MIN =  right 
for i in range(1,N):
  if S[i] == 'W':
    MIN = min(MIN,left+right)
    left += 1
  else:
    MIN = min(MIN,left+right)
    right -= 1
  
  if i==N-1:
    MIN = min(MIN,S[:i].count('W'))

print(MIN)

Problem: p03341
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    if S[0] == "E":
        e -= 1
    for s in S:
        ans = min(ans, w+e)
        if s == "E":
            e -= 1
        else:
            w += 1
    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
12
EEEWEWEWWWEW

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    for s in S:
        if s == "E":
            e -= 1
        ans = min(ans, w+e)
        if s == "W":
            w += 1
    print(ans)


if __name__ == '__main__':
    main()
Problem: p03341
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
S = input()
c = S.count("E") - S.startswith("E")
ans = c
for s in S:
    if s == "W":
        c += 1
    else:
        c -= 1
        ans = min(c,ans)
print(ans)

Failing test case input:
5
EWWEW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
c = S.count("E") - S.startswith("E")
ans = c
for i in range(N-1):
    s = S[i]
    if i<N-1 and S[i+1] == "E":
        c -= 1
    if s == "W":
        c += 1
    ans = min(c,ans)
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count
for i in range(N):
    if i == 0 and S[i] == "E":
        count_E -= 1
    else:
        if S[i-1] == "E" and i != 1:
            count_E -= 1
        elif S[i-1] == "W":
            count_W += 1
    if count < ans :
        ans = count
print(ans)

Failing test case input:
8
WEEWWEWW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)

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

e = s.count('E')
w = 0
a = e+w
for i in range(1,n):
    if s[i] == 'E':
        e -= 1
    if s[i-1] == 'W':
        w += 1
    a = min(a, e+w)
print(a)

Failing test case input:
8
EWWWWEEW

Expected output:
2


Actual output:
3


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

e = s[1:].count('E')
w = 0
a = e+w
for i in range(1,n):
    if s[i] == 'E':
        e -= 1
    if s[i-1] == 'W':
        w += 1
    a = min(a, e+w)
print(a)

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

rcost = 0
lcost = S.count('E')
ans = lcost

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

Failing test case input:
12
EWWWEWEWEWEE

Expected output:
5


Actual output:
6


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

rcost = 0
lcost = S.count('E')
if S[0] == 'E':
    lcost -= 1
ans = lcost

for i in range(N-1):
        if S[i] == 'W':
            rcost += 1
        if S[i+1] == 'E':
            lcost -= 1
        ans = min(ans, rcost+lcost)
    
print(ans)
Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
S = list(input())

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i+1]
  
  ans = min(c,ans)

print(ans)
    

  


Failing test case input:
5
EWEWW

Expected output:
1


Actual output:
0


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

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i]
  
  ans = min(c,ans)

print(ans)

Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



import sys

from collections import Counter

N = int(input())

S = input()

l = 0
r = Counter(S[1:])["E"]
print(f"{l=}{r=}")

ans = l + r
flg = False

for i in range(N):
    if flg:
        l += 1
    flg = False
    if S[i] == "E":
        r -= 1

    ans = min(ans, l + r)

    if S[i] == "W":
        flg = True


print(ans)


Failing test case input:
12
EEWWWWEEEWEW

Expected output:
4


Actual output:
l=0r=5
3


Fixed submission (verdict: Accepted):



import sys

from collections import Counter

N = int(input())

S = input()

e = [0]
w = [0]

for s in S:
    if s == "W":
        w += [w[-1] + 1]
        e += [e[-1]]
    elif s == "E":
        w += [w[-1]]
        e += [e[-1] + 1]

ans = 3 * (10 ** 5) + 1

for i in range(N):
    c = w[i]
    c += e[N] - e[i + 1]
    ans = min(c, ans)

print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
 
left = 0
right = S[0:].count("E")
ans = left + right

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

Failing test case input:
12
EWWEEWWEWEWE

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
 
left = 0
right = S[1:].count("E")
ans = left + right

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
input()
ss = input()
loss = ss[1:].count("E")
min_loss = loss
ss_before = ss[:-1]
ss_after = ss[1:]
for b, a in zip(ss_before, ss_after):
    loss += b == "W"
    if a == "W":
        loss -=1
    else:
        loss +=1
    if loss < min_loss:
        min_loss = loss
print("{}".format(min_loss))

Failing test case input:
12
EWEWEEEWWWEW

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
input()
ss = input()
loss = ss[1:].count("E")
min_loss = loss
ss_before = ss[:-1]
ss_after = ss[1:]
for b, a in zip(ss_before, ss_after):
    loss += b == "W"
    loss -= a == "E"
    if loss < min_loss:
        min_loss = loss
print("{}".format(min_loss))
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()

w_left = 0
e_right = S[1:].count("E")
ans = float('inf')
for i in range(N-1):
    if i != 0:
        if S[i+1] == "E":
            e_right -= 1
        elif S[i-1] == "W":
            w_left += 1
    ans = min(ans, w_left + e_right)
print(ans)


Failing test case input:
12
WWWWEEEWEEEW

Expected output:
5


Actual output:
2


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

w_left = 0
e_right = S[1:].count("E")
ans = float('inf')
for i in range(N):
    if i != 0:
        if S[i] == "E":
            e_right -= 1
        if S[i-1] == "W":
            w_left += 1
    ans = min(ans, w_left + e_right)
print(ans)

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


ans=10**100
a=s.count('W',0,1)
b=s.count('E',0,n)
for i in range(n):
    if a+b-1<=ans:
        ans=a+b-1
    if s[i]=='W':
        a+=1
    if s[i]=='E':
        b-=1
print(ans)


Failing test case input:
12
EEEEEWWEWWWW

Expected output:
1


Actual output:
0


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

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

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
S=list(input())
nsums=[0]*N

right =0
for s in S:
  if s=='E':right+=1

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  if S[i]=='W':left+=1
  nsums[i] = right + left
  min_sum = min(min_sum,nsums[i])
print(min_sum)

Failing test case input:
8
WWEWWEWE

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N=int(input())
S=list(input())
nsums=[0]*N

right =0
for s in S:
  if s=='E':right+=1

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  nsums[i] = right + left
  if S[i]=='W':left+=1

  min_sum = min(min_sum,nsums[i])
print(min_sum)

Problem: p03341
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E'] - (1 if s[0] == 'E' else 0)
best = tmp
for i in range(1, n):
    if s[i - 1] == 'W':
        tmp += 1
    else:
        tmp -= 1
    if tmp < best:
        best = tmp
print(best)


Failing test case input:
5
EWWEW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E']
best = tmp - (1 if s[0] == 'E' else 0)
for i in range(1, n):
    if s[i - 1] == 'W':
        tmp += 1
    else:
        tmp -= 1
    if tmp - (1 if s[i] == 'E' else 0) < best:
        best = tmp - (1 if s[i] == 'E' else 0)
print(best)
Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):



import sys

from collections import Counter

N = int(input())

S = input()

l = 0
r = Counter(S[1:])["E"]

ans = l + r
flg = False

for i in range(N):
    if flg:
        l += 1
    flg = False
    if S[i] == "E":
        r -= 1

    ans = min(ans, l + r)

    if S[i] == "W":
        flg = True


print(ans)


Failing test case input:
12
EEWWEEEWWWEW

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):



import sys

from collections import Counter

N = int(input())

S = input()

e = [0]
w = [0]

for s in S:
    if s == "W":
        w += [w[-1] + 1]
        e += [e[-1]]
    elif s == "E":
        w += [w[-1]]
        e += [e[-1] + 1]

ans = 3 * (10 ** 5) + 1

for i in range(N):
    c = w[i]
    c += e[N] - e[i + 1]
    ans = min(c, ans)

print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

Failing test case input:
8
EWEWWWEW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

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


count = 0
for e,i in enumerate(s):
    if e == 0:
        continue
    if i == 'E':
        count += 1

mincount = count
for e,i in enumerate(s):
    if e == len(s)-1:
        break

    if i == 'W':
        count+=1
    else:
        count-=1

    if s[e+1] == 'E':
        mincount = min(count-1,mincount)
    else:
        mincount = min(count,mincount)

print(mincount)


Failing test case input:
12
EWWWEWEWEWEE

Expected output:
5


Actual output:
4


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


count = 0
for e,i in enumerate(s):
    if e == 0:
        continue
    if i == 'E':
        count += 1

mincount = count
for e,i in enumerate(s):
    if e == len(s)-1:
        break
    if e == 0 and i == 'E':
        continue
    if i == 'W':
        count+=1
    else:
        count-=1

    if s[e+1] == 'E':
        mincount = min(count-1,mincount)
    else:
        mincount = min(count,mincount)

print(mincount)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))

ans = float('Inf')
for i in range(1,n):
    
    
    w = B[i]
    
    
    
    e = n - i - B[-1] + B[i]
    
    
    ans = min(ans,w+e)
print(ans)


Failing test case input:
12
WWEWEWWEEWEE

Expected output:
6


Actual output:
7


Fixed submission (verdict: Accepted):
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))

ans = float('Inf')
for i in range(0,n+1):
    
    
    w = B[i]
    
    
    
    e = n - i - B[-1] + B[i]
    
    
    ans = min(ans,w+e)
print(ans)

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

Failing test case input:
12
EWWEWEEEWWWE

Expected output:
4


Actual output:
5


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

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

A = [0]*(N+1) 


for i in range(1, N+1):
    k = 0
    if S[i-1] == "W":
        k = 1
    A[i]=k
    


ans=0
for i in range(1, N+1):
    ans = min(ans, k+A[i-1])

if ans==0: 
    ans=1
print(ans)

Failing test case input:
8
WWEWWEEW

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

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

rcost = 0
lcost = S.count('E')
ans = lcost

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

Failing test case input:
12
WEEEWWEEWWWE

Expected output:
4


Actual output:
1 5
1 4
1 3
1 3
2 3
3 2
3 1
3 1
4 1
5 1
6 0
4


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

rcost = 0
lcost = S.count('E')
if S[0] == 'E':
    lcost -= 1
ans = lcost

for i in range(N-1):
        if S[i] == 'W':
            rcost += 1
        if S[i+1] == 'E':
            lcost -= 1
        ans = min(ans, rcost+lcost)
    
print(ans)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
s = input()

ans = 0
count = 0

for i in s:
    print(i)
    if i == 'W':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)


Failing test case input:
5
EWEWW

Expected output:
1


Actual output:
E
W
E
W
W
1


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

ans = 0
count = 0

for i in s:
    if i == 'W':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count + 1
for e in S:
    if e == "E":
        count_E -= 1
    elif e == "w":
        count_w += 1
    if count < ans :
        ans = count
print(ans)

Failing test case input:
12
EWEWEWWEWWEE

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j



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

if ans==0: 
    ans=1

print(ans)

Failing test case input:
8
EEEWWWWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

Problem: p03341
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    if S[0] == "E":
        e -= 1
    for s in S:
        if s == "E":
            e -= 1
        ans = min(ans, w+e)
        if s == "W":
            w += 1
    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
12
EEEWEWEWWWEW

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    for s in S:
        if s == "E":
            e -= 1
        ans = min(ans, w+e)
        if s == "W":
            w += 1
    print(ans)


if __name__ == '__main__':
    main()
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
 
ans = len(S) - 1
left = 0
right = S[0:].count("E")

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

Failing test case input:
8
EWWEWWWE

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
 
left = 0
right = S[1:].count("E")
ans = left + right

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(ans)


Failing test case input:
8
WWEWWEEW

Expected output:
3


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


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(min(ans))

Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




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


acme = list()
acmw = list()
acme.append(0)
acmw.append(0)
ans = n+1


for i in range(n):
    if s[i] == 'E':
        acme.append(acme[i] + 1)
        acmw.append(acmw[i])
    elif s[i] == 'W':
        acme.append(acme[i])
        acmw.append(acmw[i] + 1)

acme.append(acme[n])
acmw.append(acmw[n])


for i in range(1, n+1):
    ecnt = acme[n] - acme[i+1]
    wcnt = acmw[i-1]
    wcnt = ecnt + wcnt
    ans = min(ans, wcnt)


print(ans)

Failing test case input:
12
EEWEWEWEWEWW

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):




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


acme = list()
acmw = list()
acme.append(0)
acmw.append(0)
ans = n+1


for i in range(n):
    if s[i] == 'E':
        acme.append(acme[i] + 1)
        acmw.append(acmw[i])
    elif s[i] == 'W':
        acme.append(acme[i])
        acmw.append(acmw[i] + 1)

acme.append(acme[n])
acmw.append(acmw[n])


for i in range(1, n+1):
    ecnt = acme[n] - acme[i]
    wcnt = acmw[i-1]
    wcnt = ecnt + wcnt
    ans = min(ans, wcnt)


print(ans)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999

l = 0
r = sum(a)
for i in range(n-1):

    if i == 0:
        r -= a[i]
        l = 0
        a[i] = 1
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    
print(ans)



Failing test case input:
12
EEWEWEEWWWEW

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999

l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    
print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
debug = True

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

    tmpCnt=S.count('E')
    if S[0]=='E':
        minCnt=tmpCnt-1
    else:
        minCnt=tmpCnt

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

if __name__ == "__main__":
    main()



Failing test case input:
8
EWEEWWWW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
debug = False

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

    tmpCnt=S.count('E')
    if S[0]=='E':
        tmpCnt-=1

    minCnt=tmpCnt

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

if __name__ == "__main__":
    main()

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

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


Failing test case input:
8
WWWEWEEW

Expected output:
3


Actual output:
4


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

l=[]
c=s.count('E',1)
for i in range(1,n):
    if s[i-1]=='W':
        c+=1
    if s[i]=='E':
        c-=1
    l.append(c)
print(min(min(l),s.count('E')))
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = list(input())

A = [0]*(N+1) 


for i in range(1, N+1):
    k = 0
    if S[i-1] == "W":
        k = 1
    A[i]=k
    


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

if ans==0: 
    ans=1
print(ans)

Failing test case input:
8
WWEWWWEE

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

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

ans = 0
count = 0

for i in s:
    if i == 'w':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)


Failing test case input:
12
WEEWWEEEWWWE

Expected output:
4


Actual output:
0


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

ans = 0
count = 0

for i in s:
    if i == 'W':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

if ans==0: 
    ans=1

print(ans)

Failing test case input:
8
EEEWWWWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
s=list(input())
p=[0,0]
l=[s.count("E"),s.count("W")]
t=[]
for i in range(n):
    if s[i]=="E":
        t.append(l[0]+p[1]-1)
        l[0]-=1
        p[0]+=1
    else:
        t.append(l[1]+p[0])
        l[1]-=1
        p[1]+=1
print(min(t))

Failing test case input:
8
WWWWWEEE

Expected output:
3

Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
s=list(input())
p=[0,0]
l=[s.count("E"),s.count("W")]
t=[]
for i in range(n):
    if s[i]=="E":
        t.append(l[0]+p[1]-1)
        l[0]-=1
        p[0]+=1
    else:
        t.append(l[0]+p[1])
        l[1]-=1
        p[1]+=1
print(min(t))
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()
S = list(input())

min_num = 300000
left = 0

for i in range(len(S)):

  if i > 0:
    left += int(S[i] == "W")
    
  right = S[i+1: ].count("E")

  if left + right < min_num:
    min_num = left + right

print(min_num)


Failing test case input:
8
WWEEWWEW

Expected output:
3


Actual output:
2


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

length = len(S)
min_num = 300000
left = 0
right = S.count("E")

for i in range(length):

  if i > 0:
    left += int(S[i - 1] == "W")

  if i < length:
    right -= int(S[i] == "E")

  if left + right < min_num:
    min_num = left + right

print(min_num)

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

length = len(S)
min_num = 300000
left = 0
right = S.count("E")

for i in range(length):

  if i > 0:
    left += int(S[i - 1] == "W")

  if i < length - 1:
    right -= int(S[i + 1] == "E")

  if left + right < min_num:
    min_num = left + right

print(min_num)


Failing test case input:
8
WEWWWEEW

Expected output:
3


Actual output:
2


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

length = len(S)
min_num = 300000
left = 0
right = S.count("E")

for i in range(length):

  if i > 0:
    left += int(S[i - 1] == "W")

  if i < length:
    right -= int(S[i] == "E")

  if left + right < min_num:
    min_num = left + right

print(min_num)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = str(input())
E = [0]
W = [0]

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

E = E[1:]
W = W[1:]

ans = min(W[-1]-W[0],E[-1])

for i in range(1,n):
    ans = min(ans,W[i-1]+(E[-1] - E[i]))

print(ans)

Failing test case input:
12
WEWWWEEWEWEE

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

for i in range(n+1):
    ans = min(ans,W[i] + (n-i)-(W[-1] - W[i]))
print(ans)
Problem: p03341
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections


def main():
    N = int(input())
    S = input()
    cnt = collections.Counter(S)
    E_cnt = cnt['E']
    W_cnt = cnt['W']
    tmp = 0
    if S[0] == 'E':
        ans = E_cnt - 1
    else:
        ans = E_cnt
    for i in range(1, N):
        if S[i] == 'E':
            E_cnt -= 1
        else:
            W_cnt -= 1
        if S[i - 1] == 'W':
            tmp += 1
        ans = min(ans, tmp + E_cnt)

    print(ans)


if __name__ == "__main__":
    main()


Failing test case input:
12
EEWWEWEEWWEW

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
import collections


def main():
    N = int(input())
    S = input()
    cnt = collections.Counter(S)
    E_cnt = cnt['E']
    W_cnt = cnt['W']
    tmp = 0
    if S[0] == 'E':
        E_cnt -= 1
    ans = E_cnt
    for i in range(1, N):
        if S[i] == 'E':
            E_cnt -= 1
        else:
            W_cnt -= 1
        if S[i - 1] == 'W':
            tmp += 1
        ans = min(ans, tmp + E_cnt)

    print(ans)


if __name__ == "__main__":
    main()

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

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

position = []
for s in S:
    if s == 'W':
        position.append(-1)
    else:
        position.append(1)
i = 0
flips = N + 1
while i < N:
    flips_temp = 0
    j  = 0
    while j < N:
        if j < i:
            flips_temp += (1 - position[j]) / 2.
        if j > i:
            flips_temp += (1 + position[j]) / 2.
        j = j + 1
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

Failing test case input:
12
WWEWWWWEEEEE

Expected output:
6


Actual output:
6.0


Fixed submission (verdict: Accepted):
import sys

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

position_L = []
position_R = []
for s in S:
    if s == 'W':
        position_R.append(0)
    else:
        position_R.append(1)
        
flips = sum(position_R[1:])
flips_temp = flips

i = 1
while i < N:
    
    flips_temp = flips_temp - position_R[i] + ((-1) * position_R[i-1] + 1)
    if flips_temp < flips:
        flips = flips_temp
    i = i + 1
print(flips)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = str(input())
E = [0]
W = [0]
for i in range(n):
    if s[i] == "E":
        E.append(E[-1]+1)
        W.append(W[-1])
    else:
        E.append(E[-1])
        W.append(W[-1]+1)

ans = min(W[-1],E[-1])

for i in range(2,n):
    ans = min(ans,W[i-1]+(E[-1] - E[i+1]))
print(ans)

Failing test case input:
12
WEWEWWEEEWEW

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

for i in range(n+1):
    ans = min(ans,W[i] + (n-i)-(W[-1] - W[i]))
print(ans)
Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
count_E = 0
min_change = 0
change = 0
W_flag = True
if S[0] == 'E':
    count_E += 1
    W_flag = False
for i in range(1, len(S)):
    if W_flag:
        change += 1
    if S[i] == 'E':
        count_E += 1
        W_flag = False
        change -= 1
        min_change = min(change, min_change)
    elif S[i] == 'W':
        W_flag = True
ans = count_E + min_change
print(ans)


Failing test case input:
12
EWWEWEEEWWWE

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
count_E = 0
min_change = 0
change = 0
W_flag = True
if S[0] == 'E':
    W_flag = False
for i in range(1, len(S)):
    if W_flag:
        change += 1
    if S[i] == 'E':
        count_E += 1
        W_flag = False
        change -= 1
        min_change = min(change, min_change)
    elif S[i] == 'W':
        W_flag = True
ans = count_E + min_change
print(ans)

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

CNT = []
c = 0
for s in S:
  if s == "E":
    c += 1
  CNT.append(c)
  
ans = N + 10
mn = N + 10
for i in range(N):
  c = 0
  if i > 0:
    c += i - 1 - CNT[i-1]
  if i < N - 1:
    c +=  N - i - 1 - (CNT[N-1] - CNT[i+1])
    
  if c < mn:
    ans = i+1

print(ans)
    

  


Failing test case input:
8
EEEWWWWW

Expected output:
0


Actual output:
8


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

EAST = []
WEST = []
e = 0
w = 0
for s in S:
  if s == "E":
    e += 1
  else:
    w += 1
  EAST.append(e)
  WEST.append(w)
  
ans = N - 1
for i in range(N):
  c = 0
  if i > 0:
    c += WEST[i-1]
  if i < N - 1:
    c += EAST[N-1] - EAST[i]
  
  ans = min(c,ans)

print(ans)

Problem: p03341
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j

print(A)


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

if ans==0: 
    ans=1

print(ans)

Failing test case input:
8
EWWWWEWE

Expected output:
2


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


Fixed submission (verdict: Accepted):
from itertools import accumulate

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

A = [0]*(N+1) 


for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j




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

print(ans)