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())
c_ls = input()
count_R = 0
for i in range(n):
    if c_ls[i] == 'R':
        count_R += 1
ans = 0
for i in range(count_R):
    if c_ls[i] == 'W':
        ans += 1
print(ans)

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

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

R_num = C.count("R")
R_pre_num = C[:R_num].count('R')
print(R_num-R_pre_num)

Solution (Python):
n=int(input())
s=input()
lr=0
lw=0
rr=0
rw=0
for i in range(n):
  if s[i]=='R':
    rr+=1
  else:
    rw+=1
minans=rr
for i in range(n):
  if s[i]=='R':
    rr-=1
    lr+=1
  else:
    rw-=1
    lw+=1
  ans=max(lw,rr)
  minans=min(ans,minans)
print(minans)

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

whites = []
reds = []
for i in range(N):
    if S[i] == 'W':
        whites.append(i)
    else:
        reds.append(i)

whites.reverse()

ans = 0
while reds and whites and whites[-1] < reds[-1]:
    whites.pop()
    reds.pop()
    ans += 1

print(ans)

Solution (Python):
n = int(input())
c = input()
wcnt = c.count('W')
ans = 0
it = list(reversed(c))[:wcnt]
for x in it:
    if x == 'R':
        ans += 1
print(ans)

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

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

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N = int(input())
S = input()
Rs = S.count('R')
Ws = N - Rs

if Rs == 0 or Ws == 0:
	print(0)
	sys.exit()

C = list(S)

i = 0
j = N-1
ops = 0

while i < j:
	while i < N and C[i] == 'R': i += 1
	while j >= 0 and C[j] == 'W': j -= 1

	if i < j:
		C[i], C[j] = C[j], C[i]
		ops += 1

print(ops)

Solution (Python):
n = int(input())
s = input()
tw = s.count("W")
cw = 0
ans = min(tw, n-tw)
for i in range(n):
    if s[i] == "W":
        cw += 1
    ans = min(ans, cw + n-i-1 - (tw-cw) - min(cw, n-i-1 - (tw-cw)))
print(ans)

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


white = []
for i in range(n):
    if s[i] == "W":
        white.append(i)

white = white[::-1]
if len(white) == 0:
    print(0)
    exit()
ans = 0
for i in range(n)[::-1]:
    if s[i] == "R":
        if not white:
            continue
        if i > white[-1]:
            ans += 1
            del white[-1]
print(ans)

Solution (Python):
n = int(input())
C = input()
sR = [0]*(n+1)
sW = [0]*(n+1)

for i in range(n):
    sR[i+1] = sR[i] + (C[i] == "R")
    sW[i+1] = sW[i] + (C[i] == "W")

ans = 10**10
for i in range(n+1):
    r = sR[n] - sR[i]
    w = sW[i]
    ans = min(ans, max(r,w))
print(ans)

Solution (Python):
INF = 1 << 60

N = int(input())
c = [i for i in input()]

left_w = 0
right_r = c.count("R")

ans = INF

for i in range(N + 1):
    now = min(left_w, right_r) + abs(left_w - right_r)
    ans = min(now, ans)
    if i < N:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1

print(ans)

Solution (Python):



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


l = 0
r = s.count("R")
ans = r
for i in range(n):
    if s[i] == "W":
        l += 1
    else:
        r -= 1
    ans = min(ans,max(l,r))
print(ans)

Solution (Python):
n = int(input())
a = input()
i1 = 0
i2 = n-1
t = 0

while i1 < i2:
	if a[i1] == "W" and a[i2] == "R":
		t += 1
		i1 += 1
		i2 -= 1
	elif a[i1] == "R":
		i1 += 1
	elif a[i2] == "W":
		i2 -= 1
print(t)

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

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

ans = n
for i in range(n + 1):
    right_r = cnt_r[n] - cnt_r[i]
    left_w = i - cnt_r[i]
    ans = min(ans, max(right_r, left_w))

print(ans)

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

r = 0

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

ng = 0

for i in range(r):
    if c[i] != 'R':
        ng += 1

print(ng)

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


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
s = input()
rn = [0]
wn = [0]
for i in range(n):
  if s[i] == "R":
    rn.append(rn[-1]+1)
    wn.append(wn[-1])
  else:
    rn.append(rn[-1])
    wn.append(wn[-1]+1)
ans = 10**10
for i in range(n+1):
  ans = min(ans,max(wn[i],rn[-1]-rn[i]))
print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    N = int(input())
    
    
    
    
    s=input()
    c=Counter(s)
    cr=c['R']
    cw=N-cr
    if cr==N:
        print(0)
        return
    cnt=0
    for i in range(cr):
        if s[i]=="W":
            cnt+=1
    print(cnt)




if __name__ == "__main__":
    main()

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

r_count=0

for i in stones:
	if i=='R':
		r_count+=1

ans=0
for i in stones[:r_count]:
	if i=='W':
		ans+=1
print(ans)

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

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

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

Solution (Python):
N = int(input())
S = str(input())
red = 0
for i in range(N):
  if S[i] == "R":
    red += 1
    
