Problem:
 Score : 400 points    Problem Statement An altar enshrines N stones arranged in a row from left to right. The color of the i -th stone from the left (1 \leq i \leq N) is given to you as a character c_i ; R stands for red and W stands for white.  You can do the following two kinds of operations any number of times in any order:   Choose two stones (not necessarily adjacent) and swap them.  Choose one stone and change its color (from red to white and vice versa).   According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?      Constraints  2 \leq N \leq 200000  c_i is R or W .         Input Input is given from Standard Input in the following format:  N  c_{1}c_{2}...c_{N}       Output Print an integer representing the minimum number of operations needed.        Sample Input 1 4
WWRR      Sample Output 1 2  For example, the two operations below will achieve the objective.   Swap the 1 -st and 3 -rd stones from the left, resulting in RWWR .  Change the color of the 4 -th stone from the left, resulting in RWWW .        Sample Input 2 2
RR      Sample Output 2 0  It can be the case that no operation is needed.       Sample Input 3 8
WRWWRWRR      Sample Output 3 3

Solution (Python):
n = int(input())
rh_list = list(input())

r_n = rh_list.count('R')

R_list=[]
for i in range(r_n):
  R_list.append(rh_list[i])

R_r_n = R_list.count('R')
print(r_n-R_r_n)

Solution (Python):
N = int(input())
C = input()
w = sum([True for c in C if c == "W"])
r = N - w

count = 0
for i, c in enumerate(C):
  if i < r and c == 'W':
    count += 1
print(count)

Solution (Python):
import sys

n = int(input())

c = input()

count = 0
check = 0
wList = []
rList = []

for i in range(n):
    if c[i] == "W":
        wList.append(i)
    else:
        rList.append(i)

if len(wList) == 0 or len(rList) == 0:
    print(0)
    sys.exit()

rMax = rList[-1]
wMin = wList[0]

for i in range(len(rList)):
    if rList[-1] < wList[0]:
        break
    else:
        count += 1
        del rList[-1]
        del wList[0]

print(count)

Solution (Python):

import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline



n = int(input())
s = input()
i = 0
j = n-1
ans2 = 0
while i < j:
	while s[i] == "R":
		i+=1
	while s[j] == "W":
		j-=1
	if i < j: 
		ans2+=1
		i+=1
		j-=1
print(ans2)

Solution (Python):

n = int(input())
c = list(input())
c = c[::-1]
w = c.count("W")
r = c.count("R")
ans = 0
for i in c:
    if w == 0 or r == 0:
        print(ans)
        break
    if i == "R":
        w -= 1
        r -= 1
        ans += 1
    else:
        w -= 1

Solution (Python):
n = int(input())
stones = list(input())

a = 0
rlist = []
wlist = []
for i in range(n):
  if stones[i] == "W":
    wlist.append(i+1)
  elif stones[i] == "R":
    rlist.append(i+1)
rlist.sort(reverse=True)
r_numbers =  len(rlist)
w_numbers =  len(wlist)

if r_numbers == 0 or w_numbers == 0:
  print(0)
elif r_numbers>=w_numbers:
  count = 0
  while rlist[count] > wlist[count] and count < w_numbers-1:
    count += 1
  if rlist[count] > wlist[count]:
    print(count+1)
  else:
    print(count)
elif r_numbers<=w_numbers:
  count = 0
  while rlist[count] > wlist[count] and count < r_numbers-1:
    count += 1
  if rlist[count] > wlist[count]:
    print(count+1)
  else:
    print(count)

Solution (Python):
n = int(input())
c = input()

cnt = 0
r = c.count('R')

r_s = c[:r].count('R')

print(r - r_s)

Solution (Python):
mod = 1000000007
eps = 10**-9


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

    N = int(input())
    S = input().rstrip('\n')
    S = [s for s in S]

    l = 0
    r = N-1
    ans = 0
    while True:
        if l >= r:
            break
        if S[l] == "W" and S[r] == "R":
            S[l], S[r] = S[r], S[l]
            ans += 1
            l += 1
            r -= 1
        elif S[l] == "W" and S[r] == "W":
            r -= 1
        elif S[l] == "R" and S[r] == "R":
            l += 1
        else:
            l += 1
            r -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

    lw, rr = -1, -1
    for i, c in enumerate(C):
        if lw == -1 and c == "W":
            lw = i
        elif c == "R":
            rr = i
    if lw == -1 or rr == -1:
        print(0)
        return
    ans = 0
    while rr > lw:
        C[lw] = "R"
        C[rr] = "W"
        ans += 1
        while lw < N:
            lw += 1
            if C[lw] == "W":
                break
        while rr >= 0:
            rr -= 1
            if C[rr] == "R":
                break
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
C = input()
Best = ('R'*C.count('R'))+('W'*C.count('W'))
Count = 0
for T in range(0,N):
    if Best[T]!=C[T]:
        Count += 0.5
