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 numpy as np
N = int(input())
S = input()
R_count=0
w_count=0
for i in S:
  if(i=="R"):
    R_count+=1


for i in np.arange(R_count):
  if(S[i]=="W"):
    w_count+=1

print(w_count)

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

R_count = c.count("R")
W_count = c[:R_count].count("W")

print(W_count)

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

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

ref_c = ["R"]*r_cnt + ["W"]*w_cnt

cnt = 0
for i in range(N):
    if C[i] != ref_c[i]:
        cnt += 1

ans = min(r_cnt, w_cnt, int(cnt/2))
print(ans)

Solution (Python):
n = int(input())
temparr = input()
dicts = {}
dicts["W"] = 0 
dicts["R"] = 0 
for i in temparr:
    dicts[i] += 1 

if dicts["W"] == 0 or dicts["R"] == 0 :
    print(0)
else:
    arr = []
    for i in temparr:
        arr.append(i)
    count = 0 
    index = 0 
    
    while dicts["R"]:
        if arr[index] == 'R':
            dicts["R"] -= 1 
        else:
            dicts["R"] -= 1 
            count += 1 
        index += 1
        
    print(count)

Solution (Python):
n = int(input())
c = input()
cl = list(c)
wi = 0
wnum=0
ri = n-1
rnum=0
br=0
bw=0
res1 = n
break1 = 0
for i in range(n):
    while(cl[wi] == "R" and bw==0):
        wi+=1
        if(wi >= n-1):
            bw=1
            break
    if(cl[wi] == "W"):
        wnum+=1
    while(cl[ri] == "W" and br==0):
        ri-=1
        if(ri <= 0):
            br=1
            break
    if(cl[ri] == "R"):
        rnum+=1
    if(ri < wi and break1 == 0):
        res1 = i
        break1 = 1
    wi+=1
    if(wi >= n-1):
        wi=0
        bw=1
    ri-=1
    if(ri <= 0):
        ri=n-1
        br=1

    if(br*bw==1):
        break
print(min(res1, rnum, wnum))

Solution (Python):

N = int(input())

C = list(str(input()))


Rnum = C.count('R')

ans = 0


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

print(ans)

Solution (Python):
n = int(input())
stone = input()
red_stone = stone.count("R")
white_stone = n - red_stone

left_red_stone = stone[:red_stone].count("R")
right_white_stone = stone[-white_stone:].count("W")

if left_red_stone == red_stone:
  print(0)
elif left_red_stone < right_white_stone:
  print(red_stone-left_red_stone)
else:
  print(white_stone-right_white_stone)

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

cnt = 0
w_last_index = N-1
for i in range(N):
  if c[i] == 'W':
    flag = True
    for j in range(w_last_index,i,-1):
      if c[j] == 'R':
        c[j] = 'W'
        w_last_index=j
        cnt+=1
        flag = False
        break
    if flag:
      break
print(cnt)

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

c = list(input())

n_r = c.count('R')
n_w = c[:n_r]

if 'R' in n_w:
    n_x = n_w.count('R')
else:
    n_x = 0

print(n_r - n_x)

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
S = [x for x in input()]

C = Counter(S)

W = C["W"]
R = C["R"]

SS = S[:R]
CC = Counter(SS)
RR = CC["W"]

print(RR)

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

res = 0
left, right = c.find('W'), c.rfind('R')
while left != -1 and right != -1 and left < right:
    res += 1
    left += 1
    right -= 1
    while left < n and c[left] != 'W':
        left += 1
    while right >= 0 and c[right] != 'R':
        right -= 1
print(res)

Solution (Python):
A=int(input())
N=list(input())
R=0
W=0
for i in range(A):
    if N[i]=='R':
        R+=1
for i in range(R):
    if N[i]=='W':
        W+=1
print(W)

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

ans=0

rcnt = C.count('R')

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

print(ans)

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

r_num = c_str.count('R')
w_num = c_str.count('W')

true_list = 'R' * r_num + 'W' * w_num

if c_str == 'R' * N:
    print(0)
