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):
import sys

n=int(input())
c=input()
r=c.count("R")
w=c.count("W")
mi=min(r,w)
l_w=0
l_r=0
ans=float('inf')
if w==n:
  print(0)
  sys.exit()


for i in range(n):
  if c[i]=="W":
    l_w+=1
  else:
    l_r+=1

  r_r=r-l_r
  if l_w<=r_r:
    now=l_w+(r_r-l_w)
  else:
    now=r_r+(l_w-r_r)

  ans=min(ans,now)
print(ans)

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

c=list(input())



sta=1
ans=0
for i in range(N):
    if(-sta+N<i):
        break
    if(c[i]=='W'):
        for j in range(sta,N):
            if(-j+N<=i):
                print(ans)
                exit()
                break
            if(c[-j]=='R'):
                temp=c[-j]
                c[-j]=c[i]
                c[i]=temp
                sta=j
                ans=ans+1
                break


print(ans)

Solution (Python):

n=int(input())
c=input()
r=c.count('R')
x=c[:r]
print(x.count('W'))

Solution (Python):
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] != 'W': l += 1
    elif C[r] != 'R': r -= 1
    else: l += 1; r -= 1; c += 1
print(c)

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

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

Solution (Python):
N = int(input())
S = input()
RL, WL = [0 for _ in range(N+1)], [0 for _ in range(N+1)]

for i in range(N):
  RL[i+1] = RL[i] + (S[i] == 'R')
  WL[i+1] = WL[i] + (S[i] == 'W')
mcnt = int(1e13) + 13
for i in range(N, 0, -1):
  if S[i-1] == 'R':
    mcnt = min(mcnt, RL[N] - RL[i] + max(0, WL[i-1] - RL[N] + RL[i]))
if RL[N] == 0:
  mcnt = 0
print(mcnt)

Solution (Python):
n = int(input())
c = input()
w = 0
r = c.count('R')
ans = r
for i in c:
    if i == 'W': w += 1
    else: r -= 1
    ans = min(ans, max(w, r))
print(ans)

Solution (Python):
N=int(input())
s=input()
r=s.count('R')
cnt=0
for i in range(r):
  if s[i]=='W':
    cnt+=1
print(cnt)

Solution (Python):
N = int(input())
C = input()
 
R_cnt = C.count('R')
x = C[:R_cnt].count('R')
 
print(R_cnt-x)

Solution (Python):
n = int(input())
C = list(input())
r = C.count('R')
c = 0
for i in range(r, n):
    if C[i] == 'R': c += 1
print(c)

Solution (Python):
_ = int(input())
C = input()
print(C[C.count('R'):].count('R'))

Solution (Python):
n = int(input())
C = list(input())
r = C.count('R')
c = 0
for i in range(r, n):
    if C[i] == 'R': c += 1
print(c)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
from numba import njit
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

N = I()
c = _S()

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





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

Solution (Python):
N = int(input())
c = input()
r_cnt = c.count("R")
print(c[:r_cnt].count("W"))

Solution (Python):
n = int(input())
s = str(input())
cnt = 0
a = [c for c in s]
for i in range(n):
    if a[i]=='R':
        cnt += 1
cnt_r = 0
for i in range(cnt):
    if a[i]=='R':
        cnt_r += 1
print(cnt - cnt_r)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    C = list(input().strip("\n"))

    count = 0
    rightBound = N - 1
    for i in range(N):
        if C[i] == "W":
            while rightBound > i:
                if C[rightBound] == "R":
                    C[i] = "R"
                    C[rightBound] = "W"
                    count += 1
                    break
                else:
                    rightBound -= 1
            else: break
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):



n = input()
s = input()
print(s[:s.count('R')].count('W'))

Solution (Python):
n = int(input())
s = str(input())
cnt = 0
for i in range(n):
    if s[i]=='R':
        cnt += 1

cnt_r = 0
for i in range(cnt):
    if s[i]=='R':
        cnt_r += 1

print(cnt - cnt_r)

Solution (Python):



n = int(input())
s = input()
r = s.count('R')
print(s[:r].count('W'))

Solution (Python):









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)

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

ans=0
i,j=0,N-1
while i<j:
    if s[i]=='R':
        i+=1
    elif s[j]=='W':
        j-=1
    else:
        ans+=1
        i+=1
        j-=1

print(ans)

