peterverebics/CodeNet_Python_118 huggingface dataset:
n = int(input())
c = input()

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

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

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

print(r - r_s)
from collections import Counter

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

c = Counter(C)

numR = 0

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

print(c['R']-numR)
def main():
    N = int(input())
    C = input()
    l, r = 0, N - 1
    c = 0
    while True:
        while l < r and C[l] == 'R':
            l += 1
        while l < r and C[r] == 'W':
            r -= 1
        if l >= r:
            break
        c += 1
        l += 1
        r -= 1

    return c

print(main())
n = int(input())
k =  input()
stone = list(k)
w = 0
r = 0
for i in range(n):
    if stone[i] == 'R':
        r += 1
    else:
        w += 1

ans = 0
w_s = 0
r_s = 0
for i in range(n):
    if i <= r-1 and stone[i] ==  'W':
        w_s += 1
    elif i > r-1 and stone[i] == 'R':
        r_s += 1
ans = max(w_s, r_s)
print(ans)
N = int(input())
C = list(input())
RtoW = sum(map(lambda x: x=="R",C))
WtoR = 0
ans = RtoW
for i in range(N):
    if C[i] == "R":
        RtoW -= 1
    else:
        WtoR += 1
    ans = min(ans,max(RtoW,WtoR))

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


sum_r, sum_w = [0], [0]
s1, s2 = 0, 0
for v in c:
    if v == 'R':
        s1 += 1
    else:
        s2 += 1
    sum_r.append(s1)
    sum_w.append(s2)

res = float('inf')
for i in range(n+1):
    res = min(res, max(sum_w[i], s1 - sum_r[i]))

print(res)
n=input()
c=input()
print(c[:c.count("R")].count("W"))
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)
N=int(input())
c=list(input())
cnt=0
res=10**30
rcum=[0]*(N+1)
wcum=[0]*(N+1)
for i in range(N):
    rcum[i+1]=rcum[i]+(c[i]=='R')
    wcum[i+1]=wcum[i]+(c[i]=='W')
for i in range(N+1):
    a=wcum[i]+(rcum[N]-rcum[i])
    res=min(res,a)
for i in range(N+1):
    b=max(wcum[i],(rcum[N]-rcum[i]))
    res=min(res,b)
    

print(res)
n = int(input())
a = list(input())
#print(a)
w = a.count("W")
r = a.count("R")
aa = a[:r]
#print(aa)
r2 = aa.count("R")
print(r-r2)
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)]))
n = int(input())
c = list(input())
d = sorted(c)
count = 0
for i in range(n):
    if c[i] == 'W' and d[i] == 'R':
        count+=1
print(count)
n=int(input())
c=input()
c1=c.count("R")
c2=c[:c1].count("W")
print(c2)
n = int(input())
string = input()
Rcount = string.count('R')
fixRcount = string.count('R', Rcount, n)
print(fixRcount)
n = int(input())
C = input()
len_r, len_w = 0, 0
for c in C:
    if c == 'R':
        len_r += 1
    else:
        len_w += 1
c2 = 'R'*len_r + 'W'*len_w
cnt = 0
for a, b in zip(C, c2):
    if a != b:
        cnt += 1