print(int(Count))

Solution (Python):
N = int(input())
c = str(input())
ans = 0
left = 0
right = N-1
while(left < right):
    if c[right] == 'W':
        
        right -= 1
    elif c[right] == 'R':
        if left < right and c[left] == 'R':
            
            left += 1
        elif left < right and c[left] == 'W':
            
            ans += 1
            
            left += 1
            
            right -= 1

print(ans)

Solution (Python):
n = int(input())
c = input()

w = []
r = []
for i in range(n):
  if c[i] == 'W':
    w.append(i+1)
  else:
    r.append(i+1)

w_len = len(w)
r_len = len(r)
if w_len == 0 or r_len == 0:
  print(0)
  exit(0)

if w_len < r_len:
  search = w_len
else:
  search = r_len

w_min = w[0]
r_max = r[r_len-1]

if r_max < w_min:
  print(0)
  exit(0)

count = 0
for i in range(search):
  tmp = w[i]
  w[i] = r[r_len-i-1]
  r[r_len-i-1] = tmp
  count += 1
  
  if w_len > count and (r_len-count-1) >= 0:
    w_min = w[count]
    r_max = r[r_len - count - 1]
  else:
    w_min = w[w_len-1]
    r_max = r[0]
    
  if r_max < w_min:
    print(count)
    exit(0)
print(count)

Solution (Python):
N = int(input())
S = list(input().strip())

l = 0
r = N-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
        l += 1
        r -= 1
    while l < N and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

Solution (Python):
def main():
    n = int(input())
    rw = input()
    r_num = 0
    for i in rw:
        if i == 'R':
            r_num += 1
    w_num = n - r_num
    ans = 0
    for i in range(r_num):
        if rw[i] == 'W':
            ans += 1
    print(ans)
    return
if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=input()
a=S.count("W")
b=S.count("R")
print(min([S[:b].count("W"),a,b]))

Solution (Python):
n = int(input())
c = list(input())
wpos = 0
rpos = n-1
count = 0
while wpos < rpos :
  while c[wpos] == "R":
    wpos += 1
    if wpos > rpos: break
  while c[rpos] == "W":
    rpos -= 1
    if wpos > rpos: break
  if wpos < rpos :
    count += 1
    c[wpos],c[rpos]=c[rpos],c[wpos]
print(count)

Solution (Python):
import collections as col

N = int(input())
C = input()
mp = col.Counter(C)
ideal = ''
ideal += ('R' * mp['R'])
ideal += ('W' * mp['W'])

ans = 0
for i, c in zip(ideal,C):
    if i!=c:
        ans += 1
