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 collections

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

r_n = collections.Counter(c)['R']

ans = r_n
for i in range(r_n):
    if c[i] == 'R':
        ans -= 1

print(ans)

Solution (Python):
a=int(input())
v=input()
b=v.count("R")
c=0
for i in v[:b]:
    if i!="R":
        c+=1
print(c)

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

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












def solve(x):
    r = (b[N]-b[x]) - (a[x]-a[0])
    
    return r >= 0


ok, ng = 0, N+1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    
    if solve(mid):
        ok = mid
    else:
        ng = mid




print(a[ok])

Solution (Python):
from collections import Counter

N=int(input())
color=input()

c = Counter(color)
r = c['R']

count = 0
for i in range(N):
  if r == 0:break
  if color[i]=='W':
    count += 1
    r -= 1
  else:
    r -= 1

print(count)

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

R_list = list()
W_list = list()

for i in range(N):
    if c_list[i] == "R":
        R_list.append(i)
    else:
        W_list.append(i)
        
if len(W_list) == 0 or len(R_list) == 0:
    print(0)
else:
    
    
    
    ans = len(R_list) - bisect.bisect_left(R_list,len(R_list))
    print(ans)

Solution (Python):
n = int(input())
C = list(input())
cr = 0
cw = 0
for c in C:
    if c == 'R':
        cr += 1
    else:
        cw += 1

if cw == 0:
    print(0)
else:
    ans = 0
    l = 0
    for r in range(0, cw):
        if C[n-1-r] == 'R':
            while C[l] != 'W':
                l += 1
            l += 1
            ans += 1
    print(min(ans, cr))

Solution (Python):
n = int(input())
s = input()
left = 0
right = n-1
ans = 0
while left!=right:
    if left+1 == right:
      if s[left]=="W" and s[right]=="R":
        ans += 1
        print(ans)
        exit()
      else:
        print(ans)
        exit()
    if s[left]!="W":
        left += 1
    else:
        if s[right]!="R":
            right -= 1
        else:
            right -= 1
            left += 1
            ans += 1
  
print(ans)

Solution (Python):
N=int(input())
c=list(input())
x=0
M=N
for i in range(N):
  if c[i]=="W":
    for j in range(N):
      if i==M-1-j:
        M=i
        break
      elif c[M-1-j]=="R":
        x+=1
        c[M-1-j]="W"
        M=M-j
        break
  if i==M:
    break
print(x)

Solution (Python):
import sys

input = sys.stdin.readline

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

r = s.count("R")
print(min(s[:r].count("W"), s[r:].count("R")))

Solution (Python):
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
n = ini()
c = input()
rc = c.count('R')
lc = c[:rc].count('W')
print(lc)

Solution (Python):
n=int(input())
cs=input()
ss=sorted(cs)
wr=0
for x,y in zip(cs,ss):
    if x=='W' and y=='R':
        wr+=1
print(wr)

Solution (Python):
import sys
input=sys.stdin.readline

n=int(input())
c=input().rstrip()

l=0
r=n-1
ans=0
while True:
    while c[l]=='R':
        l+=1
        if l==n:
            break
    while c[r]=='W':
        r-=1
        if r==-1:
            break
    if l>r:
        break
    ans+=1
    l+=1
    r-=1

temp=0
for i in c:
    if i=='R':
        temp+=1
temp=min(temp,n-temp)
ans=min(ans,temp)
print(ans)

Solution (Python):
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq

import bisect
import sys

sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    
    check = [False for _ in range(n)]
    check[s] = True
    
    queue = deque([s])
    visited_num = 1

    
    
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        
        if len(queue) == 0:
            
            
            return color

        now_vertex = queue.popleft()
        
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7



def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n = int(input())
s = input()
w = s.count("W")

print(w-s[w*-1:].count("W"))

Solution (Python):
n=int(input())
s=input()
rcount=0
for i in s:
	if(i=='R'):
		rcount+=1
ans=0
for i in range(rcount,n):
	if(s[i]=='R'):
		ans+=1
print(ans)

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

    w = C.count("W")
    r_right = C[-w:].count("R")

    print(min(n-w,w,r_right))
main()

Solution (Python):

from collections import deque

def main():
    n = int(input())
    c = input()

    cnt = 0
    que = deque(c)

    while que:
        r = que.pop()
        if r == 'R':
            while que:
                l = que.popleft()
                if l == 'W':
                    cnt += 1
                    break

    print(cnt)

