qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, len(arr) - 1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)

Fixed code:
import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, n-1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)
Buggy code:
import sys
readline = sys.stdin.readline
from collections import deque

def solve():
    N = int(readline())
    C = readline().rstrip()

    R, W = 'R', 'W'
    reds = deque(i for i in range(len(C)) if C[i] == 'R')
    whites = deque(i for i in range(len(C)) if C[i] == 'W')

    count = 0
    print(reds, whites)
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()

Fixed code:
import sys
readline = sys.stdin.readline
from collections import deque

def solve():
    N = int(readline())
    C = readline().rstrip()

    R, W = 'R', 'W'
    reds = deque(i for i in range(len(C)) if C[i] == 'R')
    whites = deque(i for i in range(len(C)) if C[i] == 'W')

    count = 0
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()
Buggy code:
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))

Fixed code:
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))
Buggy code:
from collections import Counter


N = int(input())
C = input()
C_cntr = Counter(C)

ans = 0
for i in range(C_cntr["R"]):
　if C[i] == "W":
        ans += 1

print(ans)


Fixed code:
from collections import Counter


N = int(input())
C = input()
C_cntr = Counter(C)

ans = 0
for i in range(C_cntr["R"]):
    if C[i] == "W":
        ans += 1

print(ans)
Buggy code:
N = int(input())
cs = list(input())

ans = 0
sorted = N - 1
for i in range(N):
  if cs[i] == "W":
    for j in range(sorted, i, -1):
      if cs[j] == "R":
        cs[i], cs[j] = cs[j], cs[i]
        ans += 1
        sorted = j
        break
  if (i + 1) == j:
    break
print(str(ans))

Fixed code:
N = int(input())
cs = list(input())

ans = 0
sorted = N - 1
for i in range(N):
  if cs[i] == "W":
    for j in range(sorted, i, -1):
      sorted = j - 1
      if cs[j] == "R":
        cs[i], cs[j] = cs[j], cs[i]
        ans += 1
        break
  if (i + 1) > sorted:
    break
print(str(ans))
Buggy code:
n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        print(22222222)
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        print(3333333333)
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    print(ans)
    ans=ans+1
print(ans)

Fixed code:
n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    ans=ans+1
print(ans)
Buggy code:
from sys import stdin
n = int(stdin.readline())
c = stdin.readline()[:-1]

red = c.count("R")
ans = red
numwhite = 0
for i in range(n):
    numwhite += 1 if c[i] == "W" else 0
    numred = i - numwhite + 1
    resred = red - numred
    ans = min(ans,min(resred,numwhite))
print(ans)

Fixed code:
from sys import stdin
n = int(stdin.readline())
c = stdin.readline()[:-1]

red = c.count("R")
ans = red
numwhite = 0
for i in range(n):
    numwhite += 1 if c[i] == "W" else 0
    numred = i - numwhite + 1
    resred = red - numred
    if resred == numwhite:
        ans = min(ans,resred)
print(ans)
Buggy code:
N = int(input())
a = input()
wc = int(0)
rc = int(0)
c = int(0)

for i in range(N):
  if a[i] == "W":
    wc += 1
  else:
    rc += 1

if rc == 0:
  print("0")
else:
  for i in range(rc):
    if a[i] == "W":
      c += 1
    print(c)

Fixed code:
N = int(input())
a = input()
wc = int(0)
rc = int(0)
c = int(0)

for i in range(N):
  if a[i] == "W":
    wc += 1
  else:
    rc += 1

if rc == 0:
  print("0")
else:
  for i in range(rc):
    if a[i] == "W":
      c += 1
  print(c)
Buggy code:
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while s[i] != 'W' and i < j:
                i += 1
        while s[j] != 'R' and i < j:
                j -= 1
        s = list(s)
        s[i], s[j] = s[j], s[i]
        s = "".join(s)
        counter += 1
        i += 1
        j -= 1

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)


find_cost(s)

Fixed code:
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            # s = list(s)
            s[i], s[j] = s[j], s[i]
            # s = "".join(s)
            counter += 1
        i += 1
        j -= 1

    # print(counter)

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)

