ZhenlongDai/ACPR huggingface dataset:
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
stone = input()

R_count = 0
W_count = 0
for i in range(len(stone)):
  if stone[i] == "R":
    R_count = R_count + 1
  else:
    W_count = W_count + 1

W = 0
R = R_count
try_num_prev = -1
for i in range(N):
  if R_count == 0 or W_count == 0:
    try_num = 0
    break
  
  if W <= R:
    try_num = R
  else:
    try_num = W
  
  if try_num_prev > 0 and try_num_prev < try_num:
    try_num = try_num_prev
    break
  else:
    try_num_prev = try_num
    if stone[i] == "R":
      R = R - 1
    else:
      W = W + 1
    
print(try_num)

Failing test case input:
4
RTWW

Expected output:
0


Actual output:
1


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

R_count = 0
W_count = 0
for i in range(len(stone)):
  if stone[i] == "R":
    R_count = R_count + 1
  else:
    W_count = W_count + 1

W = 0
R = R_count
try_num_prev = -1
for i in range(N):
  if R_count == 0 or W_count == 0:
    try_num = 0
    break
  
  if W <= R:
    try_num = R
  else:
    try_num = W
  
  
  if try_num_prev >= 0 and try_num_prev < try_num:
    try_num = try_num_prev
    break
  else:
    try_num_prev = try_num
    if stone[i] == "R":
      R = R - 1
    else:
      W = W + 1
    
print(try_num)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import collections

c=input()
c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]-count_r:
            ans+=1
            dis_r+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)

Failing test case input:
8
RRRWRWWW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import collections

c=input()
c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]:
            ans+=1
            dis_r+=1
        else:
            ans+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
S = input()

l = 0
r = len(S) - 1

W = 'W'
R = 'R'

cnt = 0
while l < r:
    if S[l] == R:
        l += 1
        continue
    else:
        while l < r:
            if S[r] == W:
                r -= 1
                continue
            else:
                cnt += 1
                l += 1
                r -= 1

print(cnt)


Failing test case input:
8
WWRRWWRR

Expected output:
2


Actual output:
3


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

l = 0
r = len(S) - 1

W = 'W'
R = 'R'

cnt = 0
while l < r:
    if S[l] == R:
        l += 1
        continue
    else:
        while l < r:
            if S[r] == W:
                r -= 1
                continue
            else:
                cnt += 1
                l += 1
                r -= 1
                break

print(cnt)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
C = list(input())

i = 0
j = N-1
count = 0 
frag = True
Frag_f = True
Frag_b = True
while (frag):
    if i >= j:
        break
    if Frag_f == True:
        if C[i] == "R":
            i = i + 1
        else:
            Frag_f = False
    
    if Frag_b == True:
        if C[j] == "w":
            j = j - 1
        else:
            Frag_b = False
    
    if Frag_b == False and Frag_f == False:
        count += 1
        Frag_f = True
        Frag_b = True
        i = i+1
        j = j-1
print(count)

Failing test case input:
8
WWRRVRWR

Expected output:
2


Actual output:
3


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

i = 0
j = N-1
count = 0 
frag = True
Frag_f = True
Frag_b = True
while (frag):
    if i >= j:
        break
    if Frag_f == True:
        if C[i] == "R":
            i = i + 1
        else:
            Frag_f = False
    if Frag_b == True:
        if C[j] == "W":
            j = j - 1
        else:
            Frag_b = False
    
    if Frag_b == False and Frag_f == False:
        count += 1
        Frag_f = True
        Frag_b = True
        i = i+1
        j = j-1
print(count)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    N = int(input())
    S = input()
    R = S[::-1]
    cnt = 0
    jdex=0
    for i in range(N):
        if S[i]== 'W':
            for j in range(jdex,N):
                if S[j]=='R':
                    cnt+=1
                    jdex=j+1
                    break
            if j+i+1>=N:
                    print(cnt)
                    return
    print(cnt)


if __name__ == '__main__':
    main()




Failing test case input:
8
WRWRWRWR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    S = input()
    R = S[::-1]
    cnt = 0
    i = 0
    r = N-1
    while i<r:
        if(S[i]=='W'):
            while i<r:
                if S[r]=='R':
                    cnt += 1
                    r -= 1 
                    break
                r -= 1
        i+=1

    print(cnt)


