Problem:
 Score : 400 points    Problem Statement An altar enshrines N stones arranged in a row from left to right. The color of the i -th stone from the left (1 \leq i \leq N) is given to you as a character c_i ; R stands for red and W stands for white.  You can do the following two kinds of operations any number of times in any order:   Choose two stones (not necessarily adjacent) and swap them.  Choose one stone and change its color (from red to white and vice versa).   According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?      Constraints  2 \leq N \leq 200000  c_i is R or W .         Input Input is given from Standard Input in the following format:  N  c_{1}c_{2}...c_{N}       Output Print an integer representing the minimum number of operations needed.        Sample Input 1 4
WWRR      Sample Output 1 2  For example, the two operations below will achieve the objective.   Swap the 1 -st and 3 -rd stones from the left, resulting in RWWR .  Change the color of the 4 -th stone from the left, resulting in RWWW .        Sample Input 2 2
RR      Sample Output 2 0  It can be the case that no operation is needed.       Sample Input 3 8
WRWWRWRR      Sample Output 3 3

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
C = input()
c = Counter(C)
R = c["R"] * "R" + c["W"] * "W"

r = c["R"]
w = c["W"]


a = Counter(C[:r])["W"] 
b = Counter(C[r:])["R"]

ans = min(max(a, b), r, w)
print(ans)

Solution (Python):
def main():
    input()  
    stones = input()
    white_counter = []
    white_stones = 0
    red_stones = 0
    for color in stones:
        if color == 'W':
            white_stones += 1
        else:
            red_stones += 1
        white_counter.append(white_stones)

    if red_stones == 0:
        print(0)
    else:
        print(white_counter[red_stones - 1])


if __name__ == '__main__':
    main()

Solution (Python):
def readinput():
    n=int(input())
    c=list(input())
    return n,c

def findR(ir,c):
    i=ir
    while (i>=0 and c[i]=='W'):
        i-=1
    return i

def findW(iw,c):
    i=iw
    while(i<n and c[i]=='R'):
        i+=1
    return i

def main(n,c):
    iw=0
    iw=findW(iw,c)
    if iw==n:
        return 0
    ir=n-1
    ir=findR(ir,c)
    if ir==-1:
        return 0
    count=0
    while(iw<ir):
        
        count+=1
        ir=findR(ir-1,c)
        iw=findW(iw+1,c)
    return count

if __name__=='__main__':
    n,c=readinput()
    ans=main(n,c)
    print(ans)

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

w_len=c.count("W")
r_len=len(c)-w_len

print(min(w_len,r_len,c[:r_len].count("W")))

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

l = 0
r = N-1
ans = 0
while(l < r):
    while(l < N and c[l] == 'R'):
        l += 1
    while(r >= 0 and c[r] == 'W'):
        r -= 1
    if l > r or l >= N or r < 0:
        break
    else:
        
        if l-1 == r:
            ans += 1
            break
        else:
            l += 1
            r -= 1
            ans += 1

print(ans)

Solution (Python):
n=int(input())
c=list(input())
r_count=c.count("R")
w_count=c.count("W")
temp=list(c[:n-w_count])
print(temp.count("W"))

Solution (Python):
N = int (input())
c = str(input())
count=0

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

Solution (Python):
N=int(input())
stone= list(input())
white_number=sum(x=='W' for x in stone)
stone.reverse()
ans=0
for i in range(white_number):
    if stone[i] != 'W':
        ans+=1
print(ans)

Solution (Python):
def count_change(num):
    return max(num[0][0], num[1][1])

N = int(input())
C = input()
W = 0
R = 0
for c in C:
    if c=="W":
        W += 1
    else:
        R += 1

num = [[0,0],[W,R]]
min_change = count_change(num)
for i in range(N):
    if C[i]=="W":
        num[0][0] += 1
        num[1][0] -= 1
    else:
        num[0][1] += 1
        num[1][1] -= 1
    change = count_change(num)
    if change < min_change:
        min_change = change
        
print(min_change)

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

Solution (Python):
n=int(input())
s=list(input())
srcount = s.count('R')
if srcount == 0:
  print(0)
  exit()
