peterverebics/CodeNet_Python_118 huggingface dataset:
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"))
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)
N=int(input())
c=list(input())
x=0
M=N
for i in range(N):
  if c[i]=="W":
    for j in range(N):
      if i==M-1-j:
        M=i
        break
      elif c[M-1-j]=="R":
        x+=1
        c[M-1-j]="W"
        M=M-j
        break
  if i==M:
    break
print(x)
def f(c):
    return 1*(c=="R")

N=int(input())
C=list(map(f,input()))

R=C.count(1)
S=C[:R].count(0)
print(S)
# coding: utf-8
n = int (input())
s=list(input())

w_count = 0
r_count = 0

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

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

ans_count = 0
for i in range(n):
    if (s[i] != target[i]):
        ans_count+=1
print (int(ans_count / 2))
import sys
import math
sys.setrecursionlimit(500000)
INF = float('inf')

def main():
    n = int(input())
    c = input()
    red_stones = c.count('R')
    return c[red_stones:].count('R')

if __name__ == '__main__':
    print(main())
n = int(input())
s = input()

siro = s.count('W')
aka = n - siro
ans = 0
for i in range(aka, n):
    if s[i] == 'R':
        ans += 1
print(ans)
import sys
read = sys.stdin.read
def main():
    n = int(input())
    a = input()
    if not 'WR' in a:
        print(0)
        sys.exit()
    a = list(a)
    rnum = a.count('R')
    r = 0
    for i1 in range(rnum):
        r += a[i1] == 'W'
    for j1 in range(n - rnum):
        r += a[rnum + j1] == 'R'
    r = r // 2
    print(r)
if __name__ == '__main__':
    main()
N = int(input())
s = input()
r = s.count("R")
print(s[:r].count("W"))
N = int(input())
C = input()
c = []
for i in C:
    c.append(i)

a = c.count("R")

count = 0
for b in c[0:a]:
    if b == "R":
        count += 1


print(a - count)
N = int(input())
A = str(input())
Wsum = 0
Wright = 0
for i in range(N):
    if A[i] == "W":
        Wsum += 1
for i in range(N - Wsum):
    if A[i] == "W":
        Wright += 1
print(Wright)
import collections

c=input()
c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]:
            ans+=1
            dis_r+=1
        else:
            ans+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)
def main():
    n = int(input())
    s = input()
    r = s.count("R")
    cnt = 0
    for i in range(n-1, r-1, -1):
        if s[i] == "R":
            cnt += 1
    print(cnt)


main()
N = int(input())
c = list(input())
Wnum = c.count("W")
if Wnum == 0 or Wnum == N:
    print(0)