if __name__ == '__main__':
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
c=list(input())

rall=c.count('R')
wlef=c[:rall+1].count('W')

print(wlef)

Failing test case input:
8
WWWRWRRR

Expected output:
3


Actual output:
4


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

rall=c.count('R')
wlef=c[:rall].count('W')

print(wlef)

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

C = input()

if N % 2 == 0:
  mid = N
else:
  mid = N

Wcount = C.count("W", 0, mid)
if N%2!=0 and C[mid-1] == "W":
  Wcount -= 1
print(Wcount)

Failing test case input:
8
RRWWWRWR

Expected output:
2


Actual output:
4


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

C = input()

if N % 2 == 0:
  mid = N
else:
  mid = N

Rcount = C.count("R")
rcount = C.count("R", 0, Rcount)
print(Rcount-rcount)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
w = s.count('W')
an1 = s[-w:].count('R')
an2 = s[:w].count('R')

print(min(an1, an2))

Failing test case input:
8
WWWRRRRW

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))

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









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




def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        if leftW == 0 or rightR == 0:
            result.append(0)
            continue

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


Failing test case input:
8
RWRRWRWW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):









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

def calculate(n, s):
    arr = list(s)

    wNum = arr.count("W")
    RNum = arr.count("R")

    if wNum == 0 or RNum == 0:
        print(0)
        return

    leftW = 0
    rightR = RNum



    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
c=list(input())

rc=c.count('R')
mini=min(rc,n-rc)
for i in range(n):
  if c[i]=='R':
    rc-=1
  
  mini=min(mini,max(rc,n-rc))
  
print(mini)
    
  

Failing test case input:
8
WRWRVWRR

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
c=list(input())
 
rj=c.count('R')
wj=0
mini=rj
for i in range(n):
  if c[i]=='R':
    rj-=1
  else:
    wj+=1
  mini=min(mini,max(rj,wj))
  
print(mini)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
    if i+1<=len(c)/2 and c[i]=='R':
        hrcnt += 1
if rcnt==len(c) or rcnt==0:
    ans = 0
elif rcnt<len(c)/2:
    ans = rcnt
elif rcnt>len(c)/2:
    ans = len(c)-rcnt
else:
    ans = rcnt-hrcnt

print(ans)

Failing test case input:
4
RPWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
for i in range(len(c)):
    if i+1<=rcnt and c[i]=='R':
        hrcnt += 1

wcnt = len(c)-rcnt
if rcnt==len(c) or rcnt==0:
    ans = 0
else:
    ans = rcnt-hrcnt

print(ans)
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
c = input()
wc = c.count("W")
rc = c.count("R")

ans = min(c[rc:].count("R"), c[:wc].count("W"))
print(ans)


Failing test case input:
8
WRRWXWRR

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
c = input()
wc = c.count("W")
rc = c.count("R")

ans = min(c[rc:].count("R"), c[:-wc].count("W"))
print(ans)

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

r = S.count('R')
w = S.count('W')

if r == N or r == 0:
  print(0)
  exit()

a = S[:r+1].count('W')

print(a)

Failing test case input:
8
RRWWWRWR

Expected output:
2


Actual output:
3


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

r = S.count('R')
w = S.count('W')

if r == N or r == 0:
  print(0)
  exit()

a = S[:r].count('W')

print(a)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    C = input()
    i = 0
    j = N - 1
    ANS = 0
    if C.find('W') == -1 or C.find('R') == -1:
        print(0)
        return
    while 1 == 1:
        i = C.find('W')
        j = C.rfind('R')
        if i >= j:
            break
        if i + 1 == j:
            ANS += 1
            break
        C = C[i+1:j]
        ANS += 1
    print(ANS)
if __name__ == '__main__':
    main()

Failing test case input:
4
WRVR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    C = input()
    
    ANS = 0
    while 1 == 1:
        i = C.find('W')
        j = C.rfind('R')
        if i == -1 or j == -1:
            break
        if i >= j:
            break
        if i + 1 == j:
            ANS += 1
            break
        C = C[i+1:j]
        ANS += 1
    print(ANS)