t = s[:srcount]
twcount = t.count('W')
print(twcount)

Solution (Python):
N = int(input())
S = list(input())
s = S.count("W")
no = N - s
ans = 0
for i in range(no):
    if S[i]=="W":
        ans += 1
print(ans)

Solution (Python):
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce

I=sys.stdin.readline

def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom


def main():
	n=ii()
	s=I().strip()
	i=0
	j=n-1
	cnt=0
	while i<j:
		if s[i]=="R":
			i+=1
		if s[j]=="W":
			j-=1
		if s[i]=="W" and s[j]=="R":
			cnt+=1
			i+=1
			j-=1
	print(cnt)






		










		


		










		






if __name__ == '__main__':
	main()

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

L = 0
R = n - 1
swaps = 0
while L < R:
    if c[L] == 'W' and c[R] == 'W':
        R -= 1
    elif c[L] == 'W' and c[R] == 'R':
        swaps += 1
        c[L], c[R] = c[R], c[L]
    elif c[L] == 'R' and c[R] == 'W':
        R -= 1
        L += 1
    elif c[L] == 'R' and c[R] == 'R':
        L += 1

print(swaps)

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import Counter

n = ii()
s = input()

d = Counter(s)
num = d['R']
ans = num
wcnt = 0
rcnt = 0
for i in s:

    if i == 'W':
        wcnt += 1
    else:
        if num - 1 >= wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt+1
            wcnt = 0
        if num == 0:
            break
print(ans)

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

w = S.count('W')
r = N - w
bad_w = S[:r].count('W')
bad_r = S[r:].count('R')

if w == 0 or r == 0:
    print(0)
else:
    print(min(bad_r, bad_w))

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

main()

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

w = s.count('W')

s1 =list(sorted(s))
if 'W' in s:
    ans2 = s[:s1.index('W')].count('W')
else:
    ans2 = n
print(min(ans2, w, n-w))

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))

def dprint(*args):
   pass

N = list(map(int, input().split()))[0]
s = list(input())

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

while(l < r):
    dprint('l,r=', l, r)
    dprint('s=', s)
    while(l < r):
        if (s[l]=='W'):
            break
        l = l + 1
        dprint('l=', l)

    while(l < r):
        if (s[r]=='R'):
            break
        r = r - 1
        dprint('r=', r)

    if (l < r):
        s[l] = 'R'
        s[r] = 'W'
        count = count + 1
    
print(count)

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

num=c.count('R')
if num == 0 or len(c) == num:
  print(0)
  exit()

count=0

for i in range(num):
  if c[i] == 'W':
    count+=1

print(count)

Solution (Python):
def d1(x):
  if x == "R":
    return 0
  else:
    return 1

N = int(input())
C = list(map(d1,input()))
w = sum(C)
r = N - w

if sum(C[:r]) < w:
  print(sum(C[:r]))
else:
  print(w)

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

Solution (Python):
from sys import stdin


def readline_from_stdin() -> str:
    return stdin.readline().rstrip


if __name__ == '__main__':
    _ = int(input())
    
    
    C = [0 if c == "R" else 1 for c in input()]
    

    L = 0
    R = len(C)-1

    count = 0
    while True:
        
        
        while C[L] == 0:
            if L == len(C)-1:
                print(count)
                exit()
            L += 1
        
        while C[R] == 1:
            if R == 0:
                print(count)
                exit()
            R -= 1
        
        if R-L < 1:
            print(count)
            exit()

        
        C[L] = 0
        C[R] = 1
        L += 1
        R -= 1
        count += 1
        
        
        if L == len(C)-1:
            print(count)
            exit()
        if R == 0:
            print(count)
            exit()

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


def main():
    N = int(input())
    c = list(input())
    w = c.count("R")
    hidari = c[:w]
    ans = 0
    for i in hidari:
        if i == "W":
            ans += 1
    print(ans)

    
if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    C = input()
    red = C.count('R')
    red2 = C[:red].count('R')
    print(red-red2)



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
c=list(input())
countR = c.count('R')
countW2 = 0
countR2 = 0
for i in range(countR):
    if c[i]=="W":
        countW2 += 1
