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

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

total_count_R = stones.count('R')
left_count_R = stones[0:total_count_R].count('R')

answer = total_count_R - left_count_R

print(answer)

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

w, r = 0, c.count('R')
ans = max(w, r)
for i in range(n):
   if c[i] == 'W':
      w += 1
   else:
      r -= 1
   res = max(w, r)
   ans = min(ans ,res)
print(ans)

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

N = int(input())
S = input()[:-1]
R = S.count('R')
accR = [0]

for Si in S:
    accR.append(accR[-1]+(1 if Si=='R' else 0))

ans = 10**18

for i in range(N+1):
    ans = min(ans, abs(i-R)+abs(i-accR[i]))

print(ans)

Solution (Python):
n=int(input())
c=input()
a=0
i=0
j=len(c)-1
while(i<j):
  while(c[i]=="R" and i<j):
      i+=1
  while(c[j]=="W" and i<j):
      j-=1
  if i<j:
    a+=1
    i+=1
    j-=1
print(a)

Solution (Python):









def solve():
    N = int(input())
    stones = input()

    count = 0
    visited = 0
    r = stones[::-1]
    for i in range(N):
        if stones[i] == "W":
            j = r.find('R', visited, N-i)
            if j > -1:
                visited = j + 1
                count += 1

    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()

Solution (Python):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = input()
r = seq.count('R')
ans = 0
if r != n and r != 0:
    cnt = 0
    for i in xrange(n):
        if seq[i] == 'R':
            cnt += 1
        else:
            ans += 1
            cnt += 1
        if cnt == r:
            break
print(ans)

Solution (Python):
n = int(input())
c = list(input())
wcount = [0] * n
rcount = [0] * n
for i in range(n):
    if c[i] == 'W':
        wcount[i] = 1
    if c[-(i+1)] == 'R':
        rcount[-(i+1)] = 1
    if i != 0:
        wcount[i] = wcount[i] + wcount[i-1]
        rcount[-(i+1)] = rcount[-(i+1)] + rcount[-i]
ans = n
for i in range(n+1):
    if i == 0:
        W = 0
        R = rcount[0]
    elif i == n:
        W = wcount[-1]
        R = 0
    else:
        W = wcount[i-1]
        R = rcount[i]
    tmp = max(W, R)
    if tmp < ans:
        ans = tmp
print(ans)

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

ans = 0

c = input()
redNum = c.count("R")
leftWhite = c.count("W", 0,redNum)
rightRed = c.count("R", redNum,N)

ans += min(leftWhite, rightRed)
if leftWhite > rightRed:
    ans += (leftWhite - rightRed)

print(ans)

Solution (Python):
N=int(input())
c=str(input())
rnum=c.count('R')
wnum=c.count('W')

rnum_front=c.count('R', 0, rnum)
wnum_back=c.count('W', N-wnum, N)

if rnum > wnum:
    print(wnum-wnum_back)
else:
    print(rnum-rnum_front)

Solution (Python):
def main():
    _ = int(input())
    S = input()
    ri = S.count("R")  
    le = 0
    ans = max(ri, le)
    for s in S:
        if s == "R":
            ri -= 1
        else:
            le += 1
        ans = min(ans, max(ri, le))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = input()
left, right = 0, n - 1
cnt = 0
while left <= right:
    while left < n and c[left] == 'R':
        left += 1
    while right > -1 and c[right] == 'W':
        right -= 1
    if left == n or right == -1 or left >= right: break
    left += 1
    right -= 1
    cnt += 1
print(cnt)

Solution (Python):
n = int(input())
c = input()
d = c.count('R')
e = c[:d].count('R')
print(d-e)

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


l1 = list()
for i in range(N):
    if c[i] == 'R':
        l1.append(i)
        


num = 0

def swap(i, j):
    a = c[i]
    c[i] = c[j]
    c[j] = a
    return

if len(l1) >= 1:
    for i in range(N):
        if i > l1[-1]:
            break
        if c[i] == 'W':
             swap(i, l1.pop(-1))
             num += 1
        if len(l1) == 0:
            break
print(num)

Solution (Python):
n=int(input())
c=input()
d=c.count("R")
e=c[:d].count("R")
print(d-e)