print(cnt//2)
N = int(input())
C = input()

W = 0                  #仕切りより左側の白い石の個数
R = C.count('R')       #仕切りより右側の赤い石の個数

ans = max(W, R)

for i in range(N):
    if C[i] == 'W':    #仕切りの左側に'W'が移動する
        W += 1
    else:              #仕切りの左側に'R'が移動する
        R -= 1
    ans = min(ans, max(W, R))

print(ans)
import sys
input = sys.stdin.readline
N = int(input())
c = input()

nR = c.count('R')
#nW = c.count('W')

lnR = c[:nR].count('R')
#lnW = c[:nW].count('W')

print(nR-lnR)
N = int(input())
c = input()
l = 0
r = N-1
cnt = 0
while(l<r):
    if c[l] == "W" and c[r] == "R":
        cnt += 1
        l += 1
        r -= 1
    elif c[l] == "R":
        l += 1
    elif c[r] == "W":
        r -= 1
print(cnt)
N = int(input())
c = list(input())
from collections import Counter
dic = Counter(c)
left = c[:dic["R"]]
print(left.count("W"))
N = int(input())
S = input()
ans = 0
d = {"RW": 0, "WR": 0}
for i in range(N):
    if S[i] == "R":
        d["RW"] += 1
ans = d["RW"]
for i in range(N):
    if S[i] == "R":
        d["RW"] -= 1
    else:
        d["WR"] += 1
    ans = min(ans, max(d["RW"], d["WR"]))
print(ans)
N=int(input())
c=input()
C=[]
for i in range(N):
    C.append(c[i])
num= C.count("W")
CC=C[(N-num):]
numnum=CC.count("W")
print(num-numnum)
n = int(input())
c = input()
rl = [ i for i,_ in enumerate(c) if _ == 'R' ]

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

if(stone == "R" * N):
    print(0)
elif(stone == "W" * N):
    print(0)
else:
    b = stone.count("R")
    c = stone[0:b].count("R")
    print(b-c)
n=int(input())
s=input()
cnt=0
ri=len(s)-1
for li,ss in enumerate(s):
  if ss=="W":
    while ri>li and s[ri]=="W":
      ri-=1
    if ri<=li:
      break
    ri-=1
    cnt+=1
print(cnt)
N = int(input())
c = list(str(input()))
for i in range(N):
    if c[i] == "R":
        c[i] = 1
    else:
        c[i] = 0
a = sum(c)
d = c[:a]
e = sum(d)
print(a - e)
n = int(input())
c = list(input())
ramount = c.count('R')
ans = c[: ramount].count('W')
print(ans)
N = int(input())
C = input()
W = sum([1 for c in C if c == 'W'])
R = len(C) - W
print(sum([1 for c in C[R:] if c == 'R']))
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)
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
s = input()
r = s.count('R')
print(s[:r].count('W'))
n = int(input())
c = input()
l, r = 0, n-1
ans = 0
while l < r:
	if c[l] == "W" and c[r] == "R":
		ans += 1
		l, r = l+1, r-1
	else:
		if c[l] == "R":
			l += 1
		if c[r] == "W":
			r -= 1
print(ans)
n = int(input())
s = str(input())
cnt1 = s.count("W") # Wの文字数
cnt2 = len(s) - cnt1 # Rの文字数
ss = s[:cnt2]
cnt3 = ss.count("W")
print(min(cnt1, cnt3))
n=int(input())
c=input()
list=[0 for i in range(n+1)]
r=0
for i in range(n):
  if c[i]=='R':
    r+=1
w=0
list[0]=max(r,w)

#i corresponds to the right side boundary of c[i]
for i in range(n):
  if c[i]=='W':
    w+=1
  if c[i]=='R':
    r-=1
  list[i+1]=max(r,w)
print(min(list))
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Cs = list(input())
from collections import deque
Q = deque()
for i, c in enumerate(Cs):
    if c=='R':
        Q.append(i)

ans = 0
for i in range(N):
    c = Cs[i]
    if c=='W':
        if not Q:
            break
        r = Q.pop()
        if r>i:
            ans += 1
        else:
            break
print(ans)
N = int(input())
C = input()

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

C_fin = ["R" if i < num_R else "W" for i in range(len(C))]

count = 0
for c, c_fin in zip(C, C_fin):
    if(c == c_fin):
        count += 1

ans = (len(C) - count)//2

print(ans)
#coding:utf-8

N = int(input())

C = str(input())

Lis = [0,0] #["R","W"]

for i in C:
    if i == "R":
        Lis[0] += 1
    else:
        Lis[1] += 1

D = "R" * Lis[0] + "W" * Lis[1]

Lis = [0,0]

for s,t in zip(C,D):
    if (s != t) and (s == "R"):
        Lis[0] += 1
    elif (s != t) and (s == "W"):
        Lis[1] += 1