print(countW2)

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

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

n=c.count("R")

for i in range(n):
    if c[i]!="R":
        ans+=1
print(ans)

Solution (Python):






import collections





N = int(input())
clist = input()





c = collections.Counter(clist)
cr = c["R"]












ans = clist[:cr].count("W")
print(ans)

Solution (Python):
N = int(input())
C = list(input())
if len(set(C)) == 1:
  print(0)
else:
  R = C.count("R")
  W = C.count("W")
  print(max(C[:R].count("W"), C[R:].count("R")))

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

cnt = 0
r_num = s.count('R')
w_num = n - r_num





for i in range(n):
    if i > r_num - 1 and s[i] == 'R':
        cnt += 1
print(cnt)

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

left = 0
right = len(c)-1
count = 0

while left < right:
    while c[left] != 'W':
        left += 1
        if left >= right:
            print(count)
            exit()
    while c[right] != 'R':
        right -= 1
        if left >= right:
            print(count)
            exit()
        
    count += 1
    left += 1
    right -= 1

print(count)

Solution (Python):
N=int(input())
S=list(input())
c = 0
l=0
r=len(S)-1
while r > l:
    while l < r and S[l] == 'R':
        l += 1
    while r > l and S[r] == 'W':
        r -= 1
    if r > l:
        S[l] = 'R'
        S[r] = 'W'
        c += 1
print(c)

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

left = 0
right = N-1
c = 0

while True:
  if right <= left:
    break
  if seq[left] == "R":
    left += 1
    continue
  if seq[right] == "W":
    right -= 1
    continue
  left += 1
  right -= 1
  c += 1

print(c)

Solution (Python):
N = int(input())
C = input()
R = C.count("R")
ans = 0

for r in range(R):
  if C[r]=="W":
    ans+=1

print(ans)

Solution (Python):
import collections


N= int(input())
s = input()
counter = collections.Counter({'R':0, 'W':0})
counter.update(s)
print(s[:counter['R']].count('W'))

Solution (Python):
n=int(input())
s=input()
r_count=s.count('R')
ans='R'*r_count+'W'*(n-r_count)
cnt=0
for i in range(n):
    if ans[i]!=s[i]:
        cnt+=1