else:
    F = "R" * (N - Wnum) + "W" * Wnum
    t = 0
    for i in range(N):
        if c[i] != F[i]:
            t += 1
    print(t//2 + t%2)
N = int(input())
c = list(input())

l = 0
r = N - 1
ans = 0
while True:
    while l < N and c[l] == 'R':
        l += 1
    while r >= 0 and c[r] == 'W':
        r -= 1
    if r < l:
        break
    c[r], c[l] = c[l], c[r]
    ans += 1

print(ans)
"""
4
WWRR
2
"""
import itertools

n = int(input())
s = list(input())
left_w = [0]
right_r = [0]
for l in s:
    if l == "W":
        left_w.append(1)
    else:
        left_w.append(0)
lacc = list(itertools.accumulate(left_w))
for r in s[::-1]:
    if r == "R":
        right_r.append(1)
    else:
        right_r.append(0)
racc = list(itertools.accumulate(right_r))
racc = racc[::-1]
print(min(map(max, zip(lacc, racc))))
n = int(input())
S = [c for c in input()]
ans = 0
i = 0
j = n-1
while i < j:
    if S[i] == "W":
        if S[j] == "R":
            S[i] = "R"
            S[j] = "W"
            j -= 1
            i += 1
            ans += 1
        else:
            j -= 1
    else:
        i += 1
print(ans)
def main():
    n = int(input())
    s = input()
    ans = 0
    L, R = 0, n-1
    while L < R:
        if s[L] != "W":
            L += 1
        elif s[R] != "R":
            R -= 1
        else:
            ans += 1
            L += 1
            R -= 1
    print(ans)

if __name__ == "__main__":
    main()
N = int(input())
c = input()
ans = [-1] * (N+1)

for i in range(0, N+1):
  if i == 0:
    l = c[:i]
    r = c[i:]
    W = l.count("W")
    R = r.count("R")
  else:
    if (c[i-1]) == "W":
      W += 1
    elif (c[i-1]) == "R":
      R -= 1

  ans[i] = max(R, W)
      
print(min(ans))
n=int(input())
c=input()
s=0
t=n-1
ans=0
while s<t and s<n and t>=0:
    while c[s]=='R':
        s+=1
        if not s<n:
            break
    while c[t]=='W':
        t-=1
        if not t>=0:
            break
    if s<t:
        ans+=1
        s+=1
        t-=1
    else:
        break
print(ans)
n = int(input())
# cs = ['W' for i in range(200000)]
cs = input()

w_count = 0
for c in cs:
    if c == 'W':
        w_count += 1

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

rest = cs[-w_count:]

answer = 0
for c in rest:
    if c == 'R':
        answer += 1
print(answer)
N = int(input())
c = input()
ans = 0

i = 0
j = N-1
while i < j:
    while True:
        # print(1, i, j)
        if i == j:
            break
        if c[i] == 'W':
            break
        i += 1
    while True:
        # print(2, i, j)
        if i == j:
            break
        if c[j] == 'R':
            ans += 1
            break
        j -= 1
    i += 1
    j -= 1
print(ans)
n = int(input())
c = input()
cls = list(c)

rcnt = cls.count('R')

wcnt = cls[:rcnt].count('W')

print(wcnt)
N = int(input())
s = input()
fir = True
f = 0
b = len(s)-1
count = 0
while(b > f):
    if(s[f] == "R"):
        f += 1
        continue
    elif(s[b] == "R"):
        count += 1
        f += 1
        b -= 1
        continue
    elif(s[b] == "W"):
        b -= 1
print(count)
N = int(input())
c = input()
red = 0
for i in c:
    if i  == "R": red += 1
ans = 0
for i in c[red:]:
    if i == "R": ans += 1
print(ans)
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)
n = int(input())
c = input()

rcnt = 0
for i in range(n):
    if c[i] == 'R':
        rcnt += 1
ans = 0
for i in range(rcnt):
    if c[i] == 'W':
        ans += 1
print(ans)
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:
        # print(l, r)
        if l-1 == r:
            ans += 1
            break
        else:
            l += 1
            r -= 1
            ans += 1

print(ans)
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)
N = int(input())
C = input()
R = C.count("R")
ans = 0
for i in range(R):
    if C[i] == "W":
        ans += 1
print(ans)
n = int(input())
c = input()


cnt = 0
for i in range(n):
  w_idx = c.find("W")
  r_idx = c.rfind("R")
  if w_idx < r_idx and w_idx != -1:
    c = c[w_idx+1:r_idx]
    cnt += 1

print(cnt)
N = input()
c = input()

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

print(W_count)
N = int(input())
c = list(input())
li = 0

import sys
if "R" not in c or "W" not in c:
    print (0)
    sys.exit()
    
ans = 0
for i in range(N-1,-1,-1):

    if c[i] == "R":
        while c[li] != "W" and li <= i:
            li += 1
        if li >= i:
            break
        c[i] = "W"
        c[li] = "R"
        ans += 1
print (ans)
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)
n = int(input())
s = input()

l = 0
r = n-1
ans = 0
while(True):
    while(s[l]=='R' and l<n-1):
        l+=1
    while(s[r]=='W' and 0<r):
        r-=1
    if l < r:
        ans += 1
        l += 1
        r -= 1
    else:
        break