print(ans//2)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()

w = s.count('W')
r = s.count('R')
if r == 0 or w == 0:
    print(0)
    exit()
i_r = s.index('R')
r2 = s[:r:].count('R')
print(r-r2)

Solution (Python):
N = int(input())
S = input()
Rcnt = S.count('R')
Wcnt = N-Rcnt

if Wcnt < Rcnt:
    cnt = S[-Wcnt:].count('W')
    print(Wcnt - cnt)
else:
    cnt = S[:Rcnt].count('R')
    print(Rcnt-cnt)

Solution (Python):
n = int(input())
c = input()
c_list = list(c)

count = 0
R_count = c_list.count("R")
for i in range(R_count):
    if c[i] == "W":
        count += 1
print(count)

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
c = list(str(input()))

cs = [0 for i in range(N)]
for i,color in enumerate(c):
    if color == "R":
        cs[i] = 1

ans = min(sum(cs), N - sum(cs))
tmp = sum(cs)


count = 0
for i in range(tmp):
    if cs[i]:
        count += 1

ans = min(ans, tmp - count)
print(ans)




"""
out 
WR



ok
RRRRRWWWWW 入れ替える
RRRRRR 全てRにする
WWWWWW 全てWにする


1100

1110111000

tmp = 6


"""

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    stones = input()

    w = []
    r = []

    for i in range(N):
        if stones[i] == 'W':
            w.append(i)
        else:
            r.append(i)

    if len(w) != 0 and len(r) != 0:
        res = 0
        for i, val in enumerate(w):
            if val <= r[-1*(i+1)]:
                res += 1
            else:
                break
        print(res)
    else:
        print(0)

if __name__ == "__main__":
    resolve()

Solution (Python):


n = int(input())
rw = input()

w = 0

c = [0] * n

for i in range(n):
    if rw[i] == 'W':
        c[i] = 1
        w += 1

r = n - w

left_w = 0
for x in c[0:r]:
    if x == 1:
        left_w += 1

print(left_w)

Solution (Python):
from collections import Counter

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

C = Counter(S)
ans = 0
for i in range(C['R']):
    if S[i] == 'W':
        ans += 1
print(ans)

Solution (Python):
N = int(input())
C = list(input())

ans = C.count("R")
ans = min(ans, N - ans)

from heapq import *

idxW = []
idxR = []
for i,c in enumerate(C):
    if c == "R":
        heappush(idxR, -i)
    else:
        heappush(idxW, i)

LEN = min(len(idxW), len(idxR))

cnt = 0
for i in range(LEN):
    iW = heappop(idxW)
    iR = heappop(idxR) * (-1)

    if iW < iR:
        cnt += 1

ans = min(ans, cnt)

print(ans)

Solution (Python):
n = int(input())
c = input()
num = c.count("R")
c2 = c[:num]
num2 = c2.count("R")
print(num - num2)

Solution (Python):
n = int(input())
s = input()
ans = 0

while True:
    if not ('R' in s and 'W' in s): break
    r = s.rindex('R')
    w = s.index('W')
    if r < w:
        break
    s = s[:w] + 'R' + s[w+1:r] + 'W' + s[r+1:]
    ans += 1
print(ans)

Solution (Python):
n = int(input())
c = input()

r = []
w = []

for i in range(n):
    if c[i] == 'R':
        r.append(i)
    else:
        w.append(i)

r.sort(reverse=True)

if len(r) == 0 or len(w) == 0:
    print(0)
else:
    ans = 0
    while ans < len(r) and ans < len(w) and r[ans] > w[ans]:
        ans += 1
    print(ans)

Solution (Python):

def main():
    t = int(input())
    arr = list(input())

    count = 0
    left = 0
    right = t-1

    

    while left < right:
        if arr[right] == 'R' and arr[left] == 'W':
            
            left += 1
            right -= 1
            count += 1

        elif arr[left] == 'R' and arr[right] =='R' :
            left += 1

        elif arr[left] == 'W' and arr[right] =='W':
            
            right -= 1
            

        else:
            left += 1
            right -= 1




    print(count)




main()

Solution (Python):
import heapq

N = int(input())
stones = input()

red = []
white = []
heapq.heapify(red)
heapq.heapify(white)

for i in range(N):
    if stones[i] == 'R':
        heapq.heappush(red, -i)
    else:
        heapq.heappush(white, i)

a = len(red)
b = N - a

if a == 0 or b == 0:
    print(0)
else:
    count = 0
    while True:
        biggest_red = -(heapq.heappop(red))
        smallest_white = heapq.heappop(white)
        if biggest_red > smallest_white:
            count += 1
            heapq.heappush(red, smallest_white * -1)
            heapq.heappush(white, biggest_red)
        else:
            break
    print(min(a, b, count))

Solution (Python):

N = int(input())
C = input()
w = C.count("W")
print(w - C[N-w::].count("W"))

Solution (Python):
n = int(input())
s = input()
w = []
r = []
for i in range(len(s)):
    if s[i] == "W": w.append(i+1)
    if s[len(s)-i-1] == "R": r.append(len(s)-i)
cnt = 0

for i in range(min(len(w), len(r))):
    if w[i] >  r[i]:
        break
    else:
        cnt += 1
print(cnt)

"""
i = 0
while True:
    wi = s.index("W")
    ri = str(s).rindex("R")
    if wi < ri:
        s[wi], s[ri] = s[ri], s[wi]
        i += 1
    else: break
print(cnt)
"""

Solution (Python):
n=int(input())
c=list(input())
ideal=["R"]*c.count("R")+["W"]*c.count("W")

cnt=0
for i in range(n):
    if c[i]!=ideal[i]:
        cnt+=1

print(min([c.count("R"), c.count("W"), (cnt+1)//2]))

Solution (Python):
import numpy as np

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R' and j>n-1:
        j-=1
    if i>=n or j<n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)

Solution (Python):
n=int(input())
c=input()

from collections import Counter
cl = list(c)
cun= Counter(cl)
cn=cun["R"]
cnt=0
for i in  range(cn):
    if c[i]=="W" :
        rpos=c.rfind("R",cn)
        cl[i],cl[rpos]=cl[rpos],cl[i]
        cnt+=1

print(cnt)

Solution (Python):
"""
RRR...RWWW...Wの並びに並び変えるのがゴール
"""

N = int(input())
c = input()

nw = 0
nr = 0

for i in c:
    if i == 'W':
        nw += 1
    elif i == 'R':
        nr += 1

lw = 0
rr = 0

for i in range(0, nr):
    if c[i] == 'W':
        lw += 1

for i in range(nr, len(c)):
    if c[i] == 'R':
        rr += 1

print(max(lw, rr))

Solution (Python):

import os
import sys
from io import BytesIO, IOBase


def main():
    n = int(input())
    s = list(input())
    w_cnt = s.count('W')
    r_cnt = n - w_cnt
    ideal = list('R' * r_cnt + 'W' * w_cnt)
    exchange = 0
    replace = 0
    flag = 0
    for i in range(n-1, -1, -1):
        if s[i] == 'R' and not flag:
            flag = 1
        if flag and s[i] == 'W':
            replace += 1
        if s[i] != ideal[i] and s[i] == 'W':
            exchange += 1
    print(min(replace, exchange))





BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
C=input()
NR=0
NW=0
ans=0
for i in range(N):
  if C[i]=="W":
    NW+=1
  else:
    NR+=1
if NW==N or NR==N:
  print(0)
else:
  for i in range(NR):
    if C[i]=="W":
      ans+=1
  print(ans)

Solution (Python):

N = int(input())
line = list(input())
rw = {"R": [], "W": []}
ans = N


def replace(c):
    left = -1
    right = len(rw["R"])
    while right - left > 1:
        idx = (right + left) // 2
        if rw["R"][idx] > c:
            right = idx
        else:
            left = idx
    req = len(rw["R"]) - right
    return req


for cnt, i in enumerate(line):
    if i == "R":
        if len(rw["R"]) == 0:
            rw["R"] = [cnt]
        else:
            rw["R"].append(cnt)
    else:
        if len(rw["W"]) == 0:
            rw["W"] = [cnt]
        else:
            rw["W"].append(cnt)
ans = min(len(rw["R"]), len(rw["W"]))
ans = min(ans, replace(len(rw["R"])-1))
print(ans)

Solution (Python):
N = int(input())
c = list(input())


ans = 0
left_W = 0
right_R =c.count("R")

if c.count("R")==0 or c.count("W") == 0:
    ans = 0
for n in range (N):
    if c[n] == "R":
        right_R -= 1
    else:
        left_W += 1


    if left_W == right_R:
        ans = right_R
        break
print(ans)

Solution (Python):
N = int(input())
c = list(input())

if N <= 1:
    print(0)
else:
    ans = 0
    r = N
    for w in range(N):
        if c[w] == 'R':
            continue
        else:
            while True:
                r += -1
                if r == -1 or c[r] == 'R':
                    break
            if r < w:
                break
            else:
                ans += 1
    print(ans)

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])
    RED = [a == 'R' for a in args[1]]
    l, r = 0, n-1
    ret = 0
    while l < r:
        if RED[l]:  
            l += 1
        elif RED[r]:  
            l += 1
            r -= 1
            ret += 1
        elif not RED[r]:  
            r -= 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
n = int(input())
stones = input()

redflag = False
whiteflag = False









start = 0
end = n - 1
count = 0
while(True):
  while(start < n and stones[start]!="W"):
    start += 1
  while(end >= 0 and stones[end]!="R"):
    end -= 1
  if(start >= end):
    break
  start += 1
  end -= 1
  count += 1

print(count)

Solution (Python):
N=int(input())
RW=input()

RightW=0
tesu=0

LeftW=0
LeftR=0

numW=0
numR=0

for i in RW:
  if i=="R":
    numR+=1
  else:
    numW+=1

for i in range(numR):
  if RW[i]=="W":
    LeftW+=1
  else:
    LeftR+=1

print(LeftW)

Solution (Python):
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)