Solution (Python):
import sys

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

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

solve()

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

def main():
    N = int(input())
    c = input()
    cnt_r = 0
    cnt_w = 0
    for i in c:
        if i == 'R':
            cnt_r += 1
        else:
            cnt_w += 1
    
    w_left = 0
    r_right = cnt_r
    ans = N
    for i in range(N):
        ans = min(ans, max(w_left, r_right))

        if c[i] == 'W':
            w_left += 1
        else:
            r_right -= 1
    print(min(ans, max(w_left, r_right)))

main()

Solution (Python):
n=int(input())
c=list(input())
numW=0
numR=c.count("R")
W=n-numR
a=[]
if numR==0 or W==0:
    print(0)
else:
    for i in range(n):
        if c[i]=="W":
            numW+=1
        else:
            numR-=1
        a.append(max(numR,numW))
    print(min(a))

Solution (Python):
N = int(input())
C = input()
num_w = 0
num_r = 0
for i in range(N):
    if C[i] == 'R':
        num_r += 1
ans = 10**10
for i in range(N+1):
    if i == 0:
        ans = min(ans, num_r)
    elif i == N:
        ans = min(ans, num_w)
    else:
        if C[i-1] == 'W':
            num_w += 1
        else:
            num_r -=1 
        ans = min(ans, max(num_r, num_w))
print(ans)

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

    right = N-1
    left = 0

    cnt = 0
    while left < right:
        while left < N and C[left] == 'R':
            left += 1

        while right >= 0 and C[right] == 'W':
            right -= 1
        
        if left >= right:
            break
        
        C[left], C[right] = C[right], C[left]
        cnt += 1
    
    print(min(cnt,C.count("R"), C.count("W")))
    
if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
C = input()
a = 0
rr = 0
lw = 0

for i in range(N):
    if C[i] == 'R':
        rr += 1
a = rr
for i in range(0, N):
    if C[i] == 'W':
        lw = lw+1
    else:
        rr = rr-1
    a = min(a, max(lw, rr))

print(a)

Solution (Python):
N=int(input())
c=input()
j_L=0
j_R=len(c)-1
ans=0
while True:
    while j_L<len(c) and c[j_L]=="R":j_L+=1
    while j_R>=0 and c[j_R]=="W":j_R-=1
    if j_L>=j_R:
        print(ans)
        exit()
    else:
        ans+=1
        j_L+=1
        j_R-=1

Solution (Python):
N=int(input())
c=input()
right_r=0
right_w=0
left_r=0
left_w=0
for i in range(N):
	if c[i]=='R':
		right_r+=1
	else:
		right_w+=1
ans=right_r
for j in range(N):
	cnt=0
	if c[j]=='W':
		left_w+=1
		right_w-=1
	else:
		left_r+=1
		right_r-=1
	if right_r<=left_w:
		cnt+=right_r
		cnt+=left_w-right_r
	else:
		cnt+=left_w
		cnt+=right_r-left_w
	if cnt<ans:
		ans=cnt
print(ans)

Solution (Python):
n=int(input())
c=input()
d=c.count("R")
e=c[:d].count("R")
print(d-e)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


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

    num_r = C.count("R")
    num_w = C.count("W")
    ans = min(num_r, num_w)

    left_r = 0
    left_w = 0
    for i in range(N):
        left_r += C[i] == 'R'
        left_w += C[i] == 'W'

        right_r = num_r - left_r
        right_w = num_w - left_w
        ans = min(ans, min(left_w, right_r) + abs(left_w - right_r))

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

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

if __name__ == "__main__":
    main()

Solution (Python):
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


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


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    cs = sRaw()
    ac_sums =[0]
    for c in cs:
        if c=="W":
            ac_sums.append(ac_sums[-1]+1)
        else:
            ac_sums.append(ac_sums[-1])
    ans = 0
    nW = ac_sums[-1]
    nR = N-nW
    ans = INF
    for n_idx,ac_sum in enumerate(ac_sums):
        ans = min(ans,max(ac_sum,nR-(n_idx-ac_sum)))
    print(ans)
    
main()

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

S = input()[:-1]
po = [0 for i in range(n)]