print(cnt//2)

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

def set_w(c, s):
    
    while s < len(c):
        if c[s] == 'W':
            return s
        else:
            s += 1
    return s

def main():
    n = int(input())
    c = list(input())
    s = 0
    e = len(c) - 1
    ans = 0

    
    s = set_w(c, s)

    while e > s:
        if c[e] == 'R':
            c[s] = 'R'
            c[e] = 'W'
            s = set_w(c, s)
            ans += 1
        e -= 1
    print(ans)

if __name__ == '__main__':
    main()

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

left = 0
right = N - 1

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


print(ans)

Solution (Python):
import sys

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

left = [-1, False]  
right = [len(c), False]  
count = 0

for i in range(len(c)):
    if not left[1]:
        left[0] += 1
        if c[left[0]] == 'W':
            left[1] = True

    if not right[1]:
        right[0] -= 1
        if c[right[0]] == 'R':
            right[1] = True

    if left[1] and right[1]:
        if left[0] > right[0]:
            break
        count += 1
        left[1] = False
        right[1] = False

    
    
    
    
    
    
    
    
    
    

print(count)

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

r = c.count('R')
w = n - r

l = ['R'] * r + ['W'] * w

count = 0
for i in range(n):
    if c[i] != l[i]:
        count += 1
        
print(int(count / 2))

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


for i in range(n):
    if s[i] == 'W':
        left = i
        break
else:
    print(0)
    exit()
for i in range(n-1, -1, -1):
    if s[i] == 'R':
        right = i
        break
else:
    print(0)
    exit()
ans = 0
while left < right and left < n and right >= 0:
    ans += 1
    
    left += 1
    right -= 1
    while left < n and s[left] != 'W':
        left += 1
    while right >= 0 and s[right] != 'R':
        right -= 1
print(ans)

Solution (Python):
n=int(input())
s=list(input())
x=[]
y=[]

for i in range(n):
  if s[i]=='R':
    x+=[i]
  elif s[i]=='W':
    y+=[i]
    
ans=0


while True:
    if len(y)==0:
      print(ans)
      break
    elif len(x)==0:
      print(ans)
      break
    elif x[-1]>y[0]:
      x.pop()
      y.pop(0)
      ans+=1
      continue
    
    else:
      print(ans)
      break

Solution (Python):
import copy


def get_int():
    return int(input())


def get_string():
    return input()


def get_int_list():
    return [int(x) for x in input().split()]


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


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


def get_string_char_list():
    return list(str(input()))





'''
while (idx < n) and ():

    idx += 1
'''

def main():

    n = get_int()
    c_list = get_string_char_list()

    count = 0
    ret = 0
    for i in range(0, n):
        if c_list[i] == "R":
            count += 1

    for i in range(0, count):
        if c_list[i] == "W":
           ret += 1

    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
stone = list(input())
r = 0
counter = 0
for i in range(n):
  if stone[i] == 'R':
    r += 1
for i in range(r):
  if stone[i] == 'W':
    counter += 1
print(counter)

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

r = c.count("R")
w = c.count("W")
a = "R"*r+"W"*w

ans = 0
for i in range(N):
    if(c[i] != a[i]):
        if(c[i] == "W" and a[i] == "R"):
            ans += 1
print(ans)

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

N=int(input().rstrip('\n'))
S=list(input().rstrip('\n'))
score = [S.count('R'),S.count('W')]
sta = 'R'
ws = 0
rs = S.count('R')
sto = 0
for i in range(N):
  if S[i] != sta:
    if sta=='W':
      ws += sto
      sto = 1
      score.append(max(rs,ws))
      sta ='R'
    else:
      rs -= sto
      sto = 1
      score.append(max(rs,ws))
      sta ='W'
  else:
    sto += 1
print(min(score))

Solution (Python):



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



r_max = 0
w_min = n - 1

cnt = 0

while r_max < w_min:
    if c[r_max] == "R":
        r_max += 1
        continue
    elif c[w_min] == "W":
        w_min -= 1
        continue
    else:
        cnt += 1
        r_max += 1
        w_min -= 1


print("{}".format(cnt))

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

head = 0
tail = n-1
cnt = 0

while head < tail:
  if c[tail] == "R":
    while c[head] == "R" and head != tail:
      head += 1
    if head != tail:
      head += 1
      cnt += 1
  tail -= 1
  
print(cnt)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)







INF = 1 << 50



def run():
    N = int(input())
    C = list(input())
    ans1 = C.count('W')
    ans2 = C.count('R')
    ans = min(ans1, ans2)
    if not ans:
        print(ans)
        return

    ans3 = 0
    l = 0
    r = N-1
    while l<r:
        if C[l] == 'W' and C[r] == 'R':
            ans3 += 1
            l += 1
            r -= 1
            continue
        elif C[l] == 'R':
            l+=1
        elif C[r] == 'W':
            r-=1
    print(min(ans, ans3))

if __name__ == "__main__":
    run()

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


def main():
  N = int(input())
  C = input()[:-1]

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

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

  print(ans)


if(__name__ == '__main__'):
  main()

Solution (Python):
n = int(input())
c = input()
cnt = 0
l, r = -1, n + 2

while True:
    l = c[l + 1 :].find("W") + l + 1
    r = c[:r].rfind("R")
    if l == -1 or r == -1 or r <= l:
        break
    else:
        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
l = list(input())
r=0
for i in l:
    if i=="R":
        r+=1
cr=0
cw=0
if r==0:
    print("0")
else:
    for i in range(len(l)):
        if l[i]=="R":
            cr+=1
        else:
            cw+=1
        if cw== r-cr:
            break
    print(cw)