if __name__ == '__main__':
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
w = s.count('W')
print(s[-w:].count('R'))

Failing test case input:
2
RU

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
cs = input()

cand1 = cs[:cs.count('R')].count('W')
cand2 = cs[cs.count('W'):].count('R')
if cand1 > cand2:
  print(min(cand1, cand2))
else:
  print(max(cand1, cand2))

Failing test case input:
2
RS

Expected output:
0


Actual output:
1


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

cand1 = cs[:cs.count('R')].count('W')
cand2 = cs[cs.count('W'):].count('R')
if cand1 < cand2:
  print(min(cand1, cand2))
else:
  print(max(cand1, cand2))
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import heapq

def input():
    return sys.stdin.readline().rstrip()


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

    Wcount=0
    Rcount =0
    rr =C.count("R")
    ww =C.count("W")


    for j in range(ww):
        if C[j]=="W":
            Rcount+=1

    for i in range(rr):
        if C[-1-i]=="R":
            Wcount+=1

    print(min(Rcount,Wcount))






if __name__ == "__main__":
    main()


Failing test case input:
8
WRWWXRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import heapq

def input():
    return sys.stdin.readline().rstrip()


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

    Wcount=0
    Rcount =0
    rr =C.count("R")
    ww =C.count("W")


    for j in range(rr):
        if C[j]=="W":
            Rcount+=1

    for i in range(ww):
        if C[-1-i]=="R":
            Wcount+=1

    print(min(Rcount,Wcount))






if __name__ == "__main__":
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w+1):]; list_w1 = mozi2[:(a-num_w+1)]
list_r2 = mozi2[(a-num_r+1):]; list_r1 = mozi2[:(a-num_r+1)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)

Failing test case input:
8
WWRRWRWR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
mozi = input()
mozi2 = list(mozi)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(N-num_w):]; list_w1 = mozi2[:(N-num_w)]
list_r2 = mozi2[num_r:]; list_r1 = mozi2[:num_r]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
    print(li)
  print(ans)


if __name__ == '__main__':
  main()

Failing test case input:
8
RWRWRWWR

Expected output:
2


Actual output:
['R', 'R', 'R', 'W', 'R', 'W', 'W', 'W']
['R', 'R', 'R', 'R', 'W', 'W', 'W', 'W']
['R', 'R', 'R', 'R', 'W', 'W', 'W', 'W']
2


Fixed submission (verdict: Accepted):
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
  print(ans)    

if __name__ == '__main__':
  main()
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    n = int(input())
    s = input()
    
    
    
    
    l = 0
    r = n-1
    ans = 0
    while(True):
        if(l >= n or r < 0):
            break
        if(s[l] == "R"):
            l += 1
            continue
        else:
            while(s[r] == "W"):
                if(r < 0):
                    print(0)
                    return
                r -= 1
            l += 1
            r -= 1
            ans += 1
            if(l >= r):
                break
    print(ans)



if __name__ == "__main__":
    main()


Failing test case input:
8
WWWRXRRR

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    s = input()
    
    
    
    
    l = 0
    r = n-1
    ans = 0
    while(True):
        if(l >= n or r < 0):
            break
        if(s[l] == "R"):
            l += 1
            continue
        else:
            while(s[r] == "W"):
                if(r < 0):
                    print(0)
                    return
                r -= 1
            if(l >= r):
                break
            l += 1
            r -= 1
            ans += 1
            if(l >= r):
                break
    print(ans)



if __name__ == "__main__":
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
red = []
white = []
for i in range(n):
  if s[i] == 'W':
    white.append(i)
for i in range(n - 1, -1, -1):
  if s[i] == 'R':
    red.append(i)
print(white, red)
if min(len(red), len(white)) == 0:
  print(0)
  exit()

for i in range(min(len(red), len(white))):
  if white[i] >= red[i]:
    print(i)
    exit()

Failing test case input:
8
WRRWRRWW

Expected output:
2


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


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
red = []
white = []
for i in range(n):
  if s[i] == 'W':
    white.append(i)
for i in range(n - 1, -1, -1):
  if s[i] == 'R':
    red.append(i)

