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 copy
N = int(input())
C = input()

first_r = -1
rcount = C.count('R')
wcount = C.count('W')
rcount_org = copy.deepcopy(rcount)
rlen = 0
ans = 0

if rcount == 0 or wcount == 0:
  print(0)
  exit()
  
for i, c in enumerate(C):
  if c == 'R':
    rcount -= 1
    rlen += 1
  
  if c == 'W':
    rcount -= 1
    rlen += 1
    ans += 1
    
  if rlen == rcount_org:
    print(ans)
    exit()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
s = input().strip()

from collections import deque

red_pos = deque([])
white_pos = deque([])
for i, v in enumerate(s):
    if v == 'R':
        red_pos.append(i)
    else:
        white_pos.append(i)

ans = 0
while True:
    if len(red_pos) == 0 or len(white_pos) == 0:
        break
    if red_pos[-1] < white_pos[0]:
        break
    ans += 1
    white_pos.popleft()
    red_pos.pop()

print(ans)

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

pos_r = set()
for i in range(n):
    if c[i] == 'R':
        pos_r.add(i)

ans = 0
num_r = len(pos_r)
for ri in pos_r:
    if ri >= num_r:
        ans += 1
print(ans)

Solution (Python):
from collections import deque
N = int(input())
A = list(input())
R = deque()
W = deque()
for i in range(N):
    if A[i] == "R":
        R.append(i)
    else:
        W.append(i)

        
ans = 0        
for i in range(N):
    if len(R) * len(W) == 0:
        print(0)
        break
    else:
        a = R.pop()
        b = W.popleft()
        if a < b:
            print(ans)
            break
        else:
            R.appendleft(b)
            W.append(a)  
            ans += 1

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

if sc[0] == "W" or sc[-1] == "R":
    print(0)
    
else:
    for i in range(n):
        if sc[i] == "W":
            W_start = i
            break

    W_in_R = 0

    for i in c[:W_start]:
        if i == "W":
            W_in_R += 1

    R_in_W = 0

    for i in c[W_start:]:
        if i == "R":
            R_in_W += 1

    print(max(W_in_R , R_in_W))

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

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

Solution (Python):




def main():
    N = int(input())
    c = list(input())
    nR = c.count("R")
    nW = c.count("W")
    
    rightR = c[nR:].count("R")
    leftW = c[:nR].count("W")
    print(max(rightR,leftW))

if __name__ == '__main__':
    main()

Solution (Python):

import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    c = list(input())
    left = 0
    right = n - 1
    ans = 0
    while True:
        if c[left] == "R" and left < n - 1:
            left += 1
        if c[right] == "W" and right > 0:
            right -= 1
        if right <= left:
            print(ans)
            break
        if c[left] == "W" and c[right] == "R":
            c[left] = "R"
            c[right] = "W"
            ans += 1
        """
        if c[left] == "W":
            c[left] = "R"
            ans += 1
        if c[right] == "R":
            c[right] = "W"
            ans += 1
        """



if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = input()
    CS = [c for c in input().strip()]

    wtotal = 0
    rtotal = 0
    for c in CS:
        if c == "W":
            wtotal += 1
        elif c == "R":
            rtotal += 1
        else:
            raise Exception()

    left = -1
    right = len(CS)

    op = 0
    w = 0
    r = 0
    while True:
        
        if w > r:
            right -= 1
            if CS[right] == "R":
                r += 1
        else:
            left += 1
            if CS[left] == "W":
                w += 1

        if w > 0 and r > 0:
            op += 1
            w -= 1
            r -= 1

        if right == left or right == 0 or left == len(CS) - 1:
            break

    change = op
    print(min(wtotal, rtotal, change))


main()

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
cnt = 0
i = 0
j = n-1
while True:
    while s[i] == 'R':
        i += 1
        if i >= n:
            break
    while s[j] == 'W':
        j -= 1
        if j < 0:
            break
    if i < j:
        cnt += 1
        i += 1
        j -=1
    else:
        break
print(cnt)

Solution (Python):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue



sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    n = ni()
    c = list(input())

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

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

    lastw = 0
    tmp = 0
    for i in range(n):
        if r == 0:
            break

        if c[i] == "W":
            r -= 1
            lastw += 1
        else:
            r -= 1

    print(lastw)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import numpy as np
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    s = S()
    cnt = 0
    for i in range(s.count("R")):
        if s[i] == "W":cnt += 1
    s = s[::-1]
    for i in range(s.count("W")):
        if s[i] == "R":cnt += 1
    print(cnt//2)

Solution (Python):
n = int(input())
cs = input()
cnt = 0
i = 0
j = n-1
while(1):
  if i >= j:
    break
  if cs[i] == "R":
    i += 1
  if cs[j] == "W":
    j -= 1
  if cs[i] == "W" and cs[j] == "R":
    cnt += 1
    i += 1
    j -= 1
      
print(cnt)

Solution (Python):
N=int(input())
A=input()
ans=0
lindex=0
rindex=N-1
flag=0
while(1):
    if lindex>=rindex:
        break
    if flag==0:
        if A[lindex]=="W":
            flag=1
        else:
            lindex+=1

    elif flag==1:
        if A[rindex]=="R":
            flag=2
        else:
            rindex-=1
    
    else:
        ans+=1
        flag=0
        lindex+=1
        rindex-=1


print(ans)

Solution (Python):
N = int(input())
colors = input()
data = [int(c == 'R') for c in colors]

lm = 0
rm = sum(data)
min_move = rm

for i in range(N):
    if data[i]:
        rm -= 1
    else:
        lm += 1
    move = min(lm, rm) + abs(lm - rm)
    min_move = min(min_move, move)

print(min_move)

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
s=X()
p=[1 if i=="W" else 0 for i in s]
a = s.count("R")
x = p[:a]
print(sum(x))

Solution (Python):
N = int(input())
c = input()
total_r = 0
total_w = 0
ans = 0
for i in range(len(c)):
    if c[i] == 'R':
        total_r += 1
    else:
        total_w += 1
for i in range(total_r):
    if c[i] == "W":
        ans += 1
print(ans)

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


ans = 10**6
r = [0]
w = [0]

for i in range(n):
    r.append(r[i] + (s[i] == "R"))
    w.append(w[i] + (s[i] == "W"))




for i in range(n + 1):
    mi = min(w[i], r[-1] - r[i])
    ma = max(w[i], r[-1] - r[i])
    
    
    
    
    ans = min(ans, mi + (ma-mi))

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)
else:
    print(c[0:r].count("W"))

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

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

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

print(ans)

Solution (Python):
N=int(input())
c=input()
C=[]
for i in range(N):
    C.append(c[i])
num= C.count("W")
CC=C[(N-num):]
numnum=CC.count("W")
print(num-numnum)

Solution (Python):




import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    
    
    n=int(readline())
    ss=readline().rstrip()
    j=len(ss)
    ans=0
    if j==1:
        print(0)
        return
    for i in range(len(ss)):
        if ss[i]=="W":
            j-=1
            if j >= 0:
                while ss[j]!="R":
                    j-=1
                    if j < 0:
                        break
            if j > i:
                ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Solution (Python):
n = int(input())
s = input()
cw = 0
lol = 0
for i in s:
    if i == 'W':
        cw += 1
for i in range(n-1,n-cw-1,-1):
    if s[i] == 'W':
        lol += 1
print(abs(lol-cw))

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

isiall = min(saidan.count('W'), saidan.count('R'))