Solution (Python):
N = int(input())
c = input()

R = c.count("R")

cnt = 0
for i in range(R):
    if c[i] != "R":
        cnt += 1

print(cnt)

Solution (Python):
import math
N=int(input())
S=list(input())
ans=0
Rc=S.count('R')
Wc=N-Rc
Wco=S[:Rc].count('W')
Rco=Rc-Wco
Wcu=Wc-Wco
Rcu=Rc-Rco







print(min(Rc,Wc,max(Wco,Rcu)))

Solution (Python):
from collections import Counter
n=int(input())
c=input()
co=Counter(c)
wcnt=co["W"]
rcnt=co["R"]
if wcnt==0 or rcnt==0:
    print(0)
    quit()
ans=0
for i in range(n):
    if c[i]=="W" and i<rcnt:
        ans+=1

print(min(ans,rcnt))

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
C = read().rstrip().decode()

l, r = 0, N - 1
cost = 0
while l < r:
    
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        
        cost += 1
        l += 1
        r -= 1

print(cost)

Solution (Python):
n = int(input())
s = input()

array = list(s)
r = len(s.replace('W', ''))
w = n - r
ans = min(r,w)

i = 0
j = len(array)-1
count = 0
for i in range(r):
  if array[i] == 'W':
    count += 1
  