if min(len(red), len(white)) == 0:
  print(0)
  exit()

for i in range(min(len(red), len(white))):
  if white[i] >= red[i]:
    print(i)
    exit()
print(min(len(red), len(white)))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
  s = c[:wc]
  print(wc-s.count('R'))

Failing test case input:
4
RUWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:rc]
    wwc = s.count('W')
    print(wwc)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = list(input())
w = c.count("W")
r = c.count("R")
wr = c[w:].count("W")

print(min(r, w - wr))


Failing test case input:
8
WWRWVRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
c = list(input())
w = c.count("W")
r = c.count("R")
wr = c[len(c) - w:].count("W")

print(min(r, w - wr))
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  i1 += 1
  if i1+i2 >= n-2:
    break
    
print(ans)

Failing test case input:
8
WWRWRRWR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  if i1+i2 >= n-2:
    break
  i1 += 1
print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    tmpw=C.count("W")
    
    C=C[tmpw:]
    
    print(C.count("R"))
    

Failing test case input:
8
WWWRXRRR

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
        tmpw=C.count("W")
        
        
        C=C[(n-tmpw):]
            
        print(C.count("R"))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
        A[i+1] += A[i]
ans = float("inf")
for i in range(1, n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)

Failing test case input:
8
RRWRVRWW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
    A[i+1] += A[i]
ans = float("inf")
for i in range(n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = input()
l = 0
j = 0
a = [0]*n
b = [0]*n
for i in range(n):
  if(c[i]=='W'):
    a[l] =i+1
    l +=1
l = 0
for i in range(n-1,0,-1):
  if(c[i]=='R'):
    b[j] = i+1
    j +=1
j = 0
while(a[l] < b[l]):
      a[l]=0
      b[l]=0
      l+=1
      j+=1
print(j)

Failing test case input:
4
WRTR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
c = input()
l = 0
j = 0
a = [0]*n
b = [0]*n
for i in range(n):
  if(c[i]=='W'):
    a[l] =i+1
    l +=1
l = 0
for i in range(n-1,0,-1):
  if(c[i]=='R'):
    b[j] = i+1
    j +=1
j = 0
while(a[l] < b[l] and not(a[l]==0 or b[l] == 0)):
      a[l]=0
      b[l]=0
      l+=1
      j+=1
print(j)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools

n = int(input())
s = list(input())
left_w = []
right_r = []
for l in s:
    if l == "W":
        left_w.append(1)
    else:
        left_w.append(0)
lacc = list(itertools.accumulate(left_w))
for r in s[::-1]:
    if r == "R":
        right_r.append(1)
    else:
        right_r.append(0)
racc = list(itertools.accumulate(right_r))
racc = racc[::-1]
print(min(map(max, zip(lacc, racc))))


Failing test case input:
4
WRWR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):

import itertools

n = int(input())
s = list(input())
left_w = [0]
right_r = [0]
for l in s:
    if l == "W":
        left_w.append(1)
    else:
        left_w.append(0)
lacc = list(itertools.accumulate(left_w))
for r in s[::-1]:
    if r == "R":
        right_r.append(1)
    else:
        right_r.append(0)
racc = list(itertools.accumulate(right_r))
racc = racc[::-1]
print(min(map(max, zip(lacc, racc))))

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
S = input()

prev = S[0]
cur = 'R'
count = 0
wNum = 0
changedPoint = 0
for i in range(N-1, -1, -1):
    cur = S[i]
    if cur == 'R':
        for j in range(wNum, i):
            if S[j] == 'W':
                wNum = j + 1
                changedPoint = j
                break
        if wNum != 0:
            count += 1

    prev = cur
    if changedPoint >= i:
        break

print(count)


Failing test case input:
8
RRWRWWWR

Expected output:
1


Actual output:
2


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

prev = S[0]
cur = 'R'
count = 0
wNum = 0
changedPoint = -1
changed = False
for i in range(N-1, -1, -1):
    cur = S[i]
    changed = False
    if cur == 'R':
        for j in range(wNum, i):
            wNum = j + 1
            if S[j] == 'W':
                changedPoint = j
                changed = True
                break
        if changed == True:
            count += 1
        elif changedPoint != -1 and wNum < i:
            count += 1
            break
        else:
            break

    prev = cur
    if wNum == i-1:
        break