print("{}".format(max(Lis)))
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)
N = input()
li = input()
#print(li)
red = li.count("R")
white = li.count("W")
#print(red,white)


target = li[:red]
ans = red - target.count("R")
print(ans)
n = int(input())
c = input()
a = c.count("R")
ans = 0

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

print(ans)
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)
import sys

input = sys.stdin.readline


n = int(input())

s = list(input())

c = 0
for e in s:
    if e == 'R':
        c += 1

res = min(c,n-c)

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

res = min(res,tmp)

print(res)
n=input()
i=list(input())
Wn=i.count("W")
print(Wn-i[(len(i)-Wn):].count("W"))
N=int(input())
C=list(input())
D=sorted(C)
P=0
for i in range(N):
  if C[i]!=D[i]:
    P+=1
print(P>>1)
n = int(input())
c = input()

#右端から見ていって初めのRが出たらWとRをカウントする
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)
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()
N = int(input())
c = list(input())
count = 0
i = 0
j = N-1
while i < j:
    while c[i] == "R" and i <= N-2:
        i += 1
    while c[j] == "W" and j >= 1:
        j -= 1
    if i < j:
        count += 1
    i += 1
    j -= 1
    if i >= j or i >= N or j <= 0:
        break
print(count)
_=input();*C,=input();print(len([''for _ in range(C.count('W'))if C and C.pop()=='R']))
N = int(input())
C = list(input())
cnt_r = 0
for c in C:
    if c == "R":
        cnt_r += 1
for i in range(cnt_r):
    if C[i] == "R":
        cnt_r -= 1
print(cnt_r)
n = int(input())
c = input()

# それぞれの色の数をカウント
w = c.count("W")
r = c.count("R")

ans = 0
for i in range(r): #　赤の数分文字列を確認する
  if c[i] == "W": ans += 1 # カウント
print(ans)
n = int(input())
k = input()

a = k.count("R")
b = k[:a].count("W")
print(b)
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
if len(rlist) == 0:
    print(0)
    exit()
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)
import sys
readline = sys.stdin.readline
from collections import deque

def solve():
    N = int(readline())
    C = readline().rstrip()

    R, W = 'R', 'W'
    reds = deque(i for i in range(len(C)) if C[i] == 'R')
    whites = deque(i for i in range(len(C)) if C[i] == 'W')

    count = 0
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()
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))
n = int(input())
c = input()
s = [0]
for i in range(n):
  if c[i] == 'R':
    s.append(s[i])
  else:
    s.append(s[i] + 1)
r = n - s[n]
ans = 10**10
for i in range(n + 1):
  ans = min(ans, max(s[i], r - i + s[i]))
print(ans)
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')

l = 0
r = n-1
ans = 0
while l < r:
    if s[l] == "W" and s[r] == "R":
        ans += 1
        l += 1
        r -= 1
    if s[l] == "R":
        l += 1
    if s[r] == "W":
        r -= 1

print(ans)
n = int(input())
cs = input()
cnt = 0
i = 0
j = n-1
while(1):
  if i >= j:
    break
  if cs[i] == "R":
    i += 1
  if cs[j] == "W":
    j -= 1
  if cs[i] == "W" and cs[j] == "R":
    cnt += 1
    i += 1
    j -= 1
      
print(cnt)
N = int(input())
string = input()
r2w = string.count("R")
w2r = 0
ans_list = [max(r2w, w2r)]
for c in string:
    if c == "W":
        w2r += 1
    else:
        r2w -= 1
    ans_list.append(max(r2w, w2r))
print(min(ans_list))
n = int(input())
c = list(input())
R_frag = 0
W_frag = 0
ans = 0
r = n - 1
l = 0
while l < r:
    if c[l] == "R":
        l += 1
    if c[r] == "W":
        r -= 1
    if c[l] == "W" and c[r] == "R":
        c[l] = "R"
        c[r] = "W"
        ans += 1
        l += 1
        r -= 1