Solution (Python):
import sys

N=int(input())
s=list(input().strip())



k=0
i,j=0,N-1
while i<j:
    if s[i]=='R':
        i+=1
    elif s[j]=='W':
        j-=1
    else:
        s[i]='W'
        s[j]='R'
        k+=1
        i+=1
        j-=1

print(k)

Solution (Python):
n = int(input())
C = input()
cnt_w = 0
cnt_r = C.count('R')
ans = max(cnt_w, cnt_r)
for c in C:
    if c == 'W':
        cnt_w += 1
        temp = max(cnt_w, cnt_r)
        ans = min(ans, temp)
    if c == 'R':
        cnt_r -= 1
        temp = max(cnt_w, cnt_r)
        ans = min(ans, temp)

print(ans)

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

R,W = C.count("R"), C.count("W")

ans = 10**9
l,r = 0,R
for i in range(N+2):
  if 0 < i < N+1: 
    if C[i-1] == "R":
      r -= 1
    else:
      l += 1

  ans = min(ans, max(l,r))

print(ans)

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

R, L = 0, s.count("R")
times = max(R, L)
for c in s:
    if c == "W":
        R += 1
    else:
        L -= 1
    if times > max(R, L):
        times = max(R, L)
print(times)

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

a, b = 0, 0
a = C.count('R')
ans = a

for i in range(N):
	if C[i] == 'R': a -= 1
	else: b += 1
	now = max(a, b)
	ans = min(ans, now)

print(ans)

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_cnt = S.count('W')
R_cnt = S.count('R')
ans = 0
for i in range(R_cnt):
    if S[i] == 'W':
        ans += 1
print(ans)

Solution (Python):

import sys
def main(N, C):
    C = list(C)
    ans = 0
    l = 0
    r = N - 1
    while l < r:
        while l < N and C[l] == 'R': l += 1
        while r >= 0 and C[r] == 'W': r -= 1
        if l < r:
            C[l], C[r] = C[r], C[l]
            ans += 1
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    C = input().rstrip()
    main(N, C)

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

rc = s.count('R')

ans = 0
for stone in s:
    if stone == 'R':
        rc -= 1
    else:
        if rc > 0:
            rc -= 1
            ans += 1

print(ans)

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

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

if N == 2 and c == "WR":
    print(1)
    sys.exit()

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)

Solution (Python):
n=int(input())
s=str(input())
c=s.count('R')
print(s[c:].count('R'))

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

Solution (Python):
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math


rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	n = int(rl())
	s = rll()[0]
	ans = 0
	A = [c for c in s]
	W = deque()
	for i, c in enumerate(A):
		if c == "W":
			W.append(i)
	for i in range(len(A)-1, -1, -1):
		if A[i] == "R" and W and W[0] < i:
			W.append(W.popleft())
			ans += 1
	print(ans)

	stdout.close()

if __name__ == "__main__":
	main()

Solution (Python):
n = int(input())
c = input()
print(c[:c.count("R")].count("W"))

Solution (Python):
n = int(input())
c = list(input())
a = c.count("R")
b = 0
count = max(a, b)

for i in range(n):
  if c[i] == "R":
    a = a - 1
  else:
    b = b + 1
  ans = max(a, b)
  count = min(ans, count)
print(count)

Solution (Python):
_,s=open(0)
print(s[:s.count('R')].count('W'))

Solution (Python):
n,s,*w=open(0)
r=[-1]
n=int(n)
a=i=0
while i<n:
  if'W'>s[i]:r+=i,
  else:w+=i,
  i+=1
for w in w:
  if r.pop()>w:a+=1
  else:break
print(a)

Solution (Python):
import sys
N = int(input())
c = [str(x) for x in list(input())]
R = sum([1 for i, x in enumerate(c) if(x=='R')])
W = 0
if(R==N)or(R==0):
  print(0)
  sys.exit()
ans = R
i = 0
while True:
  if(i==N):
    print(ans)
    sys.exit()
  if(c[i] == 'W'):
    W += 1
  else:
    R -= 1
  n_ans = max(W,R)
  if(n_ans>ans):
    print(ans)
    sys.exit()
  ans = n_ans
  i += 1

Solution (Python):
n = input()
m = input()
maxr = m.count("R")
maxw = m.count("W")