print(min(count, ans))

Solution (Python):
n = int(input())
s = input()

m = s.count("R")
ans = s[:m].count("W")

print(ans)

Solution (Python):
N = int(input())
C = input()

print(C.count("R") - C.count("R", 0, C.count("R")))

Solution (Python):
n = int(input())
c = input()

r = c.count("R")

if r == 0 or r == len(c):
    print("0")
    exit()

print(c[:r].count("W"))

Solution (Python):
n = int(input())

s = list(input())

w = s.count("R")

x = s[:w].count("R")


print(w-x)

Solution (Python):
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)

Solution (Python):
N=int(input())
c=input()
dataR=[int(c[i]=="R") for i in range(N)]
dataW=[int(c[i]=="W") for i in range(N)]

for i in range(N-2,-1,-1):
    dataR[i]+=dataR[i+1]
for i in range(1,N):
    dataW[i]+=dataW[i-1]

ans=min(dataR[0],dataW[N-1])
for i in range(1,N):
    test=max(dataR[i],dataW[i-1])
    ans=min(ans,test)

print(ans)

Solution (Python):
n = int(input())
s = str(input())
cnt1 = s.count("W") 
cnt2 = len(s) - cnt1 
ss = s[:cnt2]
cnt3 = ss.count("W")
print(min(cnt1, cnt3))

Solution (Python):
N = int(input())
C = list(input())

r = C.count("R")
print(r-C[:r].count("R"))

Solution (Python):
n = int(input())
s = input()
n_r = s.count('R')
n_r_l = s[:n_r].count('R')
print(n_r-n_r_l)

Solution (Python):
from collections import Counter
N = int(input())
c = input()
counter = Counter(c)

if counter["R"] == 0 or counter["W"] == 0:
    print(0)
else:
    r_cnt = 0
    for i in range(counter["R"]):
        if c[i] == "R":
            r_cnt += 1
    print(counter["R"]-r_cnt)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')

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

print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
c=s.count("R")
w=[0]*n
if c==0 or c==n:
    print(0)
    exit()
if s[0]=="W":
    w[0]=1
for i in range(1,n):
    w[i]=w[i-1]
    if s[i]=="W":
        w[i]+=1
print(w[c-1])

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

goal = sorted(S)

ans = 0
for i in range(N):
    if S[i] != goal[i]:
        ans += 1
print(ans // 2)

Solution (Python):
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)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    C = list(input())

    R = []
    W = []
    for i,c in enumerate(C):
        if c == "R":
            R.append(i)
        else:
            W.append(i)
    

    W.sort(reverse=True)
    R.sort()

    if len(R) == 0 or len(W) == 0:
        print(0)
        exit()

    ri = R.pop()
    wi = W.pop()

    ans = 0
    while not ri < wi:
        ans += 1
        if len(R) == 0 or len(W) == 0: break

        ri = R.pop()
        wi = W.pop()    


    print(ans)