if __name__ == '__main__':
    main()

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

n=0
for i in range(N-1):
    if (S[i]=='W' and S[i+1]=='R'):
        n+=1

if n==0 :
    ans = 0
else:
    ans=0
    p=N-1
    for i in range(N):
        if S[i]=='W':
            found = 0
            while p>i and found == 0:
                
                if S[p]=='R':
                    ans+=1
                    found = 1 

                p-=1


print(ans)

Solution (Python):
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    c = list(input())
    r = c.count('R')
    if r == 0:
        print(0)
        return
    print(r-c[:r].count('R'))

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
c=list(input())
cnt=0
res=10**30
rcum=[0]*(N+1)
wcum=[0]*(N+1)
for i in range(N):
    rcum[i+1]=rcum[i]+(c[i]=='R')
    wcum[i+1]=wcum[i]+(c[i]=='W')
for i in range(N+1):
    a=wcum[i]+(rcum[N]-rcum[i])
    res=min(res,a)
for i in range(N+1):
    b=max(wcum[i],(rcum[N]-rcum[i]))
    res=min(res,b)
    

print(res)

Solution (Python):
def solved():
    n = int(input())
    colors = input()
    red = colors.count('R')
    white = n - red

    wrong_red = 0
    for i in range(red):
        if colors[i] != 'R':
            wrong_red += 1
    wrong_white = 0
    for i in range(white):
        if colors[red + i] != 'W':
            wrong_white += 1
    assert wrong_white == wrong_red
    print(wrong_red)


if __name__ == '__main__':
    solved()

Solution (Python):


def main():
    n = int(input())
    C = input()
    w_count = C.count("W")
    if w_count == 0:
        print(0)
        return

    right_ws = C[-w_count:].count("W")
    diff = w_count - right_ws
    print(diff)
    return


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
    return int(input())
def readInts():
    return list(map(int, input().split()))
def readChar():
    return input()
def readChars():
    return input().split()

n = readInt()
c = list(input())
ans = 0
i = len(c)-1
j = 0
while 1:
    rflag = 0
    for i in range(i,-1,-1):
        if c[i]=="R":
            rflag=1
            break

    wflag = 0
    for j in range(j,len(c)):
        if c[j]=="W":
            wflag=1
            break
    if wflag and wflag and j<i:
        c[i]="W"
        c[j]="R"
        ans+=1
    else:
        break

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
d = {"RW": 0, "WR": 0}
for i in range(N):
    if S[i] == "R":
        d["RW"] += 1
ans = d["RW"]
for i in range(N):
    if S[i] == "R":
        d["RW"] -= 1
    else:
        d["WR"] += 1
    ans = min(ans, max(d["RW"], d["WR"]))
print(ans)

Solution (Python):

def main():
    n = int(input())
    c = input()
    r = c.count('R')
    w = c.count('W')
    ropt = c[:r].count('R')
    wopt = c[r:].count('W')

    rnot = r - ropt
    wnot = w - wopt

    return min(rnot,wnot)
    
 
if __name__ == '__main__':
    print(main())

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

r=0
w=0

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

delete=0

for j in range(r):
    if c[j]=="W":
        delete+=1

if r>=delete:
    print(delete)
else:
    print(delete + (r-delete))

Solution (Python):
N = int(input())
C = input()
nw = C.count('W')
nr = N - nw

if nw == N or nr == N:
    print(0)
else:
    a = C[:nr]
    b = C[nr:]
    nw = a.count('W')
    nr = b.count('R')
    n = min(nw, nr)
    m = max(nw, nr) - n
    print(n + m)

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

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

count = 0
for i in range(len(r)):
    if r[i] != i:
        r.insert(i, i)
        r.pop()
        count += 1

print(count)

Solution (Python):
N = int(input())
c = input()
w = []
r = []
for i, ci in enumerate(c):
    if ci == 'W':
        w.append(i)
    if ci == 'R':
        r.append(i)

answer = 0
lenw = len(w)
lenr = len(r)
while answer < min(lenr, lenw) and w[answer] < r[-answer-1]:
    
    answer += 1
print(answer)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    N = int(input())
    C = list(input().strip())
    l, r = 0, N-1
    ans = 0
    if 'R' not in C or 'W' not in C:
        print(0)
        return True
    while l < r:
        while C[l] == 'R':
            l += 1
        while C[r] == 'W':
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
            
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=input()
w=s.count('W')
r=s.count('R')
ans=min(w,r)
ans=min(ans,r-s[:r].count('R'))
print(ans)