s = list(s)
find_cost(s)
Buggy code:
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
 
 
def main():
    N,S = Input.split()
    print(N)
    N=int(N)
    l=0
    r=len(S)-1
    ans=0
    while(1):
        for i in range(l,len(S)):
            if S[i]=='W':
                l=i
                break
        for j in range(r,0,-1):
            if S[j]=='R':
                r=j
                break
        
        if i<j:
            ans+=1
            l=i+1
            r=j-1
        else:
            break
    print(ans)

 
if __name__ == '__main__':
    main()

Fixed code:
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
 
 
def main():
    N = int(input())
    S = input()
    l=0
    r=len(S)-1
    ans=0
    while(1):
        for i in range(l,len(S)):
            if S[i]=='W':
                l=i
                break
        for j in range(r,-1,-1):
            if S[j]=='R':
                r=j
                break
        if i<j:
            ans+=1
            l=i+1
            r=j-1
        else:
            break
    print(ans)

 
if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
l=list(map(str,input().split()))
c=list("".join(l))
w=c.count('W')
cc=c[-w:]
r=cc.count('R')
print(r)

Fixed code:
n=int(input())
l=list(map(str,input().split()))
c=list("".join(l))
w=c.count('W')
cc=c[-w:]
r=cc.count('W')
print(w-r)
Buggy code:
N = int(input())
l = input()
arr = []
for i in range(N):
    arr.append(l[i])

c = 0
left = 0
right = N-1
while True:
    while True:
        if arr[left] == 'R':
            left += 1
        else:
            break
    while True:
        if arr[right] == 'W':
            right -= 1
        else:
            break
    arr[left] = 'R'
    arr[right] = 'W'
    if left >= right:
        break
    else:
        c += 1

print(c)


Fixed code:
N = int(input())
l = input()
arr = []
for i in range(N):
    arr.append(l[i])

c = 0
left = 0
right = N-1

T = False
for i in arr:
    if i == 'R':
        T = True
if T == False:
    print(c)
else:
    T = False
    for i in arr:
        if i == 'W':
            T = True
    if T == False:
        print(c)
    else:
        while True:
            while True:
                if arr[left] == 'R':
                    left += 1
                else:
                    break
            while True:
                if arr[right] == 'W':
                    right -= 1
                else:
                    break
            arr[left] = 'R'
            arr[right] = 'W'
            if left >= right:
                break
            else:
                c += 1
        print(c)
Buggy code:
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while s[i] != 'W' and i < j:
                i += 1
        while s[j] != 'R' and i < j:
                j -= 1
        s = list(s)
        s[i], s[j] = s[j], s[i]
        s = "".join(s)
        counter += 1
        i += 1
        j -= 1

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1
    print(counter)
    
find_cost(s)

Fixed code:
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            s[i], s[j] = s[j], s[i]
            counter += 1
        i += 1
        j -= 1
    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1
    print(counter)
 
s = list(s)
find_cost(s)
Buggy code:
N = int(input())
c = input()

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer-1 + count)

Fixed code:
import sys
N = int(input())
c = input()

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red


left = 0
right = N-1
for i in range(N+1):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer)
Buggy code:
n = int(input())
c = input()

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

print([w[i]+r[i]-min(w[i],r[i]) for i in range(0,n+1)])

Fixed code:
n = int(input())
c = input()

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

ans = 1e10
for i in range(0,n+1):
  ans = min(ans,w[i]+r[i]-min(w[i],r[i]))
print(ans)
Buggy code:
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(max(Rcount,Wcount))






if __name__ == "__main__":
    main()


Fixed code:
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()
Buggy code:
import datetime
import string
import re
import math

N=int(input())
input = input()
str = []
for i in range(N):
    str.append(input[i])