for i in range(n-1,-1,-1):
    if i == n-1:
        if S[i] == "R":
            po[i] += 1
    else:
        if S[i] == "R":
            po[i] += po[i+1]+1
        else:
            po[i] += po[i+1]
co = 0

for i in range(n):
    if po[i] - co > 0 and S[i] != "R":
        co += 1
print(co)

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

w = c.count("W")
r = c.count("R")

cnt = 0

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

print(cnt)

Solution (Python):
N = int(input())
C = input()
rcount = len([1 for c in C if c == "R"])

count = 0
r = 0
w = 0
for i in range(rcount):
    c = C[i]
    if c == "W":
        if r > 0:
            r -= 1
            count += 1
        else:
            w += 1
    c = C[N-i-1]
    if c == "R":
        if w > 0:
            w -= 1
            count += 1
        else:
            r += 1
ans = count + w
print(ans)

Solution (Python):
N = int(input())
c = input()
len_r = 0
len_w = 0
for i in range(N):
    if c[i] == 'R':
        len_r += 1
len_w = N - len_r
n_r = 0
for j in range(len_r):
    if c[j] == 'R':
        n_r += 1
ans = len_r - n_r
print(ans)

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

Solution (Python):
N = int(input())
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')
a = words[0:ct_R]
W_in_a_count = a.count('W')
print(W_in_a_count)

Solution (Python):
n=int(input())
li=[]
red=0
white=0
count=0
li=list(input())
for i in li:
  if i == 'R':
    red+=1
  else:
    white+=1

checkw=0
for i in range(red):
  if li[i]=='W':
    checkw+=1

checkr=0
for i in range(white):
  if li[i+red]=='R':
    checkr+=1
sa=checkw-checkr
if sa==0:
  print(checkr)
elif sa>0:
  print(checkr+sa)
else:
  print(checkw+sa)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i < b:
    r+=1
  if c[i] == 1 and i >= b:
    w+=1
 

print(max(w,r))

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

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

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

cntR = c.count('R')

print(c[:cntR].count('W'))

Solution (Python):
N = int(input())
c = list(input())
cd = c[::-1]

rs = [0]*(N+1)
ws = [0]*(N+1)
ws[0]= 0
rs[0] = 0

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

    if(cd[i]=="R"):
        ws[i+1]=ws[i]+1
    else:
        ws[i+1]=ws[i]
    
ws.reverse()

m = 1000000000
for i in range(N+1):
    M = max(rs[i],ws[i])
    if m>M:
        m = M
    
print(m)

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

t = n
lw, rr = 0, c.count('R')
for ci in c+'Z':
    swap = min(lw, rr)
    wtor, rtow = max(0, lw-swap), max(0, rr-swap)
    t = min(t, swap + wtor + rtow)
    lw = lw + (ci == 'W')
    rr = rr - (ci == 'R')

print(t)

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

lw, rr = [0]*(n+1), [c.count('R')]*(n+1)
for i in range(n):
    lw[i+1] = lw[i] + (c[i] == 'W')
    rr[i+1] = rr[i] - (c[i] == 'R')


def operation(left_white, right_red):
    swap = min(left_white, right_red)
    white_to_red, red_to_white = max(0, left_white-swap), max(0, right_red-swap)
    return swap + white_to_red + red_to_white


print(min(operation(white, red) for white, red in zip(lw, rr)))

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

rs = l.count("R")
print(l[:rs].count("W"))

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

R_cnt = C.count('R')
print(C[:R_cnt].count('W'))

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

rw = [0, 0]
for i in range(N):
  if c[i] == 'R':
    rw[0] += 1
  else:
    rw[1] += 1
    
ans = N
left_rw = [0, 0]
right_rw = rw[:]
for i in range(N+1):
  if i == 0:
    pass
  else:
    if c[i-1] == 'R':
      left_rw[0] += 1
      right_rw[0] -= 1
    else:
      left_rw[1] += 1
      right_rw[1] -= 1
      
  ans = min(max(left_rw[1], right_rw[0]), ans)
  
print(ans)

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

if 'WR' in c:
    x=c.count('R')
    y=c.count('R',0,x)
    count=x-y
print(count)

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

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


cnt = 0
R = 0
W = 0

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

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