if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    s = input()

    wcount = s.count("W")
    rcount = s.count("R")

    ans = 0

    for i in range(rcount):
        if s[i] == "W":
            ans+=1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys, re
def i_input(): return int(input())
def s_input(): return input()
sys.setrecursionlimit(10 ** 6)

def main():
    n = i_input()
    s = list(s_input())

    r_count = s.count('R')
    w_count = n - r_count

    if r_count == n or w_count == n:
        print(0)
        exit()

    r_s = s[::-1]

    count = 0

    index = 0
    for i in range(len(s)):
        if r_s[i] == 'W':
            continue
        for j in range(index, n - i - 1):
            if s[j] == 'R':
                index = j + 1
                continue
            index = j + 1
            count += 1
            break

    print(min(count, min(r_count, w_count)))

if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    c = list(SS())

    
    
    
    
    
    cnt_r = c.count('R')
    ans = max(c[:cnt_r].count('W'), c[cnt_r:].count('R'))
    
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
s = list(input())
num_R = 0
for i in range(n):
    if s[i]=='R':
        num_R+=1
s_sort = ['R' if i<num_R else 'W' for i in range(n)]
ans = 0
for i in range(n):
    if s[i]=='W' and s_sort[i]=='R':
        ans += 1
    
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

class Result:
    def __init__(self, index, value):
        self.index = index
        self.value = value

class BinarySearch:
    def __init__(self):
        pass

    @staticmethod
    def greater_than(num: int, func, size: int = 1):
        """Searches for smallest element greater than num!"""
        if isinstance(func, list):
            index = bisect_right(func, num)
            if index == len(func):
                return Result(None, None)
            else:
                return Result(index, func[index])
        else:
            alpha, omega = 0, size - 1
            if func(omega) <= num:
                return Result(None, None)
            while alpha < omega:
                if func(alpha) > num:
                    return Result(alpha, func(alpha))
                if omega == alpha + 1:
                    return Result(omega, func(omega))
                mid = (alpha + omega) // 2
                if func(mid) > num:
                    omega = mid
                else:
                    alpha = mid

    @staticmethod
    def less_than(num: int, func, size: int = 1):
        """Searches for largest element less than num!"""
        if isinstance(func, list):
            index = bisect_left(func, num) - 1
            if index == -1:
                return Result(None, None)
            else:
                return Result(index, func[index])
        else:
            alpha, omega = 0, size - 1
            if func(alpha) >= num:
                return Result(None, None)
            while alpha < omega:
                if func(omega) < num:
                    return Result(omega, func(omega))
                if omega == alpha + 1:
                    return Result(alpha, func(alpha))
                mid = (alpha + omega) // 2
                if func(mid) < num:
                    alpha = mid
                else:
                    omega = mid


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    n = int(input())
    s = input()
    r = []
    w = []
    for i in range(n):
        if s[i] == 'R':
            r += [i]
        else:
            w += [i]
    bs = BinarySearch()
    ans = 0
    for i in range(n):
        if s[i] == 'W':
            if bs.greater_than(i, r).value is not None:
                r.pop()
                ans += 1
    print(ans)

Solution (Python):
n=int(input())
c=input()
r=c.count("R")
w=n-r
ans=0
for i,j in zip(c,"R"*r+"W"*w):
    if i!=j:
        ans+=1
print(ans//2)

Solution (Python):
n=int(input())
a=input()

lista=list(a)
w=lista.count("W")
r=lista.count("R")
count=0
for i in range(r):
  if lista[i]=="W":
    count+=1
print(count)

Solution (Python):
n = int(input())
c = input()
r_cnt = c.count('R')
w_cnt = c.count('W')
new_c = 'R' * r_cnt + 'W' * w_cnt
cnt = 0
for i in range(n):
    if c[i] != new_c[i]:
        cnt += 1
    else:
        pass
if cnt >= 2:
    ans = cnt //2
elif cnt == 1:
    ans = 1
elif cnt == 0:
    ans = 0
print(ans)

Solution (Python):
a=int(input())
b=input()
r_num=0
w_num=0
for i in b :

  if i=='W' :
    w_num+=1
  else :
    r_num+=1

count=0

for i in range(r_num) :
  if b[i]=='W' :
    count+=1


print(count)