count = 0
begin = 0
end = len(str) - 1
while True:
    if begin < len(str):
        while str[begin] == 'W':
            begin += 1
            if begin == len(str):
                break

    if end >= 0:
        while str[end] == 'R':
            end -= 1
            if end == -1:
                break

    if begin < end:
        str[begin] = 'R'
        str[end] = 'W'
        begin += 1
        end -= 1
        count += 1
    elif begin == len(str) and end != -1:
        if str[end + 1] == 'R':
            str[end] = 'W'
            end -= 1
            count += 1
        else:
            end -= 1
    elif begin != len(str) and end == -1:
        if str[begin - 1] == 'W':
            str[begin] = 'R'
            begin += 1
            count += 1
        else:
            begin += 1
    else:
        print(count)
        break

Fixed code:
import datetime
import string
import re
import math

N=int(input())
input = input()
str = []
for i in range(N):
    str.append(input[i])
str.reverse()

count = 0
begin = 0
end = len(str) - 1
while True:
    if begin < len(str):
        while str[begin] == 'W':
            begin += 1
            if begin == len(str):
                break

    if end >= 0:
        while str[end] == 'R':
            end -= 1
            if end == -1:
                break

    if begin < end:
        str[begin] = 'R'
        str[end] = 'W'
        begin += 1
        end -= 1
        count += 1
    elif begin >= len(str) and end > -1:
        if end != len(str) - 1:
            if str[end + 1] == 'R':
                str[end] = 'W'
                end -= 1
                count += 1
            else:
                end -= 1
        else:
            end -= 1
    elif begin < len(str) and end <= -1:
        if begin != 0:
            if str[begin - 1] == 'W':
                str[begin] = 'R'
                begin += 1
                count += 1
            else:
                begin += 1
        else:
            begin += 1
    else:
        print(count)
        break
Buggy code:
n = int(input())
saidan = input()

isiall = min(saidan.count('W'), saidan.count('R'))

tesuu = 0
for i in range(len(saidan)//2):
    r_iti = saidan.rfind('R')
    w_iti = saidan.find('W')
    
    if r_iti == -1 or w_iti == -1:
        break
    
    saidan = saidan[w_iti+1 : r_iti]
    tesuu += 1
    
    print(tesuu, saidan)
    
print(min(tesuu, isiall))

Fixed code:
n = int(input())
saidan = input()

isiall = min(saidan.count('W'), saidan.count('R'))

tesuu = 0
for i in range(len(saidan)//2):
    r_iti = saidan.rfind('R')
    w_iti = saidan.find('W')
    
    if r_iti == -1 or w_iti == -1 or r_iti < w_iti:
        break
    
    saidan = saidan[w_iti+1 : r_iti]
    tesuu += 1
    
print(min(tesuu, isiall))
Buggy code:
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:
    print(i)
    if i == 'W':
        wcnt += 1
    else:
        if num - 1 > wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt
            wcnt = 0
        else:
            break
print(ans)


Fixed code:
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:
#    print(i)
    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)
Buggy code:
n = int(input())
s = input()
w = s.count('w')
print( s[-w:].count('R') if w != 0 else 0)

Fixed code:
n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))
Buggy code:
import collections

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)

Fixed code:
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)
Buggy code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=input()
L=[0]*(n+1)
R=[0]*(n+1)
for i in range(n):
  if C[i]=="W":
    L[i+1]=L[i]+1
  else:
    L[i+1]=L[i]
  if C[n-1-i]=="R":
    R[n-i-1]=R[n-i]+1
  else:
    R[n-i-1]=R[n-i]
ans=n
for i in range(n):
  cur=max(L[i],R[i])
  ans=min(ans,cur)
print(ans)



Fixed code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=input()
L=[0]*(n+1)
R=[0]*(n+1)
for i in range(n):
  if C[i]=="W":
    L[i+1]=L[i]+1
  else:
    L[i+1]=L[i]
  if C[n-1-i]=="R":
    R[n-i-1]=R[n-i]+1
  else:
    R[n-i-1]=R[n-i]
ans=n
for i in range(n+1):
  cur=max(L[i],R[i])
  ans=min(ans,cur)
print(ans)
Buggy code:
N = int(input())
c = list(input())
print(c)
red=0
for i in c:
    if i=="R":
        red+=1