print(ans)
N = int(input())
C=list(input())
W=(C.count('W'))
R=N-W
WW=0
RR=0
X=[0]*(N-1)
if W>0 and R>0:
  for i in range(N-1):
    if C[i]=='W':
      WW+=1
    RR=(N-i-1)-(W-WW)
    X[i]=max(WW,RR)
print(min(X))
n = int(input())
c = list(input())
sc = sorted(c)

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

    W_in_R = 0

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

    R_in_W = 0

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

    print(max(W_in_R , R_in_W))
N = int(input())
C = [c == "R" for c in input()]
count_red = C.count(True)
print(C[:count_red].count(False))
#abc174d
n=int(input())
c=input()
r=c.count('R')
x=c[:r]
print(x.count('W'))
n = int(input())
s = input()
red = 0
white = 0
for x in s:
    if x=='R':
        red += 1
    else:
        white += 1
reqr = 0
for i in range(red):
    if s[i]=='W':
        reqr += 1
print(reqr)
def alter_altar(s):
    tmp = 'R' * s.count('R') + 'W' * s.count('W')
    ans = 0
    for i in range(len(s)):
        if s[i] == tmp[i]:
            pass
        else:
            ans += 1
    return ans//2
if __name__ == "__main__":
    _ = input()
    s = input()
    print(alter_altar(s))
n = int(input())
c = list(input())
r = c.count('R')
r_li = c[r:]
ans = r_li.count('R') 
print(ans)
n = int(input())
c = input()
l_c = len(c)
r = 0
ans = 0

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

for i in range(r,l_c):
    if c[i] == 'R':
        ans += 1

print(ans)
n=int(input())
s=input()
l=[0]
for i in range(n):
    l.append(l[i]+(s[i]=="R"))
ans=n
#print(l)
for i in range(n+1):
    ans=min(ans,abs(l[i]-i)+abs(l[-1]-l[i]))
    #print(ans,i)
    if i==l[-1]:
        ans=min(ans,abs(l[i]-i))
        #print(ans)
print(ans)
from collections import deque
n=int(input())
c=input()
r=deque()
lr=0
for i in range(n):
    if c[i]=="R":
        lr+=1
        r.append(i)
ans=0
for i in range(n):
    if lr==0:
        break
    if c[i]=="W":
        if i<r[-1]:
            ans+=1
            r.pop()
            lr-=1
        else:
            break

print(ans)
n = int(input())
s = input()
red = []
white = []
for i in range(n):
  if s[i] == 'W':
    white.append(i)
for i in range(n - 1, -1, -1):
  if s[i] == 'R':
    red.append(i)
#print(white, red)
if min(len(red), len(white)) == 0:
  print(0)
  exit()

for i in range(min(len(red), len(white))):
  if white[i] >= red[i]:
    print(i)
    exit()
print(min(len(red), len(white)))
N = int(input())
C = input()

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

print(ans)
import numpy as np
N = int(input())
S = input()
R_count=0
w_count=0
for i in S:
  if(i=="R"):
    R_count+=1


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

print(w_count)
N = int(input())
c = list(input())
r_num = c.count("R")
ref = c[:r_num]
w_num = ref.count("R")
print(r_num - w_num)
n = int(input())

s = list(input())

w = s.count("R")
#print(w)
x = s[:w].count("R")
#print(x)

print(w-x)
N = int(input())
C = input()

left = 0
right = N -1

ans = 0
while left < right:
    if C[left] == 'W' and C[right] == 'R':
        left += 1
        right -= 1
        ans += 1
    elif C[left] == 'W':
        right -= 1
    elif C[left] == 'R':
        left += 1
print(ans)
# -*- coding: utf-8 -*-
n=int(input())
c=str(input())
r=c.count('R')
if r==0:
  print(r)
else:
  cp=c[0:r]
  k=cp.count('R')
  print(r-k)
n = int(input())
c = input()

l = 0
r = n - 1