else:
    dif = 0
    for i in range(N):
        if c_str[i] != true_list[i]:
            dif += 1

    print(dif // 2)

Solution (Python):
N = int(input())
S = input()
List=list(S)
flag=True
mid = ""
res = 0
n = List.count("R")
k=0
for i in range(n):
  if List[i] == "W":
    res += 1
print(res)

Solution (Python):
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
ans = min(B[N - a - 1], a, N - a)
print(ans)

Solution (Python):
n=int(input())
l=list(map(str,input().split()))
c=list("".join(l))
w=c.count('W')
cc=c[-w:]
r=cc.count('W')
print(w-r)

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

S = 0
E = 1
Ans = 0

while S < N - E:
  while C[S] == 'R' and S < N-1:
    S += 1
    
  while C[E*-1] == 'W' and E < N:
    E += 1
    
  if S >= N - E:
    break
  else:
    S += 1
    E += 1
  
  Ans += 1

print(Ans)

Solution (Python):
n = int(input())
c_list = list(input())
start = 0
end = n
ans = 0

while 1:
    for i in range(start, n):
        start = i
        if c_list[i] == "W":
            break
    for i in reversed(range(end)):
        end = i
        if c_list[i] == "R":
            break
    if start >= end:
        break

    c_list[start], c_list[end] = c_list[end], c_list[start]
    start += 1
    ans += 1

print(ans)

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

if words == ['R'] * n or words == ['W'] * n:
  print(0)
else:
  count = 0
  key = n - 1
  flag = False
  while words[key] != 'R':
    key -= 1
  for i in range(n):
    
    if key == i or key == i - 1:
      break
    if words[i] == 'R':
      continue
    if words[i] == 'W':
      words[i], words[key] = words[key], words[i]
      count += 1
      key -= 1
      while words[key] != 'R':
        key -= 1
    
  print(count)

Solution (Python):

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

ans = 0
i = -1
j = N
while( True ):
  
  i += 1
  while( i<j ):
    if( C[i] == 'W' ):
      break
    else:
      i += 1
  
  j -= 1
  while( j>i ):
    if( C[j] == 'R' ):
      break
    else:
      j -= 1
  
  if ( i<j ):
    ans += 1
  else:
    break

print(ans)

Solution (Python):

import sys

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

l = 0
r = len(C) - 1
ans = 0

while l < r:
    l = C.find('W', l)
    r = C.rfind('R', l, r + 1)
    
    
    if l == -1 or r == -1 or l > r:
        
        break

    l += 1
    r -= 1

    ans += 1

print(ans)

Solution (Python):
n = int(input())
c = str(input())
r = c.count('R')
w = c.count('W')
rc = c[0:r].count('R')
lst = list(c)
ans = min(r - rc, w)
print(ans)

Solution (Python):
import math
import sys

def main():
    N=int(input())
    C=list(input())
    res=0
    
    R=0
    W=0
    for i in range(len(C)):
        if C[i]=="W":
            W+=1
        else:
            R+=1
    for i in range(len(C)):
        if i<R:
            if C[i]=="W":
                res+=1
    print(res)
if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
c = input()
Wcou = 0
Rcou = 0
ans = 0
for i in range(N):
    if(c[i] == "W"):
        Wcou += 1
    else:
        Rcou += 1
tmp = ""
for i in range(Rcou):
    tmp = tmp + "R"
for i in range(Wcou):
    tmp = tmp + "W"
for i in range(N):
    if(tmp[i] != c[i]):
        ans += 1
print(str(ans//2))

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return input().split()


def main():
    _ = readint()
    c = readstr()
    '''
    WRWR -> RRWW
    RWRR -> RRRR
    WWWRR -> RRWWW
    WRWWR -> RRWWW
    WWRRWRRR -> RRRRRWWW
    WRRRWRRR

    c[:rc]までをすべてRにすればよい

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


if __name__ == "__main__":
    main()

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

w = []
r = []
for i in range(len(data)):
  if data[i] == "W":
    w.append(i)
  else:
    r.append(i)

ans = 0
if len(w) == 0:
  print(ans)
elif len(r) == 0:
  print(ans)
else:
  r = r[::-1]
  for i in range(min(len(w), len(r))):
    tmp_w = w[i]
    tmp_r = r[i]
    if tmp_w <= tmp_r:
      r.append(tmp_w)
      w.append(tmp_r)
      ans += 1
    else:
      break
  print(ans)

Solution (Python):
k = int(input())
s = list(input())

R_num=0
for i in range(k):
    if s[i]=="R":
        R_num+=1
count=0
for i in range(R_num):
    
    if s[i]=="W":
        count+=1
 
print(count)

Solution (Python):
n=int(input())
s=input()
arr=[i for i in s]

ar=sorted(arr)


ans=0
for i in range(len(arr)):
    if arr[i]!=ar[i]:
        ans+=1
if ans%2==0:
    print(ans//2)
else:
    print((ans//2)+1)

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

rtow = c.count('R')
wtor = 0

anses = []
for i in range(n + 1):
  anses.append(max(rtow, wtor))
  if i == n:
    break
  if c[i] == 'W':
    wtor += 1
  else:
    rtow -= 1

print(min(anses))

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

a=list(a)

t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1

for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

Solution (Python):
from collections import Counter

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

l = 0
r = N - 1

cnt = 0
while l < r:
    while l < r and C[l] == 'R':
        l += 1

    while l < r and C[r] == 'W':
        r -= 1

    if l < r:
        cnt += 1

    l += 1
    r -= 1


d = Counter(C)
min_ = min(d['W'], d['R'])
print(min(min_, cnt))

Solution (Python):
N = int(input())
c = list(input())
ans = 0
FLG = False
j = N - 1
for i, color in enumerate(c):
    if color == "W":
        while c[j] == "W":
            j -= 1
            if j <= i:
                FLG = True
                break
        if FLG:
            break
        ans += 1
        c[i], c[j] = c[j], c[i]

print(ans)

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

if s.count('W')==0 or s.count('R')==0:
    print 0
    exit(0)
ans=-1
for i in xrange(n-1, -1, -1):
    if s[i]=='R':
        ans=s[:i].count('W')
        break
w=[]
r=[]
for i in xrange(n):
    if s[i]=='W':
        w.append(i)
for i in xrange(n-1,-1,-1):
    if s[i]=='R':
        r.append(i)

for i in xrange(min(len(w), len(r))):
    if w[i]>r[i]:
        ans=min(ans, i)

print ans

Solution (Python):
import sys
import numpy as np
import math
import collections
import copy
from collections import deque 
from functools import reduce
from itertools import product
from itertools import combinations


N = int(input())
Cn = list(input())

Cc = copy.copy(Cn)
if (Cn[0] == "R"):
    Rflg = True
else:
    Rflg = False
ans = 0
K = N-1    
allw = False
for i in range(N):
    if Rflg and Cc[i] == "R":
        continue
    else:
        Rflg = True
    if Cc[i] == "W":
        for j in range(K, i, -1):
            if Cc[j] == "R":

                ans += 1
                Cc[i], Cc[j] = Cc[j], Cc[i]
                K = j

                break
        else:
            allw = True

    else:

        ans += 1
        Cc[i] = "W"

    if allw:
        break

print(ans)

Solution (Python):
n=int(input())
c=list(input())
all_r=c.count('R')
l_w=0
l_r=0
ans=0
for i in range(n):
  if l_w==all_r-l_r:
      ans=l_w
      break
  if c[i]=='W':
    l_w+=1
  else:
    l_r+=1
print(ans)

Solution (Python):
N = int(input())
list1 = list(input())
RN = list1.count('R')
ii = 0
for i in range(N):
    if list1[i] == 'W' and RN != 0:
        RN += -1
        ii += 1
    elif list1[i] == 'R' and RN != 0:
        RN += -1
    elif RN == 0:
        break
print(ii)

Solution (Python):
X = int(input())
S = input().strip()
res = 0
for x, y in zip(S, sorted(S)):
    res += int(x != y)
print(res//2)

Solution (Python):
N = int(input())
clst = list(input())
cnt = 0
k = -1

if 'R' not in clst or 'W' not in clst:
    pass

else:
    rnum = [i for i, c in enumerate(clst) if c == 'R']
    wnum = [j for j, c in enumerate(clst) if c == 'W'][::-1]

    t = min(len(rnum), len(wnum))

    for i in range(1, t+1):
        if rnum[-i] > wnum[-i]:
            cnt += 1
        else:
            break

print(cnt)

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

ans = 0

red_index = c.rfind('R')
white_index = c.find('W')
if red_index < 0:
    print(0)
    exit()
if white_index >= red_index or white_index < 0:
    print(0)
    exit()
ans += 1

for i in range(N):
    red_end = red_index
    white_start = white_index + 1
    red_index = c.rfind('R', 0, red_end)
    white_index = c.find('W', white_start, N)
    if red_index < 0:
        break
    if white_index >= red_index or white_index < 0:
        break
    ans += 1
print(ans)

Solution (Python):
n = int(input())
c = [l for l in input()]
ideal = ['R']*(c.count('R')) + ['W']*(c.count('W'))

w_to_r=0
r_to_w=0
for i_, c_ in zip(ideal, c):
  if (i_=='R') and (c_=='W'):
    w_to_r+=1
  if (i_=='W') and (c_=='R'):
    r_to_w+=1

print(max(w_to_r, r_to_w))

Solution (Python):
n = int(input())
stones = input()
left = 0
right = n-1

ans = 0
while True:
  while left < n and stones[left] == 'R':
    left += 1
  while right > 0 and stones[right] == 'W':
    right -= 1
  if left < n and right > 0 and left < right:
    left += 1
    right -= 1
    ans += 1
  else:
    break
print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


class saidan:
    def __init__(self,n,cl):
        self.n = n
        self.cl = cl
        self.l = 0
        self.r = n

    def check(self):
        for i in range(self.l,n):
            if cl[i] == 0:
                self.l = i 
                break
        else:
            self.l = self.n-1 


        for i in range(n-self.r,n):
            if cl[self.n-1-i] == 1:
                self.r = self.n-i
                break
            else:
                self.r = 0

        return self.r - self.l

    def swap(self):
        
        
        cl[self.l], cl[self.r-1] = cl[self.r-1],cl[self.l]

n = ii()
c = input()

cl = []
for i in range(n):
    if c[i] == 'R':
        cl.append(1)
    else:
        cl.append(0)

sd = saidan(n,cl)

ans = 0
while 1:
    if sd.check() <= 1:
        break
    
    sd.swap()
    ans += 1

print(ans)

Solution (Python):
n = int(input())
red = []
white = []
s = input()

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

roop_min_num = min(len(red), len(white))

res = 0
for i in range(roop_min_num):
    if white[i] < red[-i - 1]:
        res += 1
print(res)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    c=list(input())
    hidari=0
    migi=n-1
    ans=0
    while True:
        while c[hidari] != 'W':
            hidari +=1
            if hidari == migi:
                break
        while c[migi] != 'R':
            migi -=1
            if hidari == migi:
                break
        if hidari == migi:
            break
        ans +=1
        hidari +=1
        if hidari == migi:
                break
        migi -=1
        if hidari == migi:
            break
    print(ans)

        
if __name__=='__main__':
    main()

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

w_num = c_array.count('W')
r_num = n-w_num
def get_ans(half):
    wl_num = c_array[:half].count('W')
    rr_num = c_array[half:].count('R')
    ans = min(wl_num, rr_num) + abs(wl_num-rr_num)
    return ans

ans = min(get_ans(r_num), w_num, r_num)
print(ans)

Solution (Python):


from queue import Queue

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




queue = Queue()
stack = []
for i in range(len(c)):
    if c[i] == "W":
        queue.put(i)
    else:
        stack.append(i)

def is_ok(c):
    for i in range(len(c)-1):
        if c[i] == "W" and c[i+1] == "R":
            return False
    return True

ans = 0
while True:
    if queue.empty() or stack == []:
        break
    i = queue.get()
    j = stack.pop()
    if j < i:
        break
    ans += 1

print(ans)

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

count = 0
for i in c:
    if i == "R":
        count += 1

count2 = 0
for i in c[:count]:
    if i == "R":
        count2 += 1

print(count - count2)

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

n=b.count('R')
m=b[0:n]
ans=m.count('W')
print(ans)

Solution (Python):
n = int(input())
stones = input()
w = stones.count('W')
wend = stones[-w:].count('W')
print(w-wend)

Solution (Python):
N = int(input())
li = list(input())
an = 0
a = 0
b = len(li)-1
end = True

while True:
    while True:
        if a == len(li) -1 or a > b:
            end = False
            break

        if li[a] == 'W':
            break
        else:
            a += 1

    if end:
        while True:
            if b == 0 or a > b:
                end = False
                break

            if li[b] == 'R':
                break
            else:
                b -= 1

    if end:
        li[a] = 'R'
        li[b] = 'W'
        a+= 1
        b-= 1
        an += 1
    else:
        break
print(an)

Solution (Python):
N = int(input())
S = input()
A = int(S.count("R"))
if A == N:
  print(0)
  exit()
s = S[:A]
B = int(s.count("R"))
print(A-B)

Solution (Python):
N = int(input())
L = [0]
for i in input():
    if i == 'R':
        L.append(1)
    else:
        L.append(0)

r = sum(L)
print(r - sum(L[1:r+1]))

Solution (Python):
n=int(input())
s=input().strip()
p=s.count('W')
c=0
for j in range(n-p,n):
    
    if s[j]!='W':
        c=c+1
print(c)

Solution (Python):
n = int(input())
C = input()
cnt = 0

m = n
for i in range(n):
    if C[i] == 'W':
        for j in reversed(range(i,m)):
            if C[j] == 'R':
                cnt += 1
                m = j
                break
        else:
            break

print(cnt)

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

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 == 1:
        print(ans)
        break
    else:
        c[l] = 'R'
        c[r] = 'W'
        ans += 1

Solution (Python):

import sys,math,numpy as np

from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()



def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


n = ii1()
s=is1()
a=Counter(s)
W=a['W']
R=a['R']

if W == n or R == n:
    print(0)
else:
    countr=0
    countw=0
    for i in range(R,n):
        if s[i]=='R':
            countr+=1
        else:
            countw+=1
    print(countr)

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

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

l = 0
r = len(S) - 1

W = 'W'
R = 'R'

cnt = 0
while l < r:
    if S[l] == R:
        l += 1
        continue
    else:
        while l < r:
            if S[r] == W:
                r -= 1
                continue
            else:
                cnt += 1
                l += 1
                r -= 1
                break

print(cnt)

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

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

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

print(wcount)

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

cntR = 0
for i in range(0,n):
	if(s[i]=="R"):
		cntR+=1

cntRL = 0
for i in range(0,cntR):
	if(s[i]=="R"):
		cntRL+=1

print(cntR-cntRL)

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

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

white = c.count("W")
ans = 0

for i in range(n):
    if white == 0:
        break
    else:
        if c[n - i - 1] == "R":
            ans += 1
            white -= 1
        elif c[n - i - 1] == "W":
            white -= 1

print(ans)

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

def alter(c,n):
    number = 0
    i = 0
    j = n-1
    while(i<j):
        if c[j] == 'R':
            j -= 1
            while (c[i] == 'R'):
                i += 1
                if i >= j:
                    return number
            number += 1
            i += 1
        else:
            j -= 1
    return number
    

    
print(alter(c,n))

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

cnt = 0
l = 0
r = n-1
while l < r:
    if c[l] == 'R':
        l += 1
    elif c[l] == 'W':
        if c[r] == 'R':
            c[l] = 'R'
            c[r] = 'W'
            cnt += 1
        else:
            r -= 1

print(cnt)

Solution (Python):
n = int(input())
c = input()
cw = c
cr = ''.join(list(reversed(c)))






ans = 0
w=0
r=0
nn = n

for i in range(n):
  nw = cw.find('W')
  if nw == -1:
    break
  nr = cr.find('R')
  if nr == -1:
    break
  if (nw + nr + 2) > nn:
    break
  nn = nn - (nw + nr + 2)
  cw = cw[(nw+1):]
  cr = cr[(nr+1):]
  ans +=1

  
  

print(ans)

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

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

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


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

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

ans = 0
for x in c:
    r -= 1
    if x =='W':
        ans += 1
    if r == 0:
        break    

print(ans)

Solution (Python):
import collections
N = int(input())
stones = list(input())

c = collections.Counter(stones)
r_s = collections.Counter(stones[:c['R']])
print(c['R']-r_s['R'])

Solution (Python):
from collections import deque
n = int(input())
Cs = input()


widx = deque()
ridx = deque()
for i in range(n):
    if Cs[i] == 'W':
        widx.append(i)
    else:
        ridx.append(i)

cnt = 0
while True:
    if len(widx) == 0 or len(ridx) == 0:
        break
    elif widx[0] < ridx[-1]:
        widx.popleft()
        ridx.pop()
        cnt += 1
    else:
        break

print(cnt)

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

tmp = c.count('R')
tmp2 = c[:tmp].count('W')
tmp3 = c[tmp:].count('R')


if tmp2 > tmp3:
  print(tmp2*2-tmp3)
else:
  print(tmp3*2-tmp2)

Solution (Python):
from collections import Counter

n = int(input())
C = input()

c = Counter(C)

numR = 0

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

print(c['R']-numR)

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

s = sorted(c)

cnt = 0
for i, j in zip(c, s):
    if i != j:
        cnt += 1

print(cnt // 2)

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

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

Solution (Python):
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:rc]
    wwc = s.count('W')
    print(wwc)

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

head = 0
tail = n-1
ans = 0
while head < n:
    if arr[head] == "R":
        head += 1
    else:
        break
while tail >= 0:
    if arr[tail] == "W":
        tail -= 1
    else:
        break
while head < tail:
    head += 1
    tail -= 1
    ans += 1
    while head < n:
        if arr[head] == "R":
            head += 1
        else:
            break
    while tail >= 0:
        if arr[tail] == "W":
            tail -= 1
        else:
            break

print(ans)

Solution (Python):
from collections import deque

n=int(input())
d=deque(list(input()))

r=0
while n>1:
  
  tempr=False
  n-=1
  if d.pop()=="W":
    pass
  else:
    while n>0:
      n-=1
      if d.popleft()=="R":
        pass
      else:
        r+=1
        break
  
print(r)

Solution (Python):
import sys
from math import sqrt, gcd, ceil, log

from collections import defaultdict, Counter, deque

input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))



def main():
	n = int(input()); 
	
	
	
	
	
	
	
	
	s = list(input().strip())
	i, j = 0, n-1
	ans = 0
	while i < j:
		if s[i] == "W" and s[j] == "R":
			ans += 1
			s[i], s[j] = s[j], s[i]
		else:
			i += (s[i] == "R")
			j -= (s[j] == "W")
	print(ans)





if __name__ == "__main__":
	main()

Solution (Python):
from collections import Counter

n = int(input())
C = input()

c = Counter(C)

numR = 0

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

print(c['R']-numR)

Solution (Python):


n = int(input())
given_s = input()
s = list(given_s)

nr = nw = 0 
nr = s.count('R')
nw = n-nr
ans = 0 

if nw == 0:
    print(ans)
    exit()

l = s[:nr]
ans = l.count('W')
print(ans)

Solution (Python):

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

Wcnt=0
for i in range(len(C)):
    if C[i]=="W":
        Wcnt+=1
ans=0
for i in range(N-Wcnt,N):
    if C[i]=="R":
        ans+=1
print(ans)

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

i = 0
j = n-1
cnt = 0
while(i < j):
    if l[i] == "W" and l[j] == "R":
        l[j] = 'W'
        l[i] = 'R'
        i = i+1
        j = j-1
        cnt = cnt+1
        continue

    if l[i] == "R":
        i = i+1

    if l[j] == "W":
        j = j-1


while(len(l) > 0):
    if l[-1] == "W":
        l.pop()
        continue

    if l[-1] == "R":
        break

k = "".join(l)
print(k.count("W")+cnt)

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

l = 0
r = n-1

c = 0

while l < r:
    while l < r and a[l] == 'R': l += 1
    while l < r and a[r] == 'W': r -= 1
    
    if a[l] == 'W' and a[r] == 'R':
        c += 1
        a[l] = 'R'
        a[r] = 'W'

print(c)

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

flag_left = 0
flag_right = N-1
counter = 0

ok = max(C.count("W"),C.count("R"))
if ok ==N:
    print(0)
    exit()

while flag_left<flag_right:
    while C[flag_left]=="R":
        flag_left += 1
        if flag_left>N-1:
            break
    while C[flag_right]=="W":
        flag_right -= 1
        if flag_left<0:
            break
        
    if flag_left<flag_right:
        counter += 1
    flag_left += 1
    flag_right -= 1
print(counter)

Solution (Python):
n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    ans=ans+1
print(ans)

Solution (Python):
import copy
N = input()
ls = list(input())

countR = ls.count('R')
ls2 = copy.copy(ls)
del ls2[countR:]
count = ls2.count('W')
print(count)

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

Solution (Python):
n=int(input())
s=input()
if s.count('R')==n:
    print(0)
else:
    w=s.index('W')
    s=s[w:]
    a= s.count('W')
    b=s[len(s)-a:].count('W')
    print(a-b)

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

c = list(input())

cnt = 0
headcnt = 0
tailcnt = -1

Noflag = 0

while True:
    if c[tailcnt] == 'R' and Noflag == 0:
        while True:
            if c[headcnt] == 'W':
                c[headcnt], c[tailcnt] = c[tailcnt], c[headcnt]
                cnt += 1
                
                
                break
            else:
                headcnt += 1
                if headcnt + abs(tailcnt) >= len(c):
                    Noflag += 1
                    break
    elif c[tailcnt] == 'W' or Noflag == 1:
        tailcnt -= 1
        if headcnt + abs(tailcnt) >= len(c):
            print(cnt)
            break

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

Solution (Python):
from collections import Counter

n = int(input())
C = input()

c = Counter(C)

numR = 0

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

print(c['R']-numR)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	n = int(input())
	
	s = input()
	r_num = sum([1 for c in s if c == 'R'])
	w_num = n-r_num
	ret = 0
	for c in s[:r_num]:
		if c == 'W':
			ret += 1
			
			
	print(ret)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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