Solution (Python):
import math
from decimal import *

n = int(input())
c = str(input())
w = c.count('W')
c = c[::-1]
ans= 0
for i in range(w):
    if(c[i]!= 'W'):
        ans+=1
print(ans)

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

rcnt=s.count("R")
wcnt=s[:rcnt].count("W")
print(wcnt)

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





t1=t2=True

n1=0
n2=0
num=0
while t1:
    t2=True
    if not 0<=N-1-n1<=N-1:
        t1=False
    if c[N-1-n1]=='W':
        n1+=1
        continue
    else:
        while t2:
            if c[n2]=='W':
                if n2<N-1-n1:
                    c[N-1-n1]='W'
                    c[n2]='R'
                    num+=1
                    t2=False
                    continue
                else:
                    t1=False 
            n2+=1
            if not 0<=n2<=N-1:
                t1=False
                t2=False
print(num)

Solution (Python):
N = int(input())
c = input()
W = 0
R = c.count("R")
if N == R or R == 0:
  print("0")
else:
  cnt = N
  for i in range(N):
    if c[i] == "W":
      W = W + 1
    else:
      R = R - 1
    m = max(W, R)
    if m < cnt:
      cnt = m
  print(cnt)

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

c=list(input())

minimum=len(c)
W=0
R=c.count('R')

for i in range(0,len(c)):
    if c[i]=='W':
        W += 1
    else :
        R -= 1
    min_i=max(W,R)
    if min_i < minimum:
        minimum=min_i

if c.count('R')==0:
    minimum=0

print(minimum)

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

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

print(wr)

Solution (Python):
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N = ri()
    c = rs()
    x = 0
    y = c.count('R')

    for e in c:
        if x == y:
            break
        elif e == 'W':
            x += 1
        else:
            y -= 1

    print(y)

if __name__ == '__main__':
    main()

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

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

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

count2 = 0
for i in range(count):
    if(s[i] == "W"):
        count2 += 1

print(count2)

Solution (Python):
n = int(input())
list = input()
count_r = list.count('R')
ans = list[:count_r].count('W')

print(ans)

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

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

Solution (Python):
n=input()
i=list(input())
Wn=i.count("W")
print(Wn-i[(len(i)-Wn):].count("W"))

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

Solution (Python):
import sys

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

right_R = N
for i in range(N-1,-1,-1):
    if c[i] == 'R':
        right_R = i
        break

left_W = -1
for i in range(N):
    if c[i] == 'W':
        left_W = i
        break

if right_R == N or left_W == -1:
    print(0)
    sys.exit(0)

ans = 0
p = left_W
q = right_R
while p < q:
    for i in range(p+1,N):
        if c[i] == 'W':
            p = i
            break
        if i == N-1:
            p = N
    for i in range(q-1,-1,-1):
        if c[i] == 'R':
            q = i
            break
        if i == 0:
            q = -1
    ans += 1

print(ans)

Solution (Python):
n = int(input().rstrip())
red = []
white = []
stones = input().rstrip()
for idx, stone in enumerate(stones):
  if stone == "R":
    red.append(idx)
  if stone == "W":
    white.append(idx)
red_len = len(red)
white_len = len(white)
cnt = 0
for i in range(min(red_len, white_len)):
  red_idx = red[-1-i]
  white_idx = white[i]
  if red_idx> white_idx:
    cnt += 1
  else:
    break
print(cnt)

Solution (Python):
N=int(input())
C=input()
s=0
e=N-1
ans=0
while(s<e):
  while(C[s]=="R" and s<e):
    s+=1
  while(C[e]=="W" and s<e):
    e-=1
  if s<e:
    s+=1
    e-=1
    ans+=1
print(ans)

Solution (Python):
n = int(input())
s = input()
l = 0
r = n-1
ans = 0
while l < r:
    
    if s[l] == 'W':
        if s[r] == 'W':
            r -= 1
        elif s[r] == 'R':
            r -= 1
            l += 1
            ans += 1
    elif s[l] == 'R':
        if s[r] == 'W':
            r -= 1
            l += 1
        elif s[r] == 'R':
            l += 1
print(ans)