Solution (Python):
from collections import deque
n = int(input())
w = deque([])
r = deque([])
s = input()
for i in range(n):
  if s[i] =="W":
    w.append(i)
  else:
    r.append(i)

ans = 0
if len(r)==0 or len(w)==0:
  print(0)
  quit()
  
while r[-1]>w[0]:
  rtemp = r.pop()
  wtemp = w.popleft()
  r.appendleft(wtemp)
  w.append(rtemp)
  ans += 1
  
  
  
print(ans)

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

R = 0
W = 0


for i in range(n):
    if c[i] == "R":
        R += 1
W = n - R
RR = 0
WW = 0
i = 0
while i<R:
    if c[i] == "W":
        WW +=1 
    i += 1
print(WW)

Solution (Python):
N = int(input())
c = list(input())
ans = 0
r = False
w = False
for i in c:
    if i == 'W':
        w = True
    else:
        r = True
    if r == True and w == True and i == 'R':
        ans += 1
c.reverse()
r = False
w = False
ans2 = 0
for i in c:
    if i == 'W':
        w = True
    else:
        r = True
    if r == True and w == True and i == 'W':
        ans2 += 1
cnt = c.count('W')
ans3 = 0
for i in range(N):
    if c[i] == 'R' and cnt > 0:
        ans3 += 1
        cnt -= 1
    if c[i] == 'W':
        cnt -= 1
    
print(min(ans,ans2,ans3))

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

W_cnt=c.count("W")
R_cnt=c.count("R")

wcnt=0
rcnt=0
for n in range(R_cnt):
    if c[n]=="W":
        wcnt+=1
for n in range(R_cnt+1,N):
    if c[n]=="R":
        rcnt+=1
print(max(wcnt,rcnt))

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

l, r = 0, N - 1
cnt = 0

while l < r:
    L, R = c[l], c[r]
    if L == 'W' and R == 'R':
        c[l], c[r] = 'R', 'W'
        l += 1
        r -= 1
        cnt += 1
    elif L == 'W' and R == 'W':
        r -= 1
    elif R == 'R' and R == 'R':
        l += 1
    else:
        l += 1
        r -= 1

print(cnt)

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

red = m.count('R')

con = 0;

for i in range(red):
    if m[i] == 'W':
        con += 1
print(con);

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

mae = 0
ushiro = N - 1

swap = 0

while mae < ushiro:
    if stones[mae] == "W":
        while mae < ushiro:
            if stones[ushiro] == "R":
                swap += 1
                ushiro -= 1
                break
            else:
                ushiro -= 1
                
        else:
            break
        mae += 1
        
    else:
        mae += 1
        
print(swap)

Solution (Python):
import sys
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
c = instr()
ans = 0

t = {"R":0, "W":0}

for i in range(n):
    t[c[i]] += 1

num_r = t["R"]

for i in range(num_r):
    if c[i] == "W":
        ans += 1

print(ans)

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

Solution (Python):
N = int(input())
stones = list(input().rstrip())
r = stones.count("R")

print(stones[r:].count("R"))

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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





N = getN()
C = input()









R_cnt = 0
for i in range(N):
    if C[i] == 'R':
        R_cnt += 1

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

Solution (Python):
from collections import Counter
N=int(input())
C = input()
p = Counter(C)["R"]
if p == 0 or p == N:
  print(0)
  exit()
r = 0
w = 0

for i,c in enumerate(C):
  if i < p:
    if c == "W":
      w += 1
  else:
    if c == "R":
      r += 1
print(max(r,w))

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

Wcnt = S.count('W')
Rcnt = S.count("R")

C = "R" * Rcnt + "W" * Wcnt

diff = 0
for i in range(len(S)):
    if C[i] != S[i]:
        diff += 1

ans = diff // 2
print(ans)

Solution (Python):
def resolve():
    N = int(input())
    C = input()
    l = 0
    r = len(C)-1
    cnt = 0
    while l < r:
        while l < len(C) and C[l] == 'R':
            l += 1
        while r >= 0 and C[r] == 'W':
            r -= 1

        if l >= r:
            break

        if C[l] == 'W' and C[r] == 'R':
            
            cnt += 1
            l += 1
            r -= 1
    
    print(cnt)
    