min_move = len(m)
max_r = m.count("R")
max_w = m.count("W")
right = 0
left = 0
for i in range(len(m)):
    if m[i] == "W":
        left += 1
    else:
        max_r -= 1
    if max(left,max_r) < min_move:
        min_move = max(left,max_r)
if maxw == 0 or maxr == 0:
    print(0)
else:
    print(min_move)

Solution (Python):
N=int(input())
c=list(input())
c1=c[::-1]
ans=0

w_index=[i for i, x in enumerate(c) if x=="W"]
r_index=[i for i, x in enumerate(c1) if x=="R"]

for i in range(len(r_index)):
    r_index[i]=N-1-r_index[i]


if "R" in c and "W" in c:
    for i in range(min(len(r_index),len(w_index))):
        w=w_index[ans]
        r=r_index[ans]
        if w-r>0:
             break
        ans+=1

print(ans)

Solution (Python):
n = int(input())
c = input()
sc = sorted(c)
print(sum(c[i] != sc[i] for i in range(n)) // 2)

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

num_R = C.count("R")
num_W = C.count("W")

C_fin = ["R" if i < num_R else "W" for i in range(len(C))]

count = 0
for c, c_fin in zip(C, C_fin):
    if(c == c_fin):
        count += 1

ans = (len(C) - count)//2

print(ans)

Solution (Python):
n = int(input().strip())
a = bytearray(input().strip(), encoding='ascii')
h, t = 0, len(a) - 1

ans = 0
while h < t:
    while a[h] == ord('R') and h < t:
        h += 1
    while a[t] == ord('W') and h < t:
        t -= 1
    if h >= t:
        break
    if a[h] == ord('W') and a[t] == ord('R'):
        a[h] = ord('R')
        a[h] = ord('W')
        h += 1
        t -= 1
        ans += 1
    elif a[h] == ord('W') and a[t] == ord('W'):
        a[h] = ord('R')
        h += 1
        ans += 1
    elif a[h] == ord('R') and a[t] == ord('R'):
        t -= 1
        ans += 1
    else:
        assert False

print(ans)

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

Solution (Python):
n = int(input())
c = input()
r = c.count('R')
w = c.count('W')
count = 0
for i in range(r):
    if c[i] == 'W':
        count += 1
print(count)

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

if(stone == "R" * N):
    print(0)
elif(stone == "W" * N):
    print(0)
else:
    b = stone.count("R")
    c = stone[0:b].count("R")
    print(b-c)

Solution (Python):
N = int(input())
s = input()
cuml = 0
count = []
for i in range(N):
  if s[i] == 'R':
    cuml += 1
  count.append(cuml)
if cuml == 0: print(0)
else: print(cuml - count[cuml-1])

Solution (Python):
n = int(input())
s = input()
rn = s.count('R')
count = 0
for i in range(rn):
    if s[i] == 'W':
        count += 1
print(count)

Solution (Python):
n=int(input())
i=0;j=n-1;ans=0
s=list(input())
while j > i:
    if (s[i]=="W" and s[j]=="R"):
        s[i],s[j]=s[j],s[i]
        j-=1
        i+=1
        ans+=1
    elif s[i]=="W" and s[j]=="W":
        j-=1
    elif s[i]=="R" and s[j]=="R":
        i+=1
    elif s[i]=="R" and s[j]=="W":
        j-=1
        i+=1
print(ans)

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

a = 0
for i in range(N):
    if c[i] == 'R':
        a += 1
b = 0

ans = max(a,b)

for i in range(N):
    if c[i] == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a,b))
print(ans)

Solution (Python):
n=int(input())
c=input()
r=c.count("R")
w=c.count("W")

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

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

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

if r==0 or w==0:
    print(0)

else:
    l=c.count('R', 0, r)

    print(r-l)

Solution (Python):
n = int(input())
c = input()
R = c.count('R')
ans = 0
for i in range(R):
    if c[i]=='W':
        ans += 1
print(ans)

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

l = 0
r = N - 1
count = 0
while l < r:
    if C[l] == 'R' and C[r] == 'W':
        l += 1
        r -= 1
    elif C[l] == 'R' and C[r] == 'R':
        l += 1
    elif C[r] == 'W' and C[r] == 'W':
        r -= 1
    elif C[l] == 'W' and C[r] == 'R':
        l += 1
        r -= 1
        count += 1

print(count)

Solution (Python):

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")