print(count)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:wc]
    wwc = wc-s.count('R')
    if wwc <= rc:
      print(wwc)
    else:
      print(rc)

Failing test case input:
8
WRWSWRWR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:rc]
    wwc = s.count('W')
    print(wwc)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
C = list(input())

move_right = 0
move_left = N-1

count = 0

while move_right < move_left:
    if C[move_right] == 'R':
        move_right += 1

    else:
        while C[move_left] != 'R' and move_left >= 0:
            move_left -= 1

        if move_left < 0:
            
            if C[move_right + 1] == 'R':
                count += 1

        
        if C[move_left] == 'R':
            count += 1

        move_right += 1
        move_left -= 1


print(count)


Failing test case input:
8
WRRWWWRR

Expected output:
2


Actual output:
3


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

move_right = 0
move_left = N-1

count = 0

while move_right < move_left:
    if C[move_right] == 'R':
        move_right += 1

    else:
        while C[move_left] != 'R' and move_left >= 0:
            move_left -= 1

        if move_left <= move_right:
            
            if C[move_right + 1] == 'R':
                count += 1

        
        elif C[move_left] == 'R':
            count += 1

        move_right += 1
        move_left -= 1


print(count)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
s = int(input()) 
n = input()
str_list = list(n)
w_cnt = str_list.count('W')
r_cnt = str_list.count('R')
w_result = str_list[w_cnt:]
r_result = str_list[:r_cnt]
r = w_result.count('R')
w = r_result.count('W')
if w <= r:
    print(r)
else:
    print(w)


Failing test case input:
8
RWWRVRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
s = int(input())
n = input()
str_list = list(n)
w_cnt = str_list.count('W')
r_cnt = str_list.count('R')
if w_cnt == 0 or r_cnt == 0:
    print(0)
else:
    w_result = str_list[r_cnt:]
    r_result = str_list[:r_cnt]
    r = w_result.count('R')
    w = r_result.count('W')
    if w <= r:
        print(w)
    else:
        print(r)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = str(input())


import collections
a = collections.Counter(c)
t = a["W"]

m = min(a["W"],a["R"])


co = 0

for i,j in enumerate(c):
    if co >=m or i>=t:
        break
    else:

        if j == "W":
            co +=1
        
        

print(min(m,co))


Failing test case input:
8
WWRWVRRR

Expected output:
3


Actual output:
2


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


import collections
a = collections.Counter(c)
t = a["R"]

m = min(a["W"],a["R"])


co = 0

for i,j in enumerate(c):
    if co >=m or i>=t:
        break
    else:

        if j == "W":
            co +=1
        
        

print(min(m,co))
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R >= W:
    for i in range(cnt):
        if list[N-cnt]=="R":
            ans +=1

if R<W:
    for j in range(cnt+1):
        if list[j] == "W":
            ans +=1


print(ans)




Failing test case input:
8
WRWWRRRW

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R > W:
    for i in range(0,cnt):
        if list[N-i-1]=="R":
            ans +=1

if R<=W:
    for j in range(0,cnt):
        if list[j] == "W":
            ans +=1


print(ans)

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

a=0
b=0

a = c.count("R")
ans = c.count("R")
for i in range(N):
    print(i)
    if c[i] == "R":
        a -= 1
    else:
        b += 1

    now = max(a,b)
    ans = min(ans, now)

print(ans)

Failing test case input:
8
WRWWYRRR

Expected output:
3


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


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

a=0
b=0

a = c.count("R")
ans = c.count("R")
for i in range(N):
    if c[i] == "R":
        a -= 1
    else:
        b += 1

    now = max(a,b)
    ans = min(ans, now)

print(ans)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    C.sort()
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1
        else:
            break
    for i in range(N):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Failing test case input:
8
WRWRXWRR

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N=int(input())
    c=input()
    
    
    
    
    
    
    i=0
    for _ in range(N):
        if 'WR' in c:
            x=c.index('WR')  
            y=N-c[::-1].index('R')-1
            
            c=c[:x]+'R'+c[x+1:y]+'W'+c[y+1:]
            
            i+=1
        else:
            break
            
    print(min(c.count('R'),c.count('W'),i))
    