Solution (Python):
def main():
    n = int(input())
    s = input()
    
    
    
    
    l = 0
    r = n-1
    ans = 0
    while(True):
        if(l >= n or r < 0):
            break
        if(s[l] == "R"):
            l += 1
            continue
        else:
            while(s[r] == "W"):
                if(r < 0):
                    print(0)
                    return
                r -= 1
            if(l >= r):
                break
            l += 1
            r -= 1
            ans += 1
            if(l >= r):
                break
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import heapq


N = int(input())
C = list(input())
W = [i for i, c in enumerate(C) if c == 'W']
R = [-i for i, c in enumerate(C) if c == 'R']
if not W or not R:
    print(0)
else:
    heapq.heapify(W)
    heapq.heapify(R)
    res = 0
    while W[0] < -R[0]:
        i = heapq.heappop(W)
        j = heapq.heappop(R)
        heapq.heappush(W, -j)
        heapq.heappush(R, -i)
        res += 1
    print(res)

Solution (Python):
n = int(input())
c = list(input())
cr = c.count('R')
cw = c.count('W')
if cr == 0 or cw == 0:
    print(0)
    exit()
print(c[:cr].count('W'))

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

r = C.count('R')
ans = 0
for c in C:
    if r == 0:
        break
    if c == 'W':
        ans += 1
        r -= 1
    else:
        r -= 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


def lcm(a, b):
    
    g = gcd(a, b)
    return a // g * b



N = int(input())
C = read()[:-1]
cntR = C.count('R')
print(C[:cntR].count('W'))

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

if 'R' in c:
  rc = c.count('R')
  change = c[:rc].count('W')
  right = 0
  for i in range(N):
    if c[N-1-i] == 'R':
      right = N-i
      break
  paint = c[:right].count('W')
  ans = min(change, paint)
else:
  ans = 0
print(ans)

Solution (Python):
from collections import deque
N = int(input())
T = deque(list(input()))
W = deque([])
R = deque([])
i = 1
while T:
  x = T.popleft()
  if x=="W":
    W.append(i)
  else:
    R.append(i)
  i += 1
len_w = len(W)
len_r = len(R)
if len_w==0 or len_r==0:
    print(0)
    exit()
else:
    c = 0
    while R[-1]>W[0]:
        x = W.popleft()
        y = R.pop()
        W.append(y)
        R.appendleft(x)
        c += 1
    print(min(c,len_w,len_r))

Solution (Python):
import sys


def _s(): return sys.stdin.readline().strip()


def main():
    _ = _s()
    s = _s()

    rc = 0
    wc = s.count("R")
    m = wc
    for c in s:
        if c == "R":
            wc -= 1
        else:
            rc += 1
        m = min(m, max(wc, rc))
    return m


if __name__ == "__main__":
    print(main())

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    N = II()
    C = LS()

    j = N-1
    cnt = 0
    
    for i in range(N):
        if i >= j: break
        ci = C[i]
        if ci == 'W':
            
            
            for k in range(j, i, -1):
                j = k-1
                ck = C[k]
                if ck == 'R':
                    
                    
                    cnt += 1
                    break

    
    print(cnt)


if __name__ == '__main__':
    solve()

Solution (Python):
def solve():
    N = int(input())
    C = input()
    i = 0
    j = N - 1
    ans = 0
    while i < j:
        if C[i] == 'W' and C[j] == 'W':
            j -= 1
        elif C[i] == 'W' and C[j] == 'R':
            
            
            
            i += 1
            j -= 1
            ans += 1
        elif C[i] == 'R' and C[j] == 'R':
            i += 1
        elif C[i] == 'R' and C[j] == 'W':
            i += 1
            j -= 1
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    
    t=1
    for _ in range(t):
        n=int(input())
        st=input()
        
        red=0
        white=0
        for i in range(n):
            if st[i]=='R':
                red+=1
            else:
                white+=1
        ans=0
        for i in range(red):
            if st[i]=="W":
                ans+=1
        print(ans)








BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
s = input()
l = 0
r = n - 1
cnt = 0
while l < r:
    if s[l] == "R":
        l += 1
    elif s[r] == "W":
        r -= 1
    else:
        cnt += 1
        l += 1
        r -= 1
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
c = list(input())
c_dict = Counter(c)
if len(c_dict) == 1:
    print(0)