resolve()

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    C = S()

    wi, ri = 0, N-1
    ans = 0

    while ri >= 0 and wi < N:
        while wi < N and C[wi] != "W":
            wi += 1
        while ri >= 0 and C[ri] != "R":
            ri -= 1
        if wi >= ri:
            break
        if wi < N and ri >= 0:
            C[wi], C[ri] = C[ri], C[wi]
        wi += 1
        ri -= 1
        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

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

r = 0
w = 0
for c in C:
    if c == 'R':
        r += 1
    else:
        w += 1

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

ans = 0
if r < w:
    for rx in range(r):
        if C[rx] != 'R':
            ans += 1
else:
    for wx in range(w):
        if C[N-1-wx] != 'W':
            ans += 1

print(ans)

Solution (Python):
from collections import deque

N = int(input())
C = deque(list(input()))

ans = 0
while C:
    while C and C[0]=='R':
        _ = C.popleft()
    while C and C[-1]=='W':
        _ = C.pop()
    if C:
        ans += 1
        _ = C.popleft(), C.pop()

print(ans)

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

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

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


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

if r_cnt == n:
    print(0)
else:
    print(r_cnt - r_cnt_2)

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

wCounter = 0
for i in range(n):
    if cA[i] == "W":
        wCounter+=1

flag = 0
count = 0
for i in range(n-1, -1, -1):
    if flag == 0 and cA[i] == "R":
        flag = 1
    if flag == 1 and i < n-wCounter and cA[i] == "W":
        count+=1
print(count)

Solution (Python):
n=int(input())
c=input()
i=c.count('R')
j=c.count('W',0,i)
print(j)

Solution (Python):
N=int(input())
X=input()
aka=0
siro=0
for i in range(N):
    if(X[i]=="R"):
        aka+=1
    else:
        siro+=1
c=0
for i in range(aka):
    if(X[i]=="W"):
        c+=1
print(c)

Solution (Python):
n = int(input())
c = list(map(str, input()))

ans = 0

if (len(c) > c.count('R')) and (c.count('R') != 0):
  r_c = c[:c.count('R')]
  ans = r_c.count('W')

print(ans)

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

al = 0
for c in C:
    if c == 'R':
        al += 1

so = 0
for c in C[:al]:
    if c == 'W':
        so += 1

print(so)

Solution (Python):
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    N = int(input())
    c = input()
    countlist = [0]
    count = 0
    for i in c:
        if i == 'W':
            count += 1
            countlist.append(count)
        else:
            countlist.append(count)
    ans = 10**6
    for i in range(N+1):
        lnum = countlist[i]
        rnum = N - i - (countlist[-1] - countlist[i])
        difnum = min(lnum, rnum)
        lnum -= difnum
        rnum -= difnum
        tmp = difnum
        tmp += lnum + rnum
        if tmp < ans:
            ans = tmp
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):

import collections


def main():
    n = int(input())
    c = list(input())
    wcnt = c.count("W")
    rcnt = c.count("R")
    if wcnt == 0 or rcnt == 0:
        print(0)
        return
    ans = c[0:rcnt].count("W")
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = input()
d = sorted(c)
c_sorted = "".join(d)
r_count =c.count("R")
ans = 0
for i in range(r_count):
    if c[i] != c_sorted[i]:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
cs = [i for i in input()]
n_R = 0
for c in cs:
    if c == 'R':
        n_R += 1
n_n_R = 0
for i in range(n_R):
    if cs[i] == 'R':
        n_n_R += 1
print(n_R - n_n_R)

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

Solution (Python):
n=int(input())
c=list(input())
t=c.count('R')
s=len(c)
if t==s:
  print(0)
  exit()
u=c[t:]
v=u.count('R')
print(v)

Solution (Python):

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

cnt = S.count("R")
ans = S[cnt:].count("R")
print(ans)

Solution (Python):

N = int(input())
c = input()
r,w,cnt = 0,0,0
s = 0
flag = False
for i in range(N):
    if c[i] is 'W':
        w += 1
    elif c[i] is 'R':
        r += 1
for i in range(r):
    if c[i] is 'R':
        cnt += 1
print(min(min(r,w),r-cnt))

Solution (Python):
n=int(input())
c=input()
wlist=[]
rlist=[]
cntw=0
cntr=0
for i in range(n):
  if c[i]=='R':
    rlist.append(i)
    cntr+=1
  else:
    wlist.append(i)
    cntw+=1
rlist.sort(reverse=True)
cnt=0
for j in range(min(cntw,cntr)):
  if rlist==[] or wlist==[]:
    break
  elif rlist[j]>wlist[j]:
    cnt+=1