if __name__ == '__main__':
    main()

Failing test case input:
8
RRWWWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
    N=int(input())
    c=list(input())
    
    
    
    
    
    
    res=0
    cR=c.count('R')
    cW=c.count('W')
    
    l,r=0,N-1
    while l!=r:
        if c[l]=='W':
            if c[r]=='R':
                c[l],c[r]='R','W'
                res+=1
            else:
                r-=1
        else:
            l+=1
        
    print(min(cR,cW,res))
    
 
if __name__ == '__main__':
    main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
c = input()

wcount = c.count('R')
count = 0

for i in range(n):
    if c[i] == 'W' and i<= wcount:
        count += 1
print(count)

Failing test case input:
8
WWWRWRRR

Expected output:
3


Actual output:
4


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

count = c.count('R')
ans = 0

for i in range(n):
    if c[i] == 'R' and i >= count:
        ans += 1
print(ans)

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

N = int(input())
C = input()


red_num = str.count(C, "R")


white_num_left = str.count(C[:red_num], "W")


min_ope = white_num_left


print("最小の操作回数: " + str(min_ope))

Failing test case input:
8
WRWRWWRR

Expected output:
2


Actual output:
最小の操作回数: 2


Fixed submission (verdict: Accepted):

N = int(input())
C = input()


red_num = str.count(C, "R")


white_num_left = str.count(C[:red_num], "W")


min_ope = white_num_left


print(min_ope)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import Counter

n = ii()
s = input()

d = Counter(s)
num = d['R']
ans = num
wcnt = 0
rcnt = 0
for i in s:

    if i == 'W':
        wcnt += 1
    else:
        if num - 1 > wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt+1
            wcnt = 0
        if num == 0:
            break
print(ans)

Failing test case input:
8
RRWRWWWR

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import Counter

n = ii()
s = input()

d = Counter(s)
num = d['R']
ans = num
wcnt = 0
rcnt = 0
for i in s:

    if i == 'W':
        wcnt += 1
    else:
        if num - 1 >= wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt+1
            wcnt = 0
        if num == 0:
            break
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex != backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

Failing test case input:
8
RRWWWRWR

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n = input()
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex < backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
C = list(input())
count = list()

for i in range(N):
    W = 0
    R = 0
    for j in range(0,int(N/2+1)):
        if C[j] == 'W':
            W += 1
    for j in range(int(N/2+1),N):
        if C[j] == 'R':
            R += 1
    if W > R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

Failing test case input:
8
WRRWRRWW

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
C = list(input())
count = list()
W = 0
R = 0

for i in C:
    if i == "R":
        R += 1

if R == 0:
    count.append(0)

for i in C:

    if i == "W":
        W += 1
    else:
        R -= 1

    if W <= R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

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


N = int(input())
c_list = list(input())


red_count = 0
white_count = 0
swap_count = 0


for c in c_list:
    if c=="R":
        red_count += 1
    else:
        white_count += 1


w_i = 0
r_i = N-1
while r_i>w_i:
    if c_list[r_i]=="R":
        
        while r_i>w_i and w_i<=N-1:
            if c_list[w_i]=="W":
                break
            w_i += 1
        
        tmp = c_list[r_i]
        c_list[r_i] = c_list[w_i]
        c_list[w_i] = tmp
        swap_count += 1
    else:
        r_i -= 1


ans = min(red_count, white_count, swap_count)
print(ans)


Failing test case input:
8
RRWRVRWW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):


N = int(input())
c_list = list(input())


red_count = 0
white_count = 0
swap_count = 0


for c in c_list:
    if c=="R":
        red_count += 1
    else:
        white_count += 1


w_i = 0
r_i = N-1
while r_i>w_i:
    if c_list[r_i]=="R":
        find_white = False
        
        while r_i>w_i and w_i<=N-1:
            if c_list[w_i]=="W":
                find_white = True
                break
            w_i += 1
        
        if find_white:
            tmp = c_list[r_i]
            c_list[r_i] = c_list[w_i]
            c_list[w_i] = tmp
            swap_count += 1
    else:
        r_i -= 1