ans = 0
while l < r:
    while c[l] != "W" and l + 1 < n:
        l += 1

    while c[r] != "R" and r - 1 >= 0:
        r -= 1

    if l < r:
        ans += 1
        l += 1
        r -= 1

print(ans)
n=int(input())
c=input()

cw=c.count('W')
cr=c.count('R')

ans_s='R'*cr+'W'*cw

cnt=0
for i in range(n):
  if c[i]!=ans_s[i]:
    cnt+=1

print((cnt+2-1)//2)
N = int(input())
c = list(input())

cnt = 0
w_last_index = N-1
for i in range(N):
  if c[i] == 'W':
    flag = True
    for j in range(w_last_index,i,-1):
      if c[j] == 'R':
        c[j] = 'W'
        w_last_index=j
        cnt+=1
        flag = False
        break
    if flag:
      break
print(cnt)
n = int(input())
c = input()
strings = "R"*c.count("R") + "W"*c.count("W")
ans = 0
for a,b in zip(strings,c):
    if a != b: ans += 1
print(ans//2)
n = int(input())
c_list = list(input())
start = 0
end = n
ans = 0

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

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

print(ans)
n=int(input(""))
lis=input("")
rt=0
for i in lis:
    if(i=="R"):
        rt+=1
ht=n-rt
r=0
h=0

s=max(h,rt)

for i in lis:
    if(i=="R"):
        r+=1
    else:
        h+=1
    on=rt-r
    m=max(on,h)
    if(s>m):
        s=m

print(s)
N = int(input())
S = input()

cumw = [0]
for c in S:
    cumw.append(cumw[-1] + int(c=='W'))

cumr = [0]
for c in S[::-1]:
    cumr.append(cumr[-1] + int(c=='R'))
cumr.reverse()

ans = N
for a,b in zip(cumw,cumr):
    ans = min(ans, max(a,b))
print(ans)
N=int(input())
d=input()
r=d.count('R')
w=N-r
ans=r
leftr,leftw,rightr,rightw=0,0,r,N-r
for i in range(N):
  if d[i]=='R':
    leftr+=1
    rightr-=1
  else:
    leftw+=1
    rightw-=1
  if leftw==rightr:
    f=rightr
  elif leftw<rightr:
    f=rightr
  else:
    f=leftw
  ans=min(ans,f)
print(ans)
N = int(input())
c = list(input())

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

while l < r:
    L, R = c[l], c[r]
    if L == 'W' and R == 'R':
        c[l], c[r] = 'R', 'W'
        l += 1
        r -= 1
        cnt += 1
    elif L == 'W' and R == 'W':
        r -= 1
    elif R == 'R' and R == 'R':
        l += 1
    else:
        l += 1
        r -= 1

print(cnt)
import sys
N=int(sys.stdin.readline().strip())
C=sys.stdin.readline().strip()
L=[0]
R=[0]
for c in C:
    if c=="W":
        L.append(L[-1]+1)
    else:
        L.append(L[-1])

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

ans=float("inf")
for i in range(N+1):
    ans=min(ans,max(L[i],R[i]))
print ans
import sys
input=sys.stdin.readline

n=int(input())
c=input().rstrip()

l=0
r=n-1
ans=0
while True:
    while c[l]=='R':
        l+=1
        if l==n:
            break
    while c[r]=='W':
        r-=1
        if r==-1:
            break
    if l>r:
        break
    ans+=1
    l+=1
    r-=1

temp=0
for i in c:
    if i=='R':
        temp+=1
temp=min(temp,n-temp)
ans=min(ans,temp)
print(ans)
N = int(input())
*C, = input()

nw = C.count('W')

ans = 0
for _ in range(N):
    if nw == 0:
        break
    tmp = C.pop()
    if tmp == 'W':
        nw -= 1
    else:
        ans += 1
        nw -= 1
print(ans)
def main():
  n = int(input())
  s =  str(input())
  num_r = 0
  for i in range(n):
    if s[i] == "R":
      num_r += 1
  ans = 0
  for i in range(num_r):
    if s[i] == "W":
      ans += 1
  print(ans)

if __name__ == "__main__":
  main()
n = int(input())
s = list(input())
j = 1
count = 0
for i in range(n):
    if s[i] == 'R':
        continue
    else:
        while 1:
            if j + i >= n:
                break
            elif s[-j] == 'R':
                s[i] = 'R'
                s[-j] = 'W'
                count += 1
                break
            j += 1
print(count)
N = int(input())
C = input()

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

r = c.count('R')
print(c[:r].count('W'))
N = int(input())
C = input()

def solve():
    red = C.count('R')
    white = C[:red].count('W')
    return white

if __name__ == "__main__":
    print(solve())
N = int(input())
C = input()

R, W = [], []
R_ = []
nR, nW = 0, 0
for c in C:
    if c == 'R':
        nR += 1
    else:
        nW += 1
    R.append(nR)
    W.append(nW)

if nR == 0 or nW == 0:
    print(0)
    exit()

for r in R:
    R_.append(nR - r)

ans = N

for i in range(N):
    r, w, r_ = R[i], W[i], R_[i]
    if r_ > w:
        ans = min(r_, ans)
    else:
        ans = min(w, ans)
print(ans)
def main():
    N = int(input())
    c = input()

    r_count = 0
    w_count = 0

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

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

    print(ans)


if __name__ == "__main__":
    main()
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)
from collections import Counter

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

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

ans = 0
for a, b in zip(S, S_target):
    if b == 'W':
        break
    if a != b:
        ans += 1
print(ans)
N = int(input())
C = input()
cnt = 0
left = 0
right = N-1
while(left < right and left<=N-1):
  if(C[left] == 'W'):
    flag = 0
    while(left < right):
      if(C[right] == 'R'):
        cnt += 1
        right -= 1
        break
      right -= 1
  left += 1
print(cnt)
#from functools import lru_cache
import sys

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

ls = reader()
n = int(ls[0][0])
wr =ls[1][0]
nr = len(list(filter(lambda a:a=='R',wr)))
nleftr = len(list(filter(lambda a:a=='R',wr[:nr])))
print(nr-nleftr)
N = int(input())
C = input()

i = 0
j = N-1
ans = 0
while True:
    while i<N and C[i] != "W":
        i += 1
    while j>=0 and C[j] !="R":
        j -= 1
    if i>=j:
        break
    ans += 1
    i += 1
    j -= 1

print(ans)
def main():
    n=int(input())
    c=input()
    cc=sorted(c)
    count = 0
    for i in range(n):
        if c[i] != cc[i]:
            count += 1
    print(count//2)

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


def main():
    n = int(input())
    c = list(input())
    wcnt = c.count("W")
    rcnt = c.count("R")
    if wcnt == 0 or rcnt == 0:
        print(0)
        return
    ans = c[0:rcnt].count("W")
    print(ans)


if __name__ == '__main__':
    main()
input()
s = input()
pref = 0
total = s.count('R')
res = int(1e9)
for i in range(total):
    pref += s[i] == 'R'
    res = min(res, total - pref)
print(res if total != len(s) and total != 0 else 0)
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)
N = int(input())
C = input()
White = C.count("W")
Red = C.count("R")
left_white = 0
left_red = 0
right_white = White
right_red = Red
ans = Red
for n,c in enumerate(C):
    if c == "W":
        left_white += 1
        right_white -= 1
    else:
        left_red += 1
        right_red -= 1
    ans = min(ans,max(left_white,right_red))
print(ans)
n = int(input())
c = input()
r = c.count('R')
w = c.count('W')
print(c[:r].count('W'))
N=int(input())
c=list(input())

W_cnt=c.count("W")
R_cnt=c.count("R")

wcnt=0
rcnt=0
for n in range(R_cnt):
    if c[n]=="W":
        wcnt+=1
for n in range(R_cnt+1,N):
    if c[n]=="R":
        rcnt+=1
print(max(wcnt,rcnt))
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)
n = int(input())
x = list(input())