Solution (Python):
n = input()
c = input()
i = 0
while 1:
    l = c.find('W')
    r = c.rfind('R')
    if l == -1 or r == -1 or l >= r:
        break
    c = c[:l] + 'R' + c[l + 1:r] + 'W'  + c[r + 1:]
    i += 1
print(i)

Solution (Python):
N=int(input())
stones = list(input())
l = 0
r = N-1
count = 0

while(True):
  while(stones[l] == "R" and l < N-1):
    l += 1
  while(stones[r] == "W" and r > 0):
    r -= 1
  if (l >= r):
    print(count)
    exit()
  else:
    count += 1
    l += 1
    r -= 1

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

left = string[:0]
right = string[0:]
w, r = left.count("W"), right.count("R")
count = max(w,r)

for i in range(1,n+1):
    next_str = string[i-1]
    if next_str == "W":
        w +=1
    else:
        r -= 1
    tmp = max(w,r)
    if tmp < count:
        count = tmp
        
print(count)

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):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    n = int(input())
    c = str(input())

    
    
    
    
    
    w, r = 0, 0
    for i in range(n):
        if c[i] == "W":
            w += 1
        else:
            r += 1
    x, y = 0, 0
    for j in range(r):
        if c[j] == "W":
            x += 1
    for k in range(r+1, r+w):
        if c[k] == "R":
            y += 1
    print(max(x, y))

    
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
C = [x for x in str(input())]
cnt_R = C.count('R')
swap_W = C[:cnt_R].count('W')
ans = swap_W
print(ans)

Solution (Python):
n = int(input())
c = list(input())
r = 0
w = 0
for i in range(len(c)):
    if(c[i]=="R"):
        r += 1
ans = max(r,w)
for i in range(len(c)):
    if(c[i]=="R"):
        r -= 1
    else:
        w += 1
    now = max(r,w)
    ans = min(ans,now)
print(ans)

Solution (Python):
W = "W"
R = "R"

N = int(input())
C = list(input())
numR = C.count(R)
result = 0
for i in range(numR):
    if C[i] == W:
        result += 1
print(result)

Solution (Python):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    n = ri()
    C = input()
    if C[0] == "R":
        R = [1]
        W = [0]
    else:
        R = [0]
        W = [1]

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

    best_cost = min(R[-1], W[-1])
    for i in range(n):
        rl = R[i]
        wl = W[i]
        rr = R[-1] - rl
        wr = W[-1] - wl
        swaps = min(wl, rr)
        flips = wl + rr - 2 * swaps
        best_cost = min(best_cost, flips + swaps)
    print (best_cost)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

Solution (Python):
N = int(input())
S = input()
from collections import Counter
d = Counter(list(S))
allr = d["R"]
leftd = Counter(list(S[:allr]))
leftr = leftd["R"]
print(allr-leftr)

Solution (Python):
N = int(input())
c = list(input())
w = c.count("W")
r = c.count("R")
wr = c[len(c) - w:].count("W")

print(min(r, w - wr))

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

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

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

for i in range(N):
    if C[i] == 'W':
        red_start = i
        break
    if i == N-1:
        red_start = N-1

for i in range(1, N+1):
    if C[-i] == 'R':
        white_start = i
        break
    if i == N:
        white_start = N

red_pos = red_start
white_pos = white_start    

while red_pos + white_pos < N:
    answer += 1
    for i in range(red_pos+1, N):
        if C[i] == 'W':
            red_pos = i
            break
        if i == N-1:
            red_pos = N-1
    for i in range(white_pos+1, N+1):
        if C[-i] == 'R':
            white_pos = i
            break
        if i == N:
            white_pos = N

print(answer)

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

Solution (Python):
N=int(input())
ls=list(input())
left=0
right=N-1
count=0
while True:
  while left<N and ls[left]=='R':
    left+=1
  while right>0 and ls[right]=='W':
    right-=1
  if left>=right:
    break
  left+=1
  right-=1
  count+=1
print(count)

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

c = input()

l = len(c)
a = 0
b = 0

for i in range(l):
    if c[i] == "R":
        a += 1

for i in range(a, l):
    if c[i] == "R":
        b += 1

print(b)

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

Solution (Python):
N = int(input())
c = list(str(input()))
r = c.count('R')
w = 0
for i in range(r):
    if c[i] == 'W':
        w += 1