ans = min(red_count, white_count, swap_count)
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'R':
        l += 1

    while s[r] == 'W' and l < r:
        r -= 1

    ans += 1
    l += 1
    r -= 1

    if l >= r:
        break
    
print(ans)


Failing test case input:
4
RRTW

Expected output:
0


Actual output:
1


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

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == "R":
        l += 1
    while s[r] == "W" and l != r:
        r -= 1

    if l != r:
        s[l], s[r] = s[r], s[l]
        ans += 1
        
    if l == r:
        break

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    if n%2==0:
        tmpw=C.count("W")
        
        C=C[tmpw:]
        
        print(C.count("R"))
    else:
        tmpw=C.count("W")
        
        C=C[tmpw-1:]
        
        print(C.count("R"))

Failing test case input:
8
RRRRXWWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
        tmpw=C.count("W")
        
        
        C=C[(n-tmpw):]
            
        print(C.count("R"))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

n = int(input())
n2 = n
c = input()

if c.count("R") == n:
    print(0)
else:
    cnt = c.count("W", 0, n2)
    print(cnt)

Failing test case input:
8
RRWWRWRW

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
 
n = int(input())
c = input()
r = c.count("R")
w = c.count("W")
s = c[:r]
s = s.count("W")
print(min(w, s))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i <= b:
    r+=1
  if c[i] == 1 and i > b:
    w+=1
 

print(max(w,r))


Failing test case input:
4
RPWW

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i < b:
    r+=1
  if c[i] == 1 and i >= b:
    w+=1
 

print(max(w,r))
Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('W')].count("W"))

Failing test case input:
8
WWRWVRRR

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):

n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('R')].count("W"))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
c=list(input())
k=0
for i in range(N):
    if c[i]!='R':
        k=i
        break
R=c[k:].count('R')
W=c[k:k+R+1].count('W')
print(W)

Failing test case input:
8
RRWWWWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N=int(input())
c=list(input())
R=c.count('R')
W=0
ans=max(R,W)
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans=min(ans,max(W,R))
print(ans)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
al = list(input())
cr = al.count('R')
print(al[:cr+1].count('W'))


Failing test case input:
8
RRWWWRRW

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
al = list(input())
cr = al.count('R')
print(al[:cr].count('W'))

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    li[i] = "R"
    li[j] = "W"
    ans += 1
  print(ans)


if __name__ == '__main__':
  main()

Failing test case input:
8
RRWRUWRW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
  print(ans)    

if __name__ == '__main__':
  main()

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X = input()
count_w, n, count = X.count('W'), len(X), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)

Failing test case input:
8
RWWWRRRW

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
n, X = int(input()), input()
count_w, count = X.count('W'), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
rw=list(input())
s=len(rw)
i=0
j=s-1
count=0

while i<=j:
  while (rw[i]=='R' and i<s-1):
        i+=1
  while (rw[j]=='W' and j>0):
        j-=1
  if rw[i]=='W' and rw[j]=='R':
      rw[i]='R'
      rw[j]='W'
      count+=1
  i+=1
  j-=1

j=s-1
while (rw[j]=='W' and j>=0):
      j-=1
i=0 
while (i<j):
   if (rw[i]=='W'):
      count+=1
   i+=1  
print(count)


Failing test case input:
8
WRWRWRRW

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
N=int(input())
rw=list(input())
s=len(rw)
i=0
j=s-1
count=0

while i<j:
  while (j>=0 and rw[j]=='W'):
        j-=1
  while (i<=s-1 and rw[i]=='R'):
        i+=1
  if i>=j:
    break
  if rw[i]=='W' and rw[j]=='R':
      rw[i]='R'
      rw[j]='W'
      count+=1
  i+=1
  j-=1

j=s-1
while (rw[j]=='W' and j>=0):
      j-=1
i=0 
while (i<j):
  if (rw[i]=='W'):
      count+=1
  i+=1

print(count)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
s = input()
w = s.count('w')
print( s[-w:].count('R') if w != 0 else 0)

Failing test case input:
8
RRRWWWRW

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
s = input()
ans = 0
for i in s:
	if i=="R":
		ans+=1