ans = 0    
for i in range(red):
  if S[i] == "W":
    ans += 1
  
print(ans)

Solution (Python):
n = int(input())
c = input()
r = c.count("R")
w = c.count("W")
ans = r
cc = 0
for i in range(n):
    cc += c[i] == "W"
    ans = min(ans, abs(i+1-r) + cc)
print(ans)

Solution (Python):
num = int(input())
c_i = input()
r_Count = c_i.count("R")
print(c_i[:r_Count].count("W"))

Solution (Python):
import sys

input = sys.stdin.readline


n = int(input())

s = list(input())

c = 0
for e in s:
    if e == 'R':
        c += 1

res = min(c,n-c)

tmp = 0
for i in range(c):
    if s[i] != 'R':
        tmp += 1

res = min(res,tmp)

print(res)

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

l = 0
while l < N and C[l] == "R":
    l += 1
r = N-1
while r > 0 and C[r] == "W":
    r -= 1

ans = 0
while l < r:
    if C[l] == "W" and C[r] == "R":
        ans += 1
        l += 1
        r -= 1
    elif C[l] == "W":
        r -= 1
    elif C[r] == "R":
        l += 1
    else:
        l += 1
        r -= 1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
r = S.count("R")
res = 0
for i in range(r):
  if S[i] != "R": res += 1
print(res)

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    c = ns()
    n_r = c.count("R")
    print(c[n_r:].count("R"))

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    S = input()
    border = S.count("R")
    ans = 0
    for i in range(N):
        if S[i] == "W" and i < border:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
line = input()
r_count = 0
for i in line:
  if i == 'R':
    r_count += 1
w_count = 0
for i in range(r_count):
  if line[i] == 'W':
    w_count += 1
print(w_count)

Solution (Python):
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n=N()
c=input()
ans=0
w=[]
r=[]
for i,j in enumerate(c):
    if j=="W":
        w.append(i)
    else:
        r.append(i)
x=min(len(w),len(r))
for i in range(x):
    if w[i]<r[-1-i]:
        ans+=1
    else:
        break
print(ans)

Solution (Python):
'''
自宅用PCでの解答
'''
import math

import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    c = input()
    nm = 0
    rn = 0
    for i in c:
        if i == "R":
            rn += 1

    for i in c[:rn:]:
        if i == "W":
            nm += 1

    print(nm)

    return None

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
s = ns()


w2r = 0
r2w = s.count("R")
ans = 999999999
for i in range(n+1):
    ans = min(ans, max(w2r, r2w))
    if i < n:
        if s[i] == "W":
            w2r += 1
        else:
            r2w -= 1

print(ans)

Solution (Python):


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

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

answer = 0
for c in C[:r]:
  if c=='W':
    answer += 1

print(answer)

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

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    c = ns()
    r = c.count('R')
    print(r - c[:r].count('R'))
    return

solve()

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())
C = sys.stdin.buffer.readline().decode().rstrip()

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

Solution (Python):
n=int(input())
c=input()
red=0
for i in range(n):
    if c[i]=="R":
        red+=1
for i in range(red):
    if c[i]=="R":
        red-=1
print(red)

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

N=int(input())+2
C="R"+input().strip()+"W"

W=[0]*(N+1)
R=[0]*(N+1)

for i in range(N):
    if C[i]=="W":
        W[i]=W[i-1]+1
    else:
        W[i]=W[i-1]

for i in range(N-1,-1,-1):
    if C[i]=="R":
        R[i]=R[i+1]+1
    else:
        R[i]=R[i+1]

ANS=1<<30
for i in range(N-1):
    ANS=min(ANS,max(W[i],R[i+1]))

print(ANS)

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

nR = c.count('R')


lnR = c[:nR].count('R')


print(nR-lnR)

Solution (Python):
n = int(input())
c = input()
l, r = 0, n-1
ans = 0
while l < r:
	if c[l] == "W" and c[r] == "R":
		ans += 1
		l, r = l+1, r-1
	else:
		if c[l] == "R":
			l += 1
		if c[r] == "W":
			r -= 1
print(ans)

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

rcnt = cls.count('R')

wcnt = cls[:rcnt].count('W')

print(wcnt)

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

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

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

Solution (Python):
n = int(input())
string = input()
r_cnt = string.count("R")
w_cnt = string.count("W")
j = 0
cnt = 0
for i in range(r_cnt):
    if string[i] == "W":
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
S=input()
c=0
for i in range(n):
  if S[i]=="R":
    c=c+1
d=0
for i in range(c):
  if S[i]=="R":
    d=d+1
print(c-d)

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

Solution (Python):
n=int(input())
s=input()
i=0
j=n-1
c=0
while True:
  while j>=0 and s[j]!="R":
    j-=1
  while i<n and s[i]!="W":
    i+=1
  if i>j:
    break
  c+=1
  j-=1
  i+=1
print(c)

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

Solution (Python):
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    S = input().strip()

    W = S.count("W")
    R = S[N - W:].count("R") 
    print(R)


if __name__ == "__main__":
    main()