class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque
def main():

    
        
        n = int(input())
        
        s = input()
        i=0
        j = n-1
        ans = 0
        while(i<j):
            if(s[i]=='R' and s[j]=='W'):
                i+=1
                j-=1
            elif(s[i]=='W' and s[j]=='R'):
                ans+=1
                i+=1
                j-=1
            elif((s[i]=='R' and s[j]=='R')):
                i+=1
            else:
                j-=1
        print(ans)
        


        
        



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
C = input()
W = sum([1 for c in C if c == 'W'])
R = len(C) - W
print(sum([1 for c in C[R:] if c == 'R']))

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

nowL = 0 
nowR = n-1 
ans = 0 

while(True):
    while(nowL < n-1):
        
        if(s[nowL]=='W'):
            break
        else:
            nowL+=1
    while(nowR > 0):
        
        if(s[nowR]=='R'):
            break
        else:
            nowR-=1
    if(nowR <= nowL):
        
        break
    
    nowL+=1
    nowR-=1
    ans+=1
    
    
print(ans)

Solution (Python):

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

r_count = C.count('R')
left_r_count = C[:r_count].count('R')
print(r_count-left_r_count)

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

ans = 0

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

Solution (Python):
n=int(input())
c=input()
list=[0 for i in range(n+1)]
r=0
for i in range(n):
  if c[i]=='R':
    r+=1
w=0
list[0]=max(r,w)


for i in range(n):
  if c[i]=='W':
    w+=1
  if c[i]=='R':
    r-=1
  list[i+1]=max(r,w)
print(min(list))

Solution (Python):
def alter_altar(s):
    tmp = 'R' * s.count('R') + 'W' * s.count('W')
    ans = 0
    for i in range(len(s)):
        if s[i] == tmp[i]:
            pass
        else:
            ans += 1
    return ans//2
if __name__ == "__main__":
    _ = input()
    s = input()
    print(alter_altar(s))

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



R = c.count('R')


W = c.count('W')





ans = 0
for i in range(R):
  if c[i] == 'W':
    ans += 1

print(ans)

Solution (Python):


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

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

a = 0
b = 0
for i in range(N):
    if (c[i] == 'R'):
        a +=1
ans = max(a,b)
for i in range(N):
    if (c[i] == 'R'):
        a -= 1
    else:
        b += 1
    now = max(a,b)
    ans = min(ans,now)
print(ans)

Solution (Python):
n = int(input())
s = input()
number_of_W_in_prefix = [0]
number_of_R_in_suffix = [0]
for i in range(n):
    number_of_W_in_prefix.append(number_of_W_in_prefix[i] + (s[i] == 'W'))
    number_of_R_in_suffix.append(number_of_R_in_suffix[i] + (s[n - i - 1] == 'R'))
result = n
for k in range(n + 1):
    result = min(result, max(number_of_W_in_prefix[k], number_of_R_in_suffix[n - k]))
print(result)

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

c = list(map(str, input()))

r = c.count("R")
w = 0

res = max(r, w)

for i in range(N):
    if c[i] == "R":
        r -= 1
    else:
        w += 1

    now = max(r, w)
    res = min(res, now)

print(res)

Solution (Python):
_=input();*C,=input();print(len([''for _ in range(C.count('W'))if C and C.pop()=='R']))

Solution (Python):
n = int(input())
s = str(input())
print(s[:s.count("R")].count("W"))

Solution (Python):
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] == 'W' and C[r] == 'R':
        l += 1
        r -= 1
        c += 1
    elif C[l] != 'W': l += 1
    elif C[r] != 'R': r -= 1
print(c)

Solution (Python):
N=int(input())
c=input()
a=0
b=0
for i in range(N):
    if c[i]=='R':
        a+=1

ans=max(a,b)
for i in range(N):
    if c[i]=='R':
        a-=1
    else:
        b+=1
    now=max(a,b)
    ans=min(ans,now)
print(ans)

Solution (Python):
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] != 'W' and C[r] != 'R': l += 1; r -= 1; continue
    if C[l] != 'W': l += 1; continue
    if C[r] != 'R': r -= 1; continue
    l += 1
    r -= 1
    c += 1
print(c)

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

R, W = 0, 0  
red, white = [], []  
for i in range(N):
    if C[i] == 'R':
        red.append(i)
        R += 1
    else:
        white.append(i)
        W += 1