print(ans)
N = int(input())
c = input()

num_r = 0
for i in range(N) :
  if c[i] == 'R' :
    num_r += 1
    
ans = 0
for i in range(num_r, N) :
  if c[i] == 'R' :
    ans += 1
    
print(ans)
n = int(input())
s = input()
i = 0
j = len(s)-1
count = 0
while i<j:
    if s[i] == 'R':
        i+=1
    elif s[j] == 'W':
        j-=1
    else:
        i+=1
        j-=1
        count+=1
print(count)
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)
# Nとcの定義
N = int(input())
C = input()

# 赤色の個数
red_num = str.count(C, "R")

# 左からred_num個までに含まれる白色の個数
white_num_left = str.count(C[:red_num], "W")

# 最小の操作回数
min_ope = white_num_left

# 最小の操作回数の出力
print(min_ope)
n = int(input())
s = input()

white_to_red = 0
red_to_white = s.count('R')

ans = red_to_white
for i in range(n):
    if s[i] == 'W':
        white_to_red += 1
    else:
        red_to_white -= 1
    ans = min(ans, max(white_to_red, red_to_white))

print(ans)
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)
N = int(input())
S = input()

r = S.count('R')
ans = r - S[:r].count('R')
print(ans)
n = int(input())
C = list(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
    tmp = max(a, b)
    ans = min(ans, tmp)

print(ans)
n = int(input())
C = input()
rc = C.count('R')
print(C[:rc].count('W'))
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)
n = int(input())
c = input()

ans = 0
l, r = 0, n-1
while True:
  while True:
    if c[l] == "W":
      break
    if l >= r:
      break
    l += 1
    
  while True:
    if c[r] == "R":
      break
    if l >= r:
      break
    r -= 1
  if l >= r:
    break
  ans += 1
  l += 1
  r -= 1
print(ans)
n=int(input())
inp=input()
num=[0]*(n+1)

k=0
for i in range(n):
  if inp[i]=='R':k+=1
  num[i+1]=k
R=num[-1]
W=n-R

ans=float('inf')
for i in range(n+1):
  rl=num[i]
  wl=i-rl
  rr=R-rl
  wr=W-wl
  swap=min(wl,rr)
  change=max(wl,rr)-swap
  ans=min(ans,swap+change)
print(ans)
N = int(input())
S = input()

r = S.count('R')
w = 0
ans = [max(r,w)]

for i in range(N):
    if S[i] == 'W':
        w += 1
    else:
        r -= 1
    ans.append(max(w,r))

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

a, b = 0, 0

a = c.count('R')
ans = max(a, b)

for i in range(n):
    if c[i] == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a, b))
print(ans)
N = int(input())
C = input()
nw = C.count('W')
nr = N - nw

if nw == N or nr == N:
    print(0)
else:
    a = C[:nr]
    b = C[nr:]
    nw = a.count('W')
    nr = b.count('R')
    n = min(nw, nr)
    m = max(nw, nr) - n
    print(n + m)
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)
_,s=open(0)
print(s[:s.count('R')].count('W'))
n = int(input())
c = list(input())

r_cnt = c.count('R')
w_cnt = c.count('W')

cnt = 0

for i in range(r_cnt):
    if c[i] == 'R':
        continue
    else:
        cnt += 1

print(cnt)
n = int(input())
s = input()
check = s.count("R")
q = s[:check]
print(q.count("W"))
n = int(input())
c = input()

l = 0
r = n - 1

ans = 0

while True:
  while c[l] == 'R' and l < r:
    l += 1
  while c[r] == 'W' and l < r:
    r -= 1
  if l < r:
    ans += 1
    l += 1
    r -= 1
  else:
    print(ans)
    break
n = int(input())
C = list(input())
l = 0
r = n-1
ans = 0
while l < r:  
  while C[l] == 'R' and l<r:
    l += 1    
  while C[r] == 'W' and l<r:
    r -= 1
  if C[l]=='W' and C[r] == 'R':
    ans += 1
    l += 1
    r -= 1
    
