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 = input()
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex < backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

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

ans = 0
right = n-1
for i in range(n):
    if c[i] == "W":
        for j in range(right,-1,-1):
            if j <= i:
                print(ans)
                exit()
            if c[j] == "R":
                ans += 1
                right = j-1
                break
print(ans)

Solution (Python):

n = int(input())
c = input()
red = c.count('R')
print(c[:red].count('W'))

Solution (Python):
import re
import sys

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

count_r = 0
for i in c:
    if i == 'R':
        count_r += 1
count_w = n - count_r
ans = min(count_r, count_w)
if ans == 0:
    print(0)
    sys.exit()

pattern = r"^R*W*$"


l = 0
r = n-1
count = 0

while l < r:
    while c[l] == 'R':
        l += 1
    while c[r] =='W':
        r -= 1
    if l >= r:
        break
    c[l] = 'R'
    c[r] = 'W'
    count += 1
    
    

ans = min(count, ans)

print(ans)

Solution (Python):
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
c = S()


r = Counter(list(c))['R']
ans = 0
for elem in c[:r]:
    if elem == 'W':
        ans += 1
print(ans)

Solution (Python):
n = int(input())
c = input()
c = list(c)
r = 0
w = 0
for i in range(n):
    if c[i] == 'R':
        r += 1
    else:
        w += 1
ans = min(r,w)
t = 0
v = 0
for i in range(ans):
    if c[i] == 'R':
        t -= 1
for i in range(ans):
    if c[n-i-1] == 'W':
        v -= 1
if r <= w:
    ans = ans + t
else:
    ans = ans + v
print(ans)

Solution (Python):
n = int(input())
c = input()
c = list(c)
arr = []
a = 0
b = c.count('R')
arr.append(max(a, b))
for i in range(n):
  if c[i] == 'W':
    a += 1
  elif c[i] == 'R':
    b -= 1
  arr.append(max(a, b))
ans = min(arr)
print(ans)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

N = int(input())
c = "a" + input() + "a"

l = 0
r = len(c)-1

count = 0
while True:
    for i in range(1,N+5):
        if l+i == r:
            print(count)
            sys.exit()
        if c[l+i] == "W":
            break

    l = l + i

    for i in range(1,N+5):
        if l == r-i:
            print(count)
            sys.exit()
        if c[r-i] == "R":
            break

    r = r - i

    count += 1