ans = 10**10
for i in range(N+1):  
    ans = min(ans, max(bisect.bisect_left(white, i),
                       R-bisect.bisect_left(red, i)))
print(ans)

Solution (Python):
n = int(input())
c = input()
c = [char for char in c]

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

print(ans)

Solution (Python):
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] != 'W': l += 1; continue
    if C[r] != 'R': r -= 1; continue
    l += 1
    r -= 1
    c += 1
print(c)

Solution (Python):
n = int(input())
C = input()
print(C[:C.count('R')].count("W"))

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

    stone_white_total, stone_red_total = C.count('W'), C.count('R')

    stone_white_left, stone_red_right = [0], [stone_red_total]
    stone_white, stone_red = 0, stone_red_total
    for stone in C:
        if stone == 'W':
            stone_white += 1
        else:
            stone_red -= 1
        stone_white_left.append(stone_white)
        stone_red_right.append(stone_red)

    return min([max(w, r) for w, r in zip(stone_white_left, stone_red_right)])

print(d_alter_altar())

Solution (Python):
n = int(input())
c = input()
print(c[:c.count('R')].count('W'))

Solution (Python):
n = int(input())
s = input()
l = 0
r = n - 1
ans = 0

while l < r:
    while l < r and s[l] == 'R':
        l += 1
    while l < r and s[r] == 'W':
        r -= 1
    if l >= r:
        break
    ans += 1
    l += 1
    r -= 1

print(ans)

Solution (Python):
import sys
read = sys.stdin.read
def main():
    n = int(input())
    a = input()
    if not 'WR' in a:
        print(0)
        sys.exit()
    a = list(a)
    rnum = a.count('R')
    rl = 0
    rr = 0
    for i1 in range(rnum):
        rl += a[i1] == 'W'
    for j1 in range(n - rnum):
        rr += a[rnum + j1] == 'R'
    r = max(rl, rr)
    print(r)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s =list(input())
curr = 0
l  = n-1
count = 0
while(l>=0 and l>curr):
    
    if s[l]=='R' and s[curr]=='R' and l==curr:
        l-=1
        curr+=1
    elif s[l]=='R' and s[curr]=='W':
        s[curr]='R'
        s[l]='W'
        count+=1
        l-=1
        curr+=1
    elif s[l]=='R' and s[curr]=='R':
        curr+=1
    else:
        l-=1
print(count)

Solution (Python):
import sys
read = sys.stdin.read
def main():
    n = int(input())
    a = input()
    if not 'WR' in a:
        print(0)
        sys.exit()
    a = list(a)
    rnum = a.count('R')
    r = 0
    for i1 in range(rnum):
        r += a[i1] == 'W'
    for j1 in range(n - rnum):
        r += a[rnum + j1] == 'R'
    r = r // 2
    print(r)
if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=input()
print(s[:s.count("R")].count("W"))

Solution (Python):
import sys
N=int(sys.stdin.readline().strip())
C=sys.stdin.readline().strip()
L=[0]
R=[0]
for c in C:
    if c=="W":
        L.append(L[-1]+1)
    else:
        L.append(L[-1])

for c in C[::-1]:
    if c=="R":
        R.append(R[-1]+1)
    else:
        R.append(R[-1])
R=R[::-1]

ans=float("inf")
for i in range(N+1):
    ans=min(ans,max(L[i],R[i]))
print ans

Solution (Python):

import collections
n = int(input())
c = input()


cnt = collections.Counter(c)
w_cnt = cnt['W']
r_cnt = cnt['R']
w_right_cnt = w_cnt
r_right_cnt = r_cnt
w_left_cnt = 0
r_left_cnt = 0
if w_cnt == n or r_cnt == n:
    print(0)
    exit()
ans = n
for i in range(n):
    
    if c[i] == 'W':
        w_left_cnt += 1
        w_right_cnt -= 1
    if c[i] == 'R':
        r_left_cnt += 1
        r_right_cnt -= 1
    
    if w_left_cnt <= r_right_cnt:
        ans = min(r_right_cnt, ans)
    elif w_left_cnt > r_right_cnt:
        ans = min(w_left_cnt, ans)
print(ans)

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

R = C.count("R")

print(C[:R].count("W"))

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

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

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