else:
    print(c[:n - c_dict['W']].count('W'))

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

ans1=c.count("R")
ans2=c.count("W")

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

print(min([ans1,ans2,ans3]))

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

c=input()

wnum=0

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

cnt=0
for ci in c[:n-wnum]:
    if ci=="W":
        cnt+=1

print(cnt)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from collections import  Counter
def resolve():
    N,=pin()
    C=input()
    X=Counter(C)
    a=(min(X["R"],X["W"]))
    c=list(C)


    rightlimit_R=-1
    for i in range(1,N):
        if c[-i]=="R":
            rightlimit_R=N-i
            break
    cnt=0

    for i in range(N):

        if c[i]=="W":

            for j in range(rightlimit_R-1,0,-1):
                if c[j]=="R":

                    
                    rightlimit_R=j
                    break

            cnt+=1
        if rightlimit_R<=i:
            
            break


    print(min(a,cnt))
    

resolve()

Solution (Python):
n=int(input())
c=input()
l=0
r=n-1
score=0
for i in range(n):
  if l>=r:
    break
  if c[l]=="W":
    if c[r]=="R":
      score=score+1
      l=l+1
      r=r-1
    else:
      r=r-1
  else:
    l=l+1
print(score)

Solution (Python):
n = int(input())
s = input()
w_cnt = 0
r_cnt = 0
r_lis = []
res=0

tmp = s.count("R")
for i in range(tmp):
    if(s[i]=="W"):
        res+=1

print(res)

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

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

Solution (Python):
def main():
    from collections import deque
    n = int(input())
    s = input()

    r_list = deque([])
    for i,j in enumerate(s):
        if j == 'R':
            r_list.append(i)

    c = 0
    for i,j in enumerate(s):
        if r_list: 
            if j == 'W':
                r_list.pop()
                c += 1
            else:
                r_list.popleft()
        else:
            break
    print(c)
        
main()

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




def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
	n=II()
	s=input().rstrip().decode()

	w=[0]*(n+1)
	r=[0]*(n+1)

	for i,ss in enumerate(s):
		if ss=="W":
			w[i+1]=w[i]+1
		else:
			w[i+1]=w[i]

	for i,ss in enumerate(reversed(s)):
		if ss=="R":
			r[i+1]=r[i]+1
		else:
			r[i+1]=r[i]

	

	ans=0
	for i,j in zip(w[1:],reversed(r[1:])):
		ans=max(ans,min(i,j))
	print(ans)




if __name__ == "__main__":
	main()

Solution (Python):
N = int(input())
c = input()
r_num = 0
w_num = 0
for i in range(N):
    if c[i] == "R":
        last_r = i
        r_num += 1
    
for i in range(r_num):
    if c[i] == "W":
        w_num += 1
print(w_num)

Solution (Python):
N = int(input())
C = input()
iRCnt = C.count('R')
iCnt = 0
for i in range(iRCnt):
    if C[i] == 'R': iCnt +=1
print(iRCnt - iCnt)

Solution (Python):
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1

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


if __name__ == '__main__':
    main()

Solution (Python):



N = int(input())


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





whitec = c.count("W")

res = 0

for i in range(N - whitec, N):
    if c[i] == "R":
        res += 1

print(res)

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline

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

red = deque()
white = deque()

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

s = 0

while len(white) > 0 and len(red) > 0:
    w = white.popleft()
    r = red.pop()
    if w < r:
        s += 1
    else:
        break

print(s)

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

c=input()

w=[]
r=[]

for i,color in enumerate(c):
    if color=="W":
        w.append(i)
    else:
        r.append(i)


w=w[::-1]

ans=0

def finish(w,r):
    if w==[] or r==[]:
        return True
    elif w.pop()>r.pop():
        return True
    return False
    

while not finish(w,r):
    ans+=1

print(ans)

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

j = N-1
count = 0
for i in range(N):
    if RW[i]=='W':
        while i<j:
            if RW[j]=='R':
                count += 1
                j -= 1
                break
            j -= 1

print(count)