print(ans)
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))
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')
    rl = 0
    rr = 0
    for i1 in range(rnum):
        rl += a[i1] == 'W'
    for j1 in range(n - rnum):
        rr += a[rnum + j1] == 'R'
    r = max(rl, rr)
    print(r)
if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline

N = int(input())
S = list(input().rstrip())

A1 = [0]*(N+1)
A2 = [0]*(N+1)

t = 0
for i, s in enumerate(S):
    if s == "W":
        t += 1
    A1[i+1] = t

t = 0
for i in reversed(range(N)):
    if S[i] == "R":
        t += 1
    A2[i] = t

ans = 10**18
for a1, a2 in zip(A1, A2):
    score = abs(a1-a2) + min(a1, a2)
    ans = min(ans, score)

print(ans)
n = int(input())
c = input()
r = 0
for i in range(len(c)):
    if c[i] == "R":
        r += 1
m_w = 0
for i in range(r):
    if c[i] == "W":
        m_w += 1
print(m_w)
N=int(input())
c=input()
R=c.count('R')
W=0
ans=[R,c.count('W')]
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans.append(max(R,W))
print(min(ans))
n = int(input())
c = input()
p = []
for i in range(n):
  if c[i]=='R':
    p += [i]
print(len([1 for i in p if i>=len(p)]))
N=int(input())

c=input()

C=[a for a in c]

number=0
answer=0
red=C.count('R')

if red==0 or red==N:
    print(0)
else:
    words=C[red:]
    print(words.count('R'))
N,c=input(),input()
print(c[:c.count('R')].count('W'))
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)
N = int(input())
a = list(input()) #１文字ずつ
# print(a)

allW=0
allR=0
for i in range(N):
    if a[i]=='W':
        allW+=1
    elif a[i]=='R':
        allR+=1
# print('allW,allR:',allW,allR)

W=0
R=allR
out = max(W,R)
ans = out
for shikiri in range(N):
    if a[shikiri] =='W':
        W+=1
    elif a[shikiri]=='R':
        R-=1
    out = max(W,R)
    ans = min(ans,out)
    # print('out,ans:',out,ans)

print(ans)
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    c = rl().rstrip()
    
    counter = Counter(c)
    red = counter['R']
    white = counter['W']
    
    red -= c[:red].count('R')
    white -= c[-white:].count('W')
    print(min(red, white))


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

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

ans = 0
for i in range(tmp):
    if C[i] == "W":
        ans += 1
print(ans)
N = int(input())
C = list(input())
l = 0
r = N-1
ans = 0
while (r-l) > 0:
    if C[l] == "W" and C[r] == "R":
        C[l], C[r] = C[r], C[l]
        l += 1
        r -= 1
        ans += 1
        continue
    if C[l] == "R":
        l += 1
    if C[r] == "W":
        r -= 1
print(ans)
n = int(input())
k = input()
k2 = k[::-1]
i1 = 0
i2 = 0
cnt = 0
while i1 < n:
  if k[i1] == 'W':
    while i2 < n:
      if k2[i2] == 'R':
        i2 += 1
        cnt += 1
        break
      i2 += 1
      if i1 + i2 >= n:
        break
  i1 += 1
  if i1 + i2 >= n:
    break
print(cnt)
def resolve():
    n = int(input())
    c = input()
    ans = 0
    l = -1
    r = n
    while True:
        l += 1
        r -= 1
        while l < n and c[l] == "R":
            l += 1
        while r >= 0 and c[r] == "W":
            r -= 1
        if l > r:
            break
        ans += 1
    print(ans)


if __name__ == '__main__':
    resolve()
def main():
    n = int(input())
    c = input()
    r = c.count('R')
    w = c.count('W')
    ropt = c[:r].count('R')
    wopt = c[r:].count('W')

    rnot = r - ropt
    wnot = w - wopt

    return min(rnot,wnot)
    
 
if __name__ == '__main__':
    print(main())