Solution (Python):
N = int(input())
c = input()
a = c[0:len(c)//2]

if ("W" not in c) or ("R" not in c):
  print(0)
  exit()

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

Solution (Python):




from collections import Counter



def solve(n,s):
  flag = False
  d = Counter(s)
  whiteCount = d["W"]
  redCount   = d["R"]
  res = min(s[:redCount].count("W"),s[redCount:].count("R"))
  
  return res



def main():
  N = int(input())
  s = input()
  print(solve(N,s))
  return

if __name__ == '__main__':
  main()

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

numR = c.count('R')
print(0 if numR == 0 or numR == len(c) else c[:numR].count('W'))

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

n_R = c.count('R')

m_R = c[:n_R].count('R')

print(n_R - m_R)

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

l,r=len(S),S.count('R')
print(0 if r==0 or r==l else S[:r].count('W'))

Solution (Python):
import itertools
N = int(input())
S = input()
cnt = i = 0
j = N - 1
while True:
    while i < N and S[i] == 'R':
        i += 1
    while 0 <= j and S[j] == 'W':
        j -= 1
    if j < i:
        break
    cnt += 1
    i += 1
    j -= 1
print(cnt)

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

l = 0
r = N-1

while l < r:
    if s[l] == 'W' and s[r] == 'R':
        ans += 1
        l += 1
        r -= 1
    elif s[l] == 'W' and s[r] == 'W':
        r -= 1
    elif s[l] == 'R' and s[r] == 'R':
        l += 1
    else:
        l += 1
        r -= 1

print(ans)

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

w = c.count("W")
rr = c[-w:].count("R")

print(min(w,N-w,rr))

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

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

answer = total_count_R - left_count_R

print(answer)

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

dp = [0] * (N)

len_c_W = c.count('W')
len_c_R = c.count('R')
if (len_c_W == 0 or len_c_R == 0):
    print(0)
    exit()
cnt_W = 0
cnt_R = 0
for i in range(N):
    if c[i] == 'R':
        cnt_R += 1
    else:
        cnt_W += 1
    count = 0
    if (cnt_W <= (len_c_R - cnt_R)):
        count = len_c_R - cnt_R
    else:
        count = cnt_W

    dp[i] = count
print(min(dp))

Solution (Python):
'''
参考
https://qiita.com/tanakh/items/a312a9bd684658ab1e7b
'''
N = int(input())
C = list(map(str, input()))

left = 0
right = N - 1
ans = 0

while True:
    while left < N and C[left] != 'W':      
        left += 1
    while right >= 0 and C[right] != 'R':   
        right -= 1
    if left >= right:                       
        break
    ans += 1                                
    left += 1
    right -= 1

print(ans)

Solution (Python):



def main():
    n = int(input())
    c = input()
    r_count = c.count('R')
    ans = 0

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

    
    
    
    for ci in c:
        if ci == 'W':
            ans += 1

        r_count -= 1

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = int(input())
    c = input()
    r_count = c.count('R')
    ans = 0

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

    for ci in c:
        if ci == 'W':
            ans += 1

        r_count -= 1

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
c = input()
r = c.count('R')
ans = r - c[:r].count('R')
print(ans)

Solution (Python):
def main():
    n = int(input())
    cs = input()
    color_list = []
    for i in range(n):
        if cs[i] == "W":
            color_list.append(0)
        else:
            color_list.append(1)
    r_count = sum(color_list)
    ans = r_count - sum(color_list[:r_count])
    print(ans)


if __name__ == "__main__":
    main()

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

W=[]
R=[]

for a_idx,a in enumerate(A):
    if a == 'W':
        W.append(a_idx)
    else:
        R.append(a_idx)
        
W.sort()
R.sort(reverse=True)


ans=0
for n in range(min(len(W),len(R))):
    if W[n] > R[n]:
        break
    ans+=1
    
print(ans)

Solution (Python):


import sys
input=sys.stdin.readline

n=int(input())
s=input()
ws=s.count('W')
rs=s.count('R')
ans=min(ws,rs)
posw=[]
posr=[]
for i in range(n):
    if s[i]=='W':
        posw.append(i)
    else:
        posr.append(i)
posr=posr[::-1]
for i in range(min(len(posw),len(posr))):
    if posw[i]>posr[i]:
        ans=min(ans,i)
        break
print(ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]







n = I()
c = RS()



r = c.count('R')


ans = 0
for i in range(r):
    if c[i]=='W':
        ans += 1
    else:
        pass
print(ans)

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

i = 0
j = N-1
count = 0
while i < j:
    if c[i] == "W":
        if c[j] == "R":
            i += 1
            j -= 1
            count += 1
        else:
            j -= 1
    else:
        i += 1

print(count)

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

    w = c.count("W")

    ans = c[N - w: N].count("R")
    print(ans)


if __name__ == "__main__":
    main()

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

ans = 0

W_left = 0
R_right = 0
for i in range(n):
    if arr[i] == 'R':
        R_right += 1

ans = [max(W_left,R_right)]
for i in range(n):
    if arr[i] == 'W':
        W_left += 1
    elif arr[i] == 'R':
        R_right -= 1
    ans.append(max(W_left,R_right))
print(min(ans))

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

Solution (Python):
def main():
    N = int(input())
    S = input()
    
    r = S.count("R")
    ans = S[r:].count("R")
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Solution (Python):
N = int(input())
c = input()
C = []
for c_i in c:
    C.append(c_i)
count = 0
left = N-1
for i in range(N):
    if i >= left:
        print(count)
        break
    if C[i] == 'W':
        for j in reversed(range(left+1)):
            if i == 1:
                if j == i:
                    C[i] = 'R'
                    left = i
                    break
            else:
                if j == i-1:
                    left = i
                    break
            if C[j] == 'R':
                C[i] = 'R'
                C[j] = 'W'
                left = j
                count += 1
                break

Solution (Python):
N=int(input())
c=input()
t=c.count('R')
L=[[0,t]]
for i in range(N):
    if c[i]=='W':
        L.append([L[i][0]+1,L[i][1]])
    else:
        L.append([L[i][0],L[i][1]-1])
print(min([max(L[i]) for i in range(N+1)]))

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
C = read().rstrip().decode()

l, r = 0, N - 1
cost = 0
while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        
        cost += 1
        l += 1
        r -= 1

print(cost)

Solution (Python):
from sys import exit





(N,) = map(int, input().split())

C = list(input())


na = C.count("R")

ans = na - C[0:na].count("R")

print(ans)

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

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
s=input()
r=s.count("R")
w=0
c=r
for i in range(N):
    if s[i]=="R":
        r-=1
    else:
        w+=1
    if c>max(r,w): c=max(r,w)
print(c)

Solution (Python):
n = int(input())
s = input()
rs = s.count("R")
rs_ = s[:rs].count("R")
ans = min(rs, n-rs, rs-rs_)
print(ans)

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

Solution (Python):
N=int(input())
C=input()
R=0
for i in C:
    if i=="R":
        R+=1
D=C[:R]
count=0
for i in D:
    if i=="W":
        count+=1
print(count)

Solution (Python):
N=int(input())
C=input()
R=0
W=0
for i in C:
    if i=="R":
        R+=1
    else:
        W+=1
D=C[:R]
count=0
for i in D:
    if i=="W":
        count+=1
print(count)

Solution (Python):
n=int(input())
s=input()
w=s.count("W")
r=n-w
ans1 = r - s[:r].count("R")
ans2 = w - s[-w:].count("W")
print(min(ans1,ans2))

Solution (Python):

def resolve():
    N = int(input())
    S = input()
    cnt_R = S.count("R")

    cnt = 0
    for i in range(cnt_R):
        if S[i] == "R":
            cnt += 1
    print(cnt_R - cnt)

if __name__ == "__main__":
    resolve()

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

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

for ci in c:
    acc.append(acc[-1]+(1 if ci=='R' else 0))

ans = 10**18

for i in range(N+1):
    if i>=R:
        ans = min(ans, i-R+acc[N]-acc[i])
    else:
        ans = min(ans, R-i+i-acc[i])
    
print(ans)

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

d = list(c)

i = 0
j = n - 1
result = 0
while True:
    while i < n and d[i] != "W":
        i += 1
    while j > 0 and d[j] != "R":
        j -= 1
    if i == n or j == -1 or i >= j:
        break
    d[i] = "R"
    d[j] = "W"
    result += 1
print(result)

Solution (Python):








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

r_cnt = c.count("R")

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

Solution (Python):



n = input()
s = input()
print(s[:s.count('R')].count('W'))

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

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

Solution (Python):
import collections

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

count = collections.Counter(s)
ans = 0

if "R" in count.keys():
    if count["R"] != n:
        r_count = collections.Counter(s[:count["R"]])
        if r_count["R"] == 0:
            ans = count["R"]
        else:
            ans = r_count["W"]

print(ans)

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

R=c.count("R")

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

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

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

Rcount = 0
Wcount = 0
for i in range(len(c)):
    if c[i] == 'R':
        Rcount += 1
for i in range(Rcount):
    if c[i] == 'W':
        Wcount += 1

print(Wcount)

Solution (Python):
N=int(input())
c=input()
W=[]
R=[]
pw=0
pr=0
for i in range(N):
  if c[i]=="W":
    W+=[i]
    pw+=1

  if c[N-1-i]=="R":
    R+=[i]
    pr+=1

for i in range(200000):
    if min(len(W),len(R))==i:
        result=i
        break
    if W[i]+R[i]>=N:
        result=i
        break
print(result)
result=i

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

cnt =  0
R = C.count('R')

for i in range(R):
    if C[i] == 'R':
        cnt += 1
print(R - cnt)

Solution (Python):

"""
RWとなってなければおｋ
WRはだめ
"""


def main():
    import sys

    input = sys.stdin.readline

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

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


if __name__ == '__main__':
    main()

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

rn = l.count('R')
wn = l.count('W')
ans = rn - (l[:rn].count('R'))
print(ans)

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

nr = s.count("R")
nw = s.count("W")

nwc = s[:nr].count("W")
nrc = s[nr:].count("R")

print(max(nwc,nrc))

Solution (Python):
l = []
n = int(input())
r = 0
for i in [1 if x == 'R' else 0 for x in list(input())]:
    r += i
    l.append(r)

c = r - l[r-1]
print(c)

Solution (Python):
N=int(input())
c=input()
S=[0 for i in range(N+1)]
for i in range(N):
    if c[i]=="R":
        S[i+1]=S[i]+1
    else:
        S[i+1]=S[i]
ans=N
for i in range(N+1):
    ans=min(ans,max(i-S[i],S[N]-S[i]))
print(ans)

Solution (Python):



def solve(ls):
    n = len(ls)
    num_w = len([x for x in ls if x == "W"])
    num_r = n - num_w
    left_w = 0
    right_r = num_r
    result = num_r
    for i in range(n):
        if ls[i] == 'W':
            left_w += 1
        else:
            right_r -= 1
        result = min(result, max(left_w, right_r))
    return result


def main(istr, ostr):
    (n,) = list(map(int, istr.readline().strip().split()))
    s = istr.readline().strip()
    result = solve(s)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

Solution (Python):
from collections import Counter
n=int(input())
c=input()
d=Counter(c)
w,r=Counter(c)["W"], Counter(c)["R"]
ans=0
for i in range(r):
  if c[i]=="W":
    ans+=1

print(ans)

Solution (Python):
N= int(input())
C = input()
red = 0
white = 0
for i in range(N):
    if C[i] == "W":
        white +=1
    else:
        red += 1
c = 0
for i in range(red):
    if C[i] == "W":
        c +=1
print(c)

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

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

print(min([w[i]+r[i]-min(w[i],r[i]) for i in range(0,n+1)]))

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

if 'R' in c and 'W' in c:
  R = int(c.count('R'))
  c[0:R] = []
  print(c.count('R'))
else:
  print(0)

Solution (Python):
n=int(input())
c=list(input())
import collections
p=collections.Counter(c)
last=["R"]*p["R"]+["W"]*p["W"]
ans=0
for i in range(n):
    if c[i]!=last[i]:
        ans+=1
print(ans//2)

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

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

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

print(ans)

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

Nw, Nr = 0, 0
for i in range(len(c)):
    Nw += 1 if c[i] == "W" else 0
    Nr += 1 if c[i] == "R" else 0

if Nw == 0 or Nr == 0:
    print(0)
    exit()

left_w = 0
right_r = 0
if c[0] == "W":
    left_w = 1
    right_r = Nr
else:
    left_w = 0
    right_r = Nr - 1


ans = max(left_w, right_r)

for i in range(len(c)):
    if i > 0:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1
    swap = max(left_w, right_r)
    ans = min(swap, ans)
print(ans)

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

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'
    
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()




def dijkstra(edge,st):
    
    
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        
        
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


n=I()
s=input()
r,w=[],[]
for i in range(n):
    if s[i]=='R':
        r+=i,
    else:
        w+=i,
w=w[::-1]

ans=0
while w and r:
    c=w.pop()
    if c>r[-1]:
        break
    r.pop()
    ans+=1

print(ans)

Solution (Python):
N = int(input())
l = input()
Wonleft = 0
Ronright = l.count('R')
ans = Ronright
for i in range(N):
    if l[i] == 'W':
        Wonleft += 1
    else:
        Ronright -= 1
    t = max(Wonleft, Ronright)
    if ans > t:
        ans = t
print(ans)

Solution (Python):
n = int(input())
s = input()
a = 0
b = 0
for c in s:
    if c == "R": a += 1
ans = max(a,b)
for i in range(n):
    if s[i] == "R": a -= 1
    else: b += 1
    ans = min(ans, max(a, b))
print(ans)

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

cnt = 0

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

min_operation = max(W, R)

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

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

    min_operation = min(min_operation, max(W, R))
    if min_operation == 0:
        print(0)
        exit()

print(min_operation)

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

ans = 0
r = N - 1
for l in range(N):
    if C[l] == 'R':
        continue
    r = max(l, r)
    while r > l and C[r] == 'W':
        r -= 1
    if r <= l:
        break
    C[l], C[r] = C[r], C[l]
    ans += 1

print(ans)

Solution (Python):
from collections import Counter


N = int(input())
C = input()
C_cntr = Counter(C)

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

print(ans)

Solution (Python):



import sys
n = int(input())
word = input()
res = 0
num_r = 0

for charactor in word:
    if charactor == 'R':
        num_r += 1

num_w = 0
for i in range(num_r):
    if word[i] == 'W':
        num_w += 1

print(num_w)

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

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

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

    left, right = 0, N - 1
    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while right >= 0 and C[right] == 'W':
            right -= 1

        if left >= right:
            break
        left += 1
        right -= 1
        ans += 1
    return ans

print(d_alter_altar_2())

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

Solution (Python):
import sys
N = int(input())
c = list(input())
n = 0
k = N - 1
for i in range(N):
    if c[i] == 'W':
        for j in range(k, i, -1):
            if c[j] == 'R':
                n += 1
                c[i] = 'R'
                c[j] = 'W'
                k = j - 1
                break
            if j == i + 1:
                print(n)
                sys.exit()
print(n)

Solution (Python):
n = int(input())
c = input()
a = 0
b = 0
for i in range(n):
    if c[i] == 'R':
        a+=1
ans = max(a, b)
for i in range(n):
    if c[i] == 'R':
        a-=1
    else:
        b+=1
    now = max(a, b)
    ans = min(ans, now)
print(ans)

Solution (Python):
n=int(input())
c=list(input())
 
rj=c.count('R')
wj=0
mini=rj
for i in range(n):
  if c[i]=='R':
    rj-=1
  else:
    wj+=1
  mini=min(mini,max(rj,wj))
  
print(mini)

Solution (Python):
n = int(input())
mozi = input()
a_list = []
for i in range(n):
    if mozi[i] == 'W':
        a_list.append(0)
    else:
        a_list.append(1)
r_count = sum(a_list)
print(r_count - sum(a_list[0:r_count]))

Solution (Python):
n = int(input())
c = list(input())
r = c.count('R')
r_li = c[r:]
ans = r_li.count('R') 
print(ans)

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

a, b = 0, 0

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

ans = max(a, b)

for i in range(n):
    if c[i] == 'R':
        a -= 1
    else:
        b += 1
    now = max(a, b)
    ans = min(now, ans)

print(ans)

Solution (Python):
n = int(input())
c = input()
lists = list(c)
cnt = 0

for i in range(len(lists)):
    if lists[i] == "R":
        cnt += 1
change = 0
for i in range(cnt):
    if lists[i] == "W":
        change += 1
print(change)

Solution (Python):



import collections



def solve(c):
    counts = collections.Counter(c)
    if counts['R'] == 0 or counts['W'] == 0:
        return 0

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

    return inversions


def main():
    _ = int(input().rstrip())
    c = input().rstrip()
    a = solve(c)
    print(a)

if __name__ == '__main__':
    main()

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

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

l_w = [0 for i in range(n+1)]
r_r = [0 for i in range(n+1)]

for i in range(n):
    l_w[i+1] = l_w[i]
    if c[i] == 'W':
        l_w[i+1] += 1
for i in range(n, 0, -1):
    r_r[i-1] = r_r[i]
    if c[i-1] == 'R':
        r_r[i-1] += 1

ans = int(1e9)

for i in range(n+1):
    ans = min(ans, max(l_w[i], r_r[i]))

print(ans)

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

n = input()
s = input()

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

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

S=0
T=N-1

t=0
while S<T:
  if C[S]=='R' and C[T]=='R':
    S+=1
  elif C[S]=='R' and C[T]=='W':
    S+=1
    T-=1
  elif C[S]=='W' and C[T]=='R':
    S+=1
    T-=1
    t+=1
  else:
    T-=1

print (t)

Solution (Python):
n = int(input())
ls = list(input())
r = ls.count('R')
w = ls.count('W')
if r == 0 or w == 0:
    print(0)
else:
    r_in_half = ls[:r].count('R')
    ans = r - r_in_half
    print(ans)