sx = len(set(x))
if sx == 1:
    print(0)
    exit()

cnt_r = x.count("R")
cnt = 0
for i in range(cnt_r):
    if x[i] == "W":
        cnt += 1
print(cnt)
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)
N=int(input())
c=input()
left=0
right=N-1
ans=0
if all(c[i]=='R' for i in range(N)):
    print('0')
    exit()
if all(c[i]=='W'for i in range(N)):
    print('0')
    exit()
while left<right:
    if c[left]=='R':#これより左に白石なし
        left+=1
    if c[right]=='W':#これより右に赤石なし
        right-=1
    if c[left]=='W' and c[right]=='R':
        left+=1
        right-=1
        ans+=1
print(ans)
N = int(input())
c = list(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)
N = int(input())
S = input()

r, w = 0, 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    else:
        w += 1

res = [0 for _ in range(N+1)]
for i in range(1, N+1):
    if S[i-1] == 'R':
        res[i] = res[i-1] + 1
    else:
        res[i] = res[i-1]

print(r-res[r])
def main():
    import collections

    N = int(input())
    stones = input()

    N_red = stones.count('R')
    N_whi = N - N_red

    ans = stones[:N_red].count('W')

    print(ans)


if __name__ == '__main__':
    main()
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W")
list_w = mozi2[(a-num_w+1):]
list_r = mozi2[:(a-num_w+1)]
if "W" in list_w:
    print(list_r.count("W"))