n = int(input())
c = input()
r = 0
left, right = 0, n-1
while left < right:
    if c[left] == 'W' and c[right] == 'R':
        r += 1
        left += 1
        right -= 1
        continue
    if c[left]=='R':
        left += 1
    if c[right]=='W':
        right -= 1
print(r)
from collections import deque

n=int(input())
d=deque(list(input()))
#print(d)
r=0
while n>1:
  #print(d)
  tempr=False
  n-=1
  if d.pop()=="W":
    pass
  else:
    while n>0:
      n-=1
      if d.popleft()=="R":
        pass
      else:
        r+=1
        break
  #print(d,r)
print(r)
N = int(input())
stone = input()
R = stone.count('R')
ans = stone.count('W', 0, R)
print(ans)
import collections


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

r_num = c.count("R")

for i in range(n):
    if c[i] == "W":
        break

print(max(c[i:].count("R")-c[i:r_num].count("R"), 0))
n, c = int(input()), input()

wa = [0] * (n+2)
for i in range(n):
    if(c[i]=='W'): wa[i+1]+=1
for i in range(n+1):
    wa[i+1] += wa[i]

ans = n;
for i in range(n+2):
    w = wa[i]
    r = n-i - (wa[n] - wa[i])
    ans = min(ans, max(w, r))
print(ans)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

C = input()

r = C.count('R')
w = C.count('W')

if len(C) == r or len(C) == w or C[:r].count('R') == r:
    print(0)
else:
    print(C[:r].count('W'))
n=int(input())
c=input()
R=c.count("R")
W=c.count("W")
LW=0
for i in range(R):
    if c[i]=="W":
        LW+=1
print(LW)
import collections
N = int(input())
c = input()
A = collections.Counter(c)["R"]
B = collections.Counter(c[A:])["R"]
print(B)
n=int(input())
c=list(input())

import math

rkosu=c.count("R")
wkosu=n-rkosu

ca=["R"]*rkosu+["W"]*wkosu

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

ans=math.ceil(count/2)
print(ans)
import sys
N = int(input())
c = str(input())

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

red = c.count("R")
stay_red = c.count("R", 0, red)
print(red - stay_red)
n=int(input())
s=input()

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

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

print(wcount-wwcount)
n = int(input())
cs = input()
b=[]
for i in range(n):
  if cs[i] == "W":
    b.append(0)
  else:
    b.append(1)
a= sum(b)
ans = a- sum(b[:a])
print(ans)
n = int(input())
s = input()

w = s.count('W')
r = s.count('R')
sw = s.count('W',0-w)

rw = 2*10**5
if r >=1:
  rw = w-sw
  
print(min(w,r,rw))
N = int(input())
S = input()
print(S[S.count("R"):].count("R"))
N = int(input())
S = input()

R = [0]
W = [0]
r = 0
w = 0

for i in range(N):
    if S[i]=="W":
        w+=1
    else:
        r+=1
    R.append(r)
    W.append(w)
ans = N
for i in range(N+1):
    ans = min(ans,max(W[i],R[N]-R[i]))
print(ans)
n=int(input())
c=input()
a=c.count('R')
print(c[:a].count('W'))
n=int(input())
c=list(input())
if len(set(c))==1:
    print('0')
else:
    r=c.count('R')
    w=c.count('W')
    rc=c[:r].count('R')
    wc=c[:r].count('W')
    if rc==0:
        if r<w:
            print(r)
        else:
            print(w)
    else:
        if r-rc<wc:
            print(r-rc)
        else:
            print(wc)
N = int(input())
c = input()

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

print(cnt)
import math
import sys
from itertools import permutations
input = sys.stdin.readline

n=int(input())
arr=list(input())
if arr[-1]=='\n':
	arr.pop()

countW=0
for i in range(n):
	if arr[i]=='W':
		countW+=1

ans=0
for i in range(n-countW):
	if arr[i]=='W':
		ans+=1

print(ans)
_,C=input(),input()
a=C.count('R')
print(a-C[:a].count('R'))