print(w)

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

left = 0
right = N-1
count = 0

while left < right:
    if C[left] == 'W' and C[right] == 'R':
        count += 1
        left += 1
        right -= 1

    if C[left] == 'R':
        left += 1
    if C[right] == 'W':
        right -= 1

print(count)

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

r = s.count("R")

print(s[:r].count("W"))

Solution (Python):
N = int(input())
S = input()
redPref = [0 for i in range(0, N)]

if S[0] == 'R':
    redPref[0] += 1

for i in range(1, N):
    redPref[i] += redPref[i - 1]
    if S[i] == 'R':
        redPref[i] += 1

def query(l, r, pref):
    a, b = 0, pref[r]
    if l - 1 >= 0:
        a = pref[l - 1]
    return b - a


ans = min(N - redPref[-1], redPref[-1])

for i in range(0, N - 1):
    leftRed = query(0, i, redPref)
    leftWhite = i - leftRed + 1

    rightRed = query(i + 1, N - 1, redPref)
    rightWhite = ((N - 1) - (i + 1) + 1) - rightRed

    swaps = min(leftWhite, rightRed)
    leftWhite -= swaps
    rightRed -= swaps
    leftRed += swaps
    rightWhite += swaps

    ans = min(ans, leftWhite + rightRed + swaps)

print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
c = stdin.readline().rstrip()
R_cnt = c.count('R')
L_cnt = 0
for i in range(R_cnt):
  if c[i] == 'R':
    L_cnt += 1
print(R_cnt - L_cnt)

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

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

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

Solution (Python):
N = int(input())
O = input()
ridx = [i for i, s in enumerate(O) if s == 'R']
n = len([i for i in ridx if i >= len(ridx)])
print(n)

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

tmp = C
tmp2 = len(tmp.replace("W",""))
tmp3 = C[0:tmp2]
ans = len(tmp3.replace("R",""))   
print(ans)

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


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


w = 0

r = R

ans = r

for i in range(n):
    if C[i] == "W":
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
print(ans)

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

count = 0
r = c.count('R')

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

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

Solution (Python):
N=int(input())
s=input()
A=[]
for i in range(N):
    A.append(s[i])

cntW=0
for i in range(N):
    if A[i]=="W":
        cntW+=1
cntR=N-cntW

changeW=0
changeR=0
for i in range(cntR):
    if A[i]=="W":
        changeW+=1
for i in range(cntR,N):
    if A[i]=="R":
        changeR+=1

if changeR==changeW:
    ans=changeW
else:
    
    maxN=max(changeR,changeW)
    ans=maxN
print(ans)

Solution (Python):
n = int(input())
s = input()
l = 0
r = n - 1
cnt = 0

while l<r:
    while s[l] == 'R' and l < r:
        l += 1
    while s[r] == 'W' and l < r:
        r -= 1
    if l>=r:
        break
    cnt += 1
    l += 1
    r -= 1

print(cnt)

Solution (Python):
n = int(input())
cl = str(input())
cl_R = cl.count("R")

cl_leftR = cl[:cl_R].count("R")

print(cl_R-cl_leftR)

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

def main():
    N = int(input())
    c = list(input())[:-1]
    
    w_count = 0
    r_count = 0
    for i in range(N):
        if c[i] == 'W':
            w_count += 1
        else:
            r_count += 1
        
        
    
    
    
    if w_count == N or r_count == N:
        print(0)
        exit(0)
    no_exchange = 0
    for i in range(r_count):
        if c[i] == 'R':
            no_exchange += 1
    
    print(r_count - no_exchange)

if __name__ == '__main__':
    main()

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

i, j = 0, n - 1
if c.count('W') == 0:
    count=0
elif c.count('R') == 0:
    count = 0
else:
    white_cnt = []
    red_cnt = []
    for i in range(n):
        if c[i] == 'W':
            white_cnt.append(i)
        else:
            red_cnt.append(i)
    while 1:
        white_num = white_cnt.pop(0)
        red_num = red_cnt.pop()
        if white_num < red_num:
            count += 1
        if len(white_cnt) == 0:
            break
        if len(red_cnt) == 0:
            break
print(count)