else:
    print(num_w)
n=int(input())
s=input()

cntw=[0]*(n+1)
totr=0
totw=0

for i in range(n):
    if s[i]=='W':
        cntw[i+1]=cntw[i]+1
        totr+=1
    else:
        cntw[i+1]=cntw[i]
        totw+=1
ans=10**6
for i in range(n):
    w=cntw[i]
    r=n-i-(totw-cntw[i])
    ans=min(ans,max(w,r))

print(ans)
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[-1] == 'W':
            c = c[:-1]
        while c[0] == 'R':
            c = c[1:]
        if (c.index('R') == len(c) - 1):
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

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

print(checkFunction(c))
N=int(input())
S=input()
l,r=0,N-1
ans=0
f=0
while l<r:
  while S[l]=='R':
    l+=1
    if l==N:
      f=1
      break
  while S[r]=='W':
    r-=1
    if r==-1:
      f=1
      break
  if f==1:
    break
  ans+=1
  l,r=l+1,r-1
print(ans)
i=int(input())
s=list(input())
fw,fr=0,0
count=0

if s[0]=="W" and s[i-1]=="R":
    count+=1
    s[0]="R"
    s[i-1]="W"
if s[i-1]=="R":
    count+=1
    s[i-1]="W"
for j in range (i):
    if s[j]=="W" :
        fw=j 
        break
    
print (s)
for j in range (fw,i):
    if s[j]=="R":
        count+=1
print(count)
N = int(input())
c = input()
ans = 0
fs = 0
ls = N - 1
for _ in range(N):
    for i, ci in enumerate(c[fs:ls]):
        if ci == 'W':
            break
        fs += 1
    for i , ci in enumerate(c[fs:ls:-1]):
        if ci == 'R':
            break
        ls -= 1
    if fs == ls:
        break
    ans += 1
    fs += 1
    ls -= 1
    #print(c[fs:ls] + 1)
    if len(c[fs:ls + 1]) <= 1:
        break
print(ans)
k = int(input())
cs = input()
print(cs[:len(cs)//2].count("W"))
n = int(input())
c = input()
count = 0

while "WR" in c:
    c = c.replace("W", "R", 1)
    c = c.replace("WR", "WW", 1)
    count += 1
print(count)
# D Alter Altar

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

num_R = C.count("R")

if len(C) == num_R or num_R == 0:
  print(0)
  exit()

space = 0
for c in C:
  if c == "W":
    space += 1
  elif c == "R":
    break

if num_R <= space:
  print(num_R)
else:
  print(num_R - 1)