print(cnt)

Solution (Python):
n = int(input())
init = list(input())
num_w = init.count("W")
num_r = init.count("R")
count = 0
for i in range(num_r):
    if init[i] == "W":
        count += 1
print(count)

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

Solution (Python):




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


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

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


print(ans)

Solution (Python):
n=int(input())
c=input()
w=0
for i in range(n):
    if c[i]=="W":
        w+=1
w1=0
t=100
s=0
for i in range(n+1):
    r=n-i-(w-w1)
    if abs(w1-r)==1 and t!=0:
        t=1
        s=w1
    if w1==r:
        t=0
        s=w1
    if i!=n:
        if c[i]=="W":
            w1+=1
print(s+t)

Solution (Python):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction

INF = float('inf')
mod = int(1e9)+7


w=[]
r=[]
n=int(data())
s=data()
for i in range(n):
    if s[i]=='R':
        r.append(i)
    else:
        w.append(i)
cnt=0
w=w[::-1]
while r and w:
    if r.pop()<w.pop():
        break
    cnt+=1
out(cnt)

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

cw=c.count('W')
cr=c.count('R')

ans_s='R'*cr+'W'*cw

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

print((cnt+2-1)//2)

Solution (Python):

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

rcount = 0
wcount = 0
for i in range(N):
    if c[i] == 'W':
        wcount += 1
    else:
        rcount += 1

rst = 0
wst = 0
for i in range(N):
    if i <= rcount-1:
        if c[i] == 'W':
            wst += 1
    else:
        if c[i] == 'R':
            rst += 1
ans = max(wst, rst)
wst -= ans
rst -= ans

ans += wst
ans += rst

print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    c = S()
    dp1 = [0] * (n + 1)
    dp2 = [0] * (n + 1)
    W = c.count("W")
    R = c.count("R")
    for i in range(1, n + 1):
        dp1[i] = (c[i - 1] == "W") + dp1[i - 1]
        dp2[i] = (c[i - 1] == "R") + dp2[i - 1]
    ans = inf
    for i in range(n + 1):
        w = max(dp1[i], R - dp2[i], i - dp2[i])
        ans = min(ans, w)
    print(ans)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
C = list(input())
c = 0
top = 0
back = N-1
while top < back:
  if(C[top]=="W" and C[back]=="R"):
    c += 1
    C[top] = "R"
    C[back] = "W"
    top += 1
    back -= 1
  elif(C[top]=="W" and C[back]=="W"):
    back -= 1
  elif(C[top]=="R" and C[back]=="W"):
    top += 1
    back -= 1
  elif(C[top]=="R" and C[back]=="R"):
    top += 1
    
print(c)

Solution (Python):
N=int(input())
data=list(input())
r=data.count("R")
w=data.count("W")
last=[]
for i in range(r):
    last.append("R")
for i in range(w):
    last.append("W")
ans=0
for i in range(len(data)):
    if last[i]!=data[i]:
        ans+=1
print(int(ans/2))

Solution (Python):
N = int(input())
c = input()
cnt = 0
for char in c:
    if char == 'R':
        cnt += 1
cnt_loc = 0
for i in range(cnt):
    if c[i] == 'R':
        cnt_loc += 1
print(cnt - cnt_loc)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False



def main():
    N = I()
    c = list(S())

    left = 0
    right = N - 1
    ans = 0

    while True:
        if c[left] != 'W':
            left += 1
        if c[right] != 'R':
            right -= 1

        if left >= right:
            break

        if c[left] == 'W' and c[right] == 'R':
            c[left] = 'R'
            c[right] = 'W'
            ans += 1

        

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(input())
x = a.count('R')
b = a[:x]
print(b.count('W'))

Solution (Python):
from collections import deque
N = int(input())
S = input()
W = deque([])
R = deque([])

for i in range(N):
    if S[i] == "W":
        W.append(i)
    else:
        R.appendleft(i)


ans = 0
while W and R:
    w = W.popleft()
    r = R.popleft()
    if w > r:
        break
    ans += 1
print(ans)

Solution (Python):
def resolve():
    import math
    n = int(input())
    c = input()
    num = []
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
            num.append(0)
        else:
            w += 1
            num.append(1)
    fi = [0]*r+[1]*w
    ct = 0
    for i in range(n):
        if num[i] != fi[i]:
            ct += 1
    print(min(math.ceil(ct/2), w))
resolve()

Solution (Python):
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))