for i in range(0,ans):
	if i=="R":
		ans-=1

print(ans)

Failing test case input:
8
WWRWRRWR

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
s = input()
ans = 0
for i in s:
	if i=="R":
		ans+=1

for i in range(0,ans):
	if s[i]=="R":
		ans-=1

print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
stones = list(input())
if not ('R' in stones and 'W' in stones):
    print('0')
    exit()
right = 0
left = N - 1
white_idx = -1
red_idx = -1
ans = 0
while right < left:
    while right < N and right < left:
        if stones[right] == 'W':
            white_idx = right
            break
        right += 1
    while 0 < left and right < left:
        if stones[left] == 'R':
            red_idx = left
            break
        left -= 1
    if 0 <= white_idx and 0 <= red_idx:
        ans += 1
    right += 1
    left -= 1
print(ans)

Failing test case input:
4
WRXR

Expected output:
1


Actual output:
2


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

stones = list(input())

if not ('R' in stones and 'W' in stones):
    print('0')
    exit()
right = 0
left = N - 1
white_idx = -1
red_idx = -1
ans = 0
while right < left:
    while right < N and right < left:
        if stones[right] == 'W':
            white_idx = right
            break
        right += 1
    while 0 < left and right < left:
        if stones[left] == 'R':
            red_idx = left
            break
        left -= 1
    if left == right:
        break
    if 0 <= white_idx and 0 <= red_idx:
        ans += 1
    right += 1
    left -= 1
print(ans)
Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(input())
c=a.count("W")
b=a[:n-c]
d=b.count("W")
print(d)
print(b)

Failing test case input:
8
WRWSWRWR

Expected output:
2


Actual output:
2
['W', 'R', 'W', 'S']


Fixed submission (verdict: Accepted):
n=int(input())
a=list(input())
c=a.count("W")
b=a[:n-c]
d=b.count("W")
print(d)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
list=[]
list = (str(input()))
cnt = 0

for i in range(N-1):
    if list[i] == 'W':
        for j in range(N-1):
            if list[N-j-1] == 'R' and (N-j-1) > i:
                cnt +=1
                break
ans = cnt
for k in range (cnt-1):
    if list[N-k-1] == 'W':
        ans -= 1
print(ans)







Failing test case input:
8
WRWWWRRR

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R > W:
    for i in range(0,cnt):
        if list[N-i-1]=="R":
            ans +=1

if R<=W:
    for j in range(0,cnt):
        if list[j] == "W":
            ans +=1


print(ans)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while i != j and i < j:
    if d[i] == 'W':
        while d[j] != 'R' and i < j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)


Failing test case input:
8
WWRRWRWR

Expected output:
2


Actual output:
3


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

d = list(c)

i = 0
j = N - 1
result = 0
while True:
    while i < N and d[i] != 'W':
        i += 1
    while j > 0 and d[j] != 'R':
        j -= 1
    if i == N or j == -1 or i >= j:
        break
    d[i] = 'R'
    d[j] = 'W'
    result += 1
print(result)

Problem: p02597
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
k = input()
k2 = k[::-1]
i1 = 0
i2 = 0
cnt = 0
while i1 < n:
  if k[i1] == 'W':
    while i2 < n:
      if k2[i2] == 'R':
        k2 = k2[:i2] + 'W' + k2[i2+1:]
        cnt += 1
        break
      i2 += 1
  i1 += 1
  if i1 + i2 >= n:
    break
print(cnt)

Failing test case input:
8
RWRRUWRW

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
k = input()
k2 = k[::-1]
i1 = 0
i2 = 0
cnt = 0
while i1 < n:
  if k[i1] == 'W':
    while i2 < n:
      if k2[i2] == 'R':
        i2 += 1
        cnt += 1
        break
      i2 += 1
      if i1 + i2 >= n:
        break
  i1 += 1
  if i1 + i2 >= n:
    break
print(cnt)

Problem: p02597
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
c=list(input())
s=c.count("W")
d=c[:n-s+1].count("W")
print(d)

Failing test case input:
8
WRWRXWRR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
c=list(input())
s=c.count("W")
d=c[:n-s].count("W")
print(d)