count = 0
for i in range(red):
    if c[i]=="W":
        count+=1
print(count)

Fixed code:
N = int(input())
c = list(input())

red=0
for i in c:
    if i=="R":
        red+=1
count = 0
for i in range(red):
    if c[i]=="W":
        count+=1
print(count)
Buggy code:
N=int(input())
c=list(input())
print(c)
i=0
count1=0
count2=0
for i in c:
    if i=="R":
        count1+=1
for j in range(count1):
    if c[j]=="R":
        count2+=1
print(count1-count2)

Fixed code:
N=int(input())
c=list(input())
i=0
count1=0
count2=0
for i in c:
    if i=="R":
        count1+=1
for j in range(count1):
    if c[j]=="R":
        count2+=1
print(count1-count2)
Buggy code:
n = int(input())
s = input()
l = []
for i in range(len(s)):
  if s[i] == "R":
    l.append(i)
if l[0] < len(l):
  ans = 0
  for i in l:
    if i >len(l):
      ans += 1
  print(ans)
	
else:
  print(len(l))

Fixed code:
n = int(input())
s = input()
l = []
for i in range(len(s)):
  if s[i] == "R":
    l.append(i)
if l ==[]:
  print(0)
elif l[0] < len(l):
  ans = 0
  for i in l:
    if i >len(l)-1:
      ans += 1
  print(ans)
else:
  print(len(l))
Buggy code:
n = int(input())
s = input()
res = 2000000 
#aw=s.count('W')
ar=s.count('R')
pw=0
pr=0
for i in range(n-1):
	if (s[i] == 'R'):
		pr=pr+1
	else:
		pw=pw+1
	if (max(pw,ar-pr) < res):
		res = max(pw,ar-pr)

print(str(res))

Fixed code:
n = int(input())
s = input()
res = 2000000 
aw=s.count('W')
ar=s.count('R')
if (aw == 0 or ar == 0):
	res=0
pw=0
pr=0
for i in range(n-1):
	if (s[i] == 'R'):
		pr=pr+1
	else:
		pw=pw+1
	if (max(pw,ar-pr) < res):
		res = max(pw,ar-pr)

print(str(res))
Buggy code:
N=int(input())
c=input()
W=[]
R=[]
pw=0
pr=0
for i in range(N):
  if c[i]=="W":
    W+=[i]
    pw+=1

  if c[N-1-i]=="R":
    R+=[i]
    pr+=1

for i in range(200000):
    if min(len(W),len(R))==0:
        result=0
        break
    if W[i]+R[i]>=N:
        result=i
        break
print(result)
result=i


Fixed code:
N=int(input())
c=input()
W=[]
R=[]
pw=0
pr=0
for i in range(N):
  if c[i]=="W":
    W+=[i]
    pw+=1

  if c[N-1-i]=="R":
    R+=[i]
    pr+=1

for i in range(200000):
    if min(len(W),len(R))==i:
        result=i
        break
    if W[i]+R[i]>=N:
        result=i
        break
print(result)
result=i
Buggy code:
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1
    print(r, w)

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
c = list(map(str, input().split()))

a=0
b=0

a = 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)


Fixed code:
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)
Buggy code:
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))))


Fixed code:
"""
4
WWRR
2
"""
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))))
Buggy code:
input()
l =list(input())
cw = l.count('W')
cr = l.count('R')

if cr < cw:
  ans = l[:cr].count('W')
else:
  ans = l[cw:].count('R')
print(ans)

Fixed code:
input()
l =list(input())
cw = l.count('W')
cr = l.count('R')

if cr < cw:
  ans = l[:cr].count('W')
else:
  ans = l[cr:].count('R')
print(ans)
Buggy code:
N = int(input())
c = input()
W = c.count('W')
print(c[:R].count('W'))

Fixed code:
N = int(input())
c = input()
W = c.count('W')
R = c.count('R')
print(c[:R].count('W'))
Buggy code:
n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(cnt)


Fixed code:
n  = int(input())
c = list(input())


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(rcnt - cnt)