i = 0
j = N-1
ans = 0
while True:
    if j <= i:
        break
    c = C[i]
    rc = C[j]
    if c=="W" and rc=="R":
        ans += 1
        i += 1
        j -= 1
    elif c=="W" and rc=="W":
        j -= 1
    elif rc=="R" and rc=="R":
        i += 1
    else:
        i += 1
        j -= 1
print(ans)

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

R = C.count("R")
W = C.count("W")

if R == 0 or W == 0:
    print(0)
    quit()

print(C[:R].count("W"))

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

i = 0
j = len(c)-1
cnt = 0

while i < j:
  if c[i] == "R":
    i += 1
    continue
  if c[j] == "W":
    j -= 1
    continue
  i += 1
  j -= 1
  cnt += 1
print(cnt)

Solution (Python):
n = int(input())
c = input()
_w = c.count('W')
_r = c.count('R')
ans = min(_w, _r)
d = [0] * n 
d[0] = 1 if c[0] == 'W' else 0
for i in range(n-1):
  d[i] = d[i-1] + 1 if c[i] == 'W' else d[i-1]
for i in range(1, n - 1):
  l = d[i-1] 
  r = _r - (i-d[i-1])
  ans = min(ans,max(l,r))
print(ans)

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

r=C.count("R")
s=C[0:r].count("R")

print(r-s)

Solution (Python):
import sys
from collections import Counter
n = int(input())
c = list(input())
s = Counter(c)
if s['R'] == 0 or s['W'] == 0:
  print('0')
  sys.exit()
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break

Solution (Python):
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  
		rightR -= 1
	else:          
		leftW += 1
	moves.append(max(leftW, rightR))

ans = min(moves[i] for i in range(N+1))
print(ans)

Solution (Python):
_,t=open(0)
print(t[:t.count('R')].count('W'))

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

r = S.count("R")
T = S[0:r]

print(r-T.count("R"))

Solution (Python):
n = int(input())
s = str(input())
print(s[:s.count("R")].count("W"))

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

a = c.count("R")
b = c[:a].count("R")

print(a-b)

Solution (Python):
n = int(input())
c = input()
cnt_R = c.count("R")
right_R = c[:cnt_R].count("R")
print(cnt_R - right_R)

Solution (Python):

import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
s = input().strip()
print(s[:s.count('R')].count('W'))

Solution (Python):
n=input();c=input();print(c[:c.count("R")].count("W"))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  

N = I()
c = LS2()



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

b = r[-1]  

if b == 0:
    print(0)
    exit()

print(min(max(w[i],b-r[i]) for i in range(N)))

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

a = s.count('R')
b = s[:a].count('R')

print(a-b)

Solution (Python):
def main():
    input()  
    stones = input()
    reds = stones.count('R')
    print(stones[:reds].count('W'))

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
c=input()
R=c.count('R')
W=0
ans=[R,c.count('W')]
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans.append(max(R,W))
print(min(ans))

Solution (Python):
n = int(input())
c = list(input())
r = n - 1
l = 0
ans = 0
while r >= l:
    if c[r] == 'R':
        while l <= r:
            if c[l] == 'W':
                break
            l += 1
        if l <= r:
            c[l], c[r] = c[r], c[l]
            ans += 1
    r -= 1
print(ans)

Solution (Python):
from math import ceil
n=int(input())
s=input()
lst=list(s)
i=0
j=n-1
c=0
while i<=j:
    if lst[j]=='R' and lst[i]=='W':
        temp=lst[j]
        lst[j]=lst[i]
        lst[i]=temp
        j-=1
        i+=1
        c+=1
        
    elif lst[j]=='R' and lst[i]=='R':
        i+=1
        
    elif lst[j]=='W' and lst[i]=='W':
        j-=1
        
    elif lst[j]=='W' and lst[i]=='R':
        i+=1
        j-=1
        
print(c)

Solution (Python):
n = int(input())
s = input()
print(s[:s.count("R")].count("W"))

Solution (Python):
N,c=input(),input()
print(c[:c.count('R')].count('W'))

Solution (Python):
N = int(input())
C = input()
print(C[:C.count("R")].count("W"))

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

rCount=c.count('R')
wCount=c[0:rCount].count('W')
print(wCount)

Solution (Python):
N = int(input())
s = input()
R_count = s.count("R")
 
new_s = s[R_count:N+1]
R_new = new_s.count("R")
print(R_new)