tesuu = 0
for i in range(len(saidan)//2):
    r_iti = saidan.rfind('R')
    w_iti = saidan.find('W')
    
    if r_iti == -1 or w_iti == -1 or r_iti < w_iti:
        break
    
    saidan = saidan[w_iti+1 : r_iti]
    tesuu += 1
    
print(min(tesuu, isiall))

Solution (Python):
import collections
def main():
    N = int(input())
    S = list(input())
    if len(set(S))==1:
        print(0)
        return
    cnt = 0
    left = 0
    right = len(S)-1
    while left<right:
        while left<len(S) and S[left]=='R':
            left += 1
        while right>=0 and S[right] == 'W':
            right -=1
        if left<right and S[left] == 'W':
            cnt +=1
            left += 1
            right -=1
    print(cnt)
    return 0
if __name__ == "__main__":
    main()

Solution (Python):

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from functools import lru_cache

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

N = I()
C = S()

rest_R = C.count("R")
index = 0
operation = 0

while True:
    if rest_R == 0:
        break
    current = C[index]
    if current == "R":
        rest_R -= 1
        index += 1
    else:
        operation += 1
        rest_R -= 1
        index += 1

print(operation)

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

ans = 0
left = 0
right = N -1
while left < right:
    if C[right] == "W":
        right -= 1
        continue
    if C[left] == "R":
        left += 1
        continue
    if C[left] == "W" and C[right] == "R":
        ans += 1
        right -= 1
        left += 1

print(ans)

Solution (Python):
import numpy as np

N=int(input())
C=np.array([x for x in input()])

if np.count_nonzero(C=='W')==N:
  print(0)
else:
  R_count=np.count_nonzero(C=='R')
  print(np.count_nonzero(C[:R_count]=='W'))

Solution (Python):
N = int(input())
S = input()
cnt_w = S.count("W")
cnt_r = S.count("R")
cl_chg = min(cnt_w, cnt_r)

sw = S[:cnt_r].count("W")
sr = S[cnt_r:].count("R")
swap = min(sw, sr)
print(min(cl_chg, swap))

Solution (Python):
n = int(input())
c = str(input())
cn = [False]*n
for i in range(n):
    if c[i]=="R":
        cn[i]= True


ans = 0
k=n-1
b=0

for i in range(n):
    if b==1:
        break

    if not(cn[i]):
        for j in range(k,0,-1):

            if cn[j]:
                k =j-1
                if i < j:
                    
                    
                    ans +=1
                    break
            if i>=j:
                b=1
                break
print(ans)

Solution (Python):
n = int(input())
c = input()
rl = [ i for i,_ in enumerate(c) if _ == 'R' ]

cnt = 0
loc = 0
rid = -1
while True:
	try:
		if c[loc] == 'W':
			rloc = rl[rid]
			rid -= 1
			if rloc < loc:
				break
			else:
				cnt += 1
		loc += 1
		if loc == n:
			break
		
	except:
		break
print(cnt)

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

stones = input()

N = len(stones)

l = 0
r = N - 1

cnt = 0

while r - l > 0:
    while stones[l] != 'W' and r - l > 0:
        l += 1

    while stones[r] != 'R' and r - l > 0:
        r -= 1

    if r - l > 0:
        cnt += 1
        l += 1
        r -= 1
    else:
        break

print(cnt)

Solution (Python):
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    if N-i > exchange:
        if c[-(i+1)] =="R":
            
            
            
            
            
            
            
            
            ans += 1
            for k in range(exchange+1,N-(i+1)):
                if c[k] == "W":
                    exchange = k
                    break
            else:
                break
    else:
        break
print(ans)

Solution (Python):
n=int(input())
s=input()
l=[0]
for i in range(n):
    l.append(l[i]+(s[i]=="R"))
ans=n

for i in range(n+1):
    ans=min(ans,abs(l[i]-i)+abs(l[-1]-l[i]))
    
    if i==l[-1]:
        ans=min(ans,abs(l[i]-i))
        
print(ans)

Solution (Python):
n = int(input())
alis = list(input())
t = alis.count("R")
print(alis[0:t].count("W"))

Solution (Python):
n = int(input())
s = input()
nw = len([i for i in s if(i == 'W')])
ns = n - nw
i = 0
j = n-1
c = 0
while(i < j):
	if(s[i] == 'W' and s[j] == 'R'):
		c += 1
		i += 1
		j -= 1
	elif s[i] == 'R':
		i += 1
	elif s[j] == 'W':
		j -= 1
print(min([c,nw, ns]))

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

right = N-1
left = 0
cnt = 0
for i in range(N):
    if right <= left:
        break
        
    if c[right] == "W":
        right -= 1
    else:
        if c[left] == "R":
            left += 1
        
        else:
            cnt += 1
            left += 1
            right -= 1

print(cnt)

Solution (Python):

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

l = 0
r = n - 1
cnt = 0

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

print(cnt)

Solution (Python):


n=int(input())
c=list(input())
left=0
right=0
aru=0
for i in range(n):
  if c[i]=="R":
    aru+=1
dab=n-aru

left=0
right=aru
hantei=1000000000
for i in range(n):
  if c[i]=="R":
    right-=1
  else:
    left+=1
  if max(left,right)<hantei:
    hantei= max(left,right)
ans1=hantei
print(min(ans1,aru,dab))

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

Solution (Python):
num = int(input())
ban = list(input())
count = 0
Rcount = 0

for i in range(len(ban)):
    if ban[i] == "R":
        Rcount += 1

for i in range(len(ban)):
    if ban[i] == "R" and Rcount <= i:
        count += 1

print(count)

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

    r_count = 0
    w_count = 0

    for cc in c:
        if cc == 'R':
            r_count += 1
        else:
            w_count += 1

    ans = 0
    for cc in c[:r_count]:
        if cc == 'W':
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
c = input()
rnum = 0
okrnum = 0
wnum = 0
for i in range(N):
  if(c[i]=="R"):
    rnum += 1
  else:
    wnum += 1
if(rnum == 0 or wnum == 0):
  print(0)
else:
  for i in range(rnum):
    if(c[i]=="R"):
      okrnum += 1
  
  
  print(rnum - okrnum)

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

r_count = c.count("R")
w_count = c.count("W")

temp_c = c[r_count:]
print(temp_c.count("R"))

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


t = c.count("R")
print(t-c[:t].count("R"))

Solution (Python):
n = int(input())
s = input()
r = []
w = []
for i in range(n):
    if s[i] == 'W':
        w.append(i)
    else:
        r.append(i)
ans = 0
for i in w:
    if len(r) == 0:
        break
    if i > r[-1]:
        break
    r.pop()
    ans += 1
print(ans)

Solution (Python):
def next_i(i: int, S: str):
    while i < len(S):
        if S[i] == "W":
            return i
        else:
            i += 1
    return -1


def prev_i(i: int, S: str):
    while 0 <= i:
        if S[i] == "R":
            return i
        else:
            i -= 1
    return -1


def main():
    N = int(input())
    S = input()
    ans = 0

    left = next_i(0, S)
    right = prev_i(N - 1, S)

    while 0 <= left < right:
        ans += 1
        left = next_i(left + 1, S)
        right = prev_i(right - 1, S)

    print(ans)


main()

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

i = 0
j = N-1
count = 0 
frag = True
Frag_f = True
Frag_b = True
while (frag):
    if i >= j:
        break
    if Frag_f == True:
        if C[i] == "R":
            i = i + 1
        else:
            Frag_f = False
    if Frag_b == True:
        if C[j] == "W":
            j = j - 1
        else:
            Frag_b = False
    
    if Frag_b == False and Frag_f == False:
        count += 1
        Frag_f = True
        Frag_b = True
        i = i+1
        j = j-1
print(count)

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

Solution (Python):
n = int(input())
c = input()
if c.count('R') == n:
    print(0)
elif c.count('W') == n:
    print(0)
else:
    MIN = min(n-c.count('R'),n-c.count('W'))
    for i in range(n):
        if c[i] == 'W':
            red = c[i:].count('R')
            MIIN = red-c[i:i+red].count('R')
            print(min(MIIN,MIN))
            break

Solution (Python):
n=int(input())
c=list(input())
R_num=c.count("R")

pri_R=c[:R_num].count("R")

print(R_num-pri_R)

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n = II()
    t = input()
    conter = cl.Counter(t)
    num_w = conter["W"]
    num_r = conter["R"]
    w_in_r = 0
    r_in_r = 0
    for i in range(num_r):
        if t[i] == "W":
            w_in_r += 1
        else:
            r_in_r += 1
    r_in_w = num_r - r_in_r
    print(max(w_in_r, r_in_w))


main()

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
c = list(input())

ans = 0
l = 0
r = N-1
while l <= r:
    flag = False
    for i in range(l,N):
        if c[i] == 'W':
            l = i
            flag = True
            break
    if not flag:
        l = N

    flag = False
    for i in range(r+1)[::-1]:
        if c[i] == 'R':
            r = i
            flag = True
            break
    if not flag:
        r = -1

    if r < l:
        break
    
    c[l] = 'R'
    c[r] = 'W'
    ans += 1

print(ans)

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

Solution (Python):




def main():
    N = int(input())
    C = input()

    left = 0
    right = 1

    ans = 0

    while (left+right<N):
        if C[left]=='W':
            if C[-right]=='R':
                ans += 1
                left += 1
                right += 1
            else:
                right += 1
        else:
            left += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

N = int(input())
cs = list(input())


count_R = cs.count("R")
count_W = cs.count("W")

W_check = cs[: count_R]
R_check = cs[count_R:]



print(min(W_check.count("W"), R_check.count("R")))

Solution (Python):
N=int(input())
S= list(input())
W_count=S.count('W')
R_count=S.count('R')
count=0
if((W_count==0) or (R_count==0)):
    print(0)
else:
    list_test=['R']*R_count+['W']*W_count
    for i,j in zip(S,list_test):
        if(i!=j):
            count+=1
    print(count//2)

Solution (Python):
N = int(input())
S = input()
array = list(S)
leftW = None
rightR = None
for i in range(N):
    if array[i] == 'W':
        leftW = i
        break
for i in range(N):
    j = N-i-1
    if array[j] == 'R':
        rightR = j
        break
if leftW == None or rightR == None:
    print(0)
    exit()
counter = 0
while leftW < rightR:
    array[leftW] = 'R'
    array[rightR] = 'W'
    for i in range(leftW, N):
        if array[i] == 'W':
            leftW = i
            break
    for i in range(rightR):
        j = rightR - i
        if array[j] == 'R':
            rightR = j
            break
    counter += 1

print(counter)

Solution (Python):
N = int(input())
C = list(input())
ans = 0
r = 0
l = N - 1
while r < l:
    if C[r] == 'W':
        while True:
            if C[l] == 'R':
                ans += 1
                l -= 1
                break
            else:
                l -= 1
                if r == l:
                    break
    r += 1
print(ans)

Solution (Python):

"""
Created on Sun Aug  2 21:49:26 2020

@author: naoki
"""

N = int(input()) 
stones = input() 
count1 = stones.count("R") 
stones2 = stones[count1:]
count2 = stones2.count("R")
print(count2)

Solution (Python):
n=int(input())
data=input()
cnt=0
wcnt=0
for i in data:
    if i=="R":
        cnt+=1
for i in range(cnt):
    if data[i]=="W":
        wcnt+=1
print(wcnt)

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

Solution (Python):
from collections import Counter

N = int(input())
C = list(input())
C1 = Counter(C)
ans = 0
for i in range(C1["R"]):
    if C[i] == "W":
        ans += 1
print(ans)

Solution (Python):

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

w_count = 0
r_count = 0

for item in s:
    if (item == "W"):
        w_count+=1
    elif (item == "R"):
        r_count+=1

target = ["R"] * r_count + ["W"] * w_count

ans_count = 0
for i in range(n):
    if (s[i] != target[i]):
        ans_count+=1
print (int(ans_count / 2))

Solution (Python):


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

r_count = c.count('R')
w_count = c.count('W', 0, r_count)

print(w_count)

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

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
C = input()

i = 0
w = deque()
r = deque()
for c in C:
    if c == 'W':
        w.appendleft(i)
    else:
        r.append(i)
    i += 1

ans = 0
while len(w) != 0 and len(r) != 0:
    ww = w.pop()
    rr = r.pop()
    if ww > rr:
        break
    ans += 1

print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(S)
S_target = 'R' * c['R'] + 'W' * c['W']

ans = 0
for a, b in zip(S, S_target):
    if b == 'W':
        break
    if a != b:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
c = input()
left = 0
right = len(c)-1
ans = 0
while left < right:
    while left < len(c):
        if c[left] == "W":
            break
        left += 1
    while right > -1:
        if c[right] == "R":
            break
        right -= 1
    if left < right:
        ans += 1
    left += 1
    right -= 1
print(ans)

Solution (Python):
import sys

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

r = c.count("R")
if r == 0 :
    print(0)
    sys.exit()   
rs = c[:r]
rsw = rs.count("W")
a = rsw

w = list(reversed(c)).index("R")
w = (N - 1) - w
ws = c[:w]
b = ws.count("W")
print(min(a,b))

Solution (Python):
N = int(input())
c = list(str(input()))
cnt = 0
w = c.count("W")
r = N - w

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

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

wcnt=clist.count("W")
rcnt=clist.count("R")

clist1 = clist[0:rcnt]

wcnt2 = clist1.count("W")

print(wcnt2)

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

ans=20000000
num=0
for i in range(n):
     if c[i]=='W':
          num+=1
ans=min(ans,num)


l=0
for i in range(n):
     if c[i]=='W':
          l=i
          break
r=0
for i in range(n):
     if c[i]=='R':
          r=i

sum=0

while(l<r):
     sum+=1
     c[l]='R'
     c[r]='W'
     for i in range(l+1,n):
          if c[i]=='W':
               l=i
               break
     for i in range(r,0,-1):
          if c[i]=='R':
               r=i
               break
     

ans=min(ans,sum)
print(ans)

Solution (Python):
a = int(input())
l=list(input())
b = l.count("R")
s = 0
for i in range(b):
  if l[i]=="W":
    s = s+1
print(s)

Solution (Python):
N=int(input())
c=list(input())
ansa=c.count("R")
ansb=c[:c.count("R")].count("W")
print(min(ansa,ansb))

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


l = 0
r = n-1
c = 0
while l < r:
    
    

    if C[l]=='W' and C[r]=='R':
        C[l],C[r] = C[r],C[l]
        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()
cnt = [0 for _ in range(n)]
red = 0
for i in range(n):
    if c[i] == 'R': red += 1
    cnt[i] = red

print(red - cnt[red-1])

Solution (Python):
N=int(input())
S=list(input())
RS=S[::-1]

RSS=[]
F=0
W=0
R=0
for i in range(len(RS)):
    if F==0:
        if RS[i]=="R":
            RSS.append("R")
            R+=1
            F=1
    else:
        RSS.append(RS[i])
        if RS[i]=="R":
            R+=1
        else:
            W+=1

SS=RSS[::-1]


LW=[]
LR=[]
for i in range(len(SS)):
    if SS[i]=="W":
        LW.append(i)
    else:
        LR.append(i)
LR=LR[::-1]


LW.append(10**7)
LR.append(-1)

for i in range(len(LR)):
    if LW[i]>LR[i]:
        cnt=i
        break
print(min(cnt,W,R))

Solution (Python):

import math
n = int(input())
color = list(input())

i = 0
j = n-1
count = 0

while(i<j):
  found1 = 0
  found2 = 0
  for k in range(n-1-i):
    if color[i+k] == 'W':
      i = i+k
      found1 = 1
      break
  for k in range(j):
    if color[j-k] == 'R':
      j = j-k
      found2 = 1
      break

  if found1*found2 == 0:
    break
  elif i>j:
    break
  else:
    count += 1
    i+=1
    j-=1
      

print(count)

Solution (Python):
import sys

n = int(input())

s = input()

count_w = s.count('W')
count_r = n - count_w

if count_w == 0 or count_r == 0:
    print(0)
    sys.exit()

sa = s[:count_r]
sb = s[count_r:]
num_sa = sa.count('W')
num_sb = sb.count('R')
if num_sa <= num_sb:
    print(num_sa)
else:
    print(num_sb)

Solution (Python):
n = int(input())
c = input()
r = 0
for i in range(len(c)):
    if c[i] == "R":
        r += 1
m_w = 0
for i in range(r):
    if c[i] == "W":
        m_w += 1
print(m_w)

Solution (Python):
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-cnt:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

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

s = input()

cnt = 0

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

ans = 0

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

print(ans)

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

C = input()
firstW = -1
for i in range(N):
    if C[i] == "W":
        firstW = i
        break
for i in range(N-1,-1,-1):
    if C[i] == "R":
        firstR = i
        break

def checkR(ri,wi):
    for i in range(ri,wi,-1):
        if C[i] == "R":
            return i
    else:
        return -1

def checkW(ri,wi):
    for i in range(wi,ri):
        if C[i] == "W":
            return i
    else:
        return -1


if len(set(C)) == 1:
    print(0)
elif firstW > firstR:
    print(0)
else:
    ri = firstR
    wi = firstW
    cnt = 0
    while 1:
        wi = checkW(ri,wi+1)
        ri = checkR(ri-1,wi)
        if wi == -1 or ri == -1:
            break
        cnt += 1
    print(cnt+1)