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

w = 0
w_left = [None]*(N+1)
w_left[0] = 0
for i in range(N):
    if c[i] == 'W': w += 1
    w_left[i+1] = w

r = 0
r_right = [None]*(N+1)
r_right[N] = 0
for i in reversed(range(N)):
    if c[i] == 'R': r += 1
    r_right[i] = r

def cost(i):
    return max(w_left[i], r_right[i])

best = min(cost(i) for i in range(N+1))
print(best)
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R > W:
    for i in range(0,cnt):
        if list[N-i-1]=="R":
            ans +=1

if R<=W:
    for j in range(0,cnt):
        if list[j] == "W":
            ans +=1


print(ans)
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N = int(input())
S = input()
Rs = S.count('R')
Ws = N - Rs

if Rs == 0 or Ws == 0:
	print(0)
	sys.exit()

C = list(S)

i = 0
j = N-1
ops = 0

while i < j:
	while i < N and C[i] == 'R': i += 1
	while j >= 0 and C[j] == 'W': j -= 1

	if i < j:
		C[i], C[j] = C[j], C[i]
		ops += 1

print(ops)
n=int(input())
c=list(input())
all_r=c.count('R')
l_w=0
l_r=0
ans=0
for i in range(n):
  if l_w==all_r-l_r:
      ans=l_w
      break
  if c[i]=='W':
    l_w+=1
  else:
    l_r+=1
print(ans)
n=int(input())
data=input()
cnt=0
wcnt=0
for i in data:
    if i=="R":
        cnt+=1
for i in range(cnt):
    if data[i]=="W":
        wcnt+=1
print(wcnt)
n = int(input())
s = str(input())


r = 0
w = 0
w_num = 0


for i in s:
    if i == "R":
        r += 1


for j in s[0:r]:
    if j == "W":
        w_num += 1
print(w_num)
n = int(input())
cA = input()

wCounter = 0
for i in range(n):
    if cA[i] == "W":
        wCounter+=1

flag = 0
count = 0
for i in range(n-1, -1, -1):
    if flag == 0 and cA[i] == "R":
        flag = 1
    if flag == 1 and i < n-wCounter and cA[i] == "W":
        count+=1
print(count)
N=int(input())
c=str(input())
R=c.count('R')
W=c[:R].count('W')
print(W)
n=int(input())
c=input()
r=c.count('R')
x=c[:r]
print(x.count('W'))
n=int(input())
s=input()

from collections import Counter

c=Counter(s)

r=c['R']

cnt=0
for i in range(r):
    if s[i]=='W':
        cnt+=1


print(cnt)
I=lambda:list(map(int,input().split()))
n,=I()
s=list(input())
i=0
j=n-1
ans=0
while i<j:
	if s[i]=='R' and s[j]=='W':
		i+=1
		j-=1
	elif s[i]=='R':
		i+=1
	elif s[j]=='W':
		j-=1
	else:
		s[i]='R'
		s[j]='W'
		ans+=1
		i+=1
		j-=1
print(ans)
n = int(input())
C = list(input())
c = 0
pi = 0
pj = n-1
while True:
    for i in range(pi, n):
        if C[i] == 'W':
            break
    else:
        break
    for j in range(pj, 0, -1):
        if C[j] == 'R':
            break
    else:
        break
    if i < j:
        C[i] = 'R'
        C[j] = 'W'
        c += 1
    else:
        break
    pi = i
    pj = j
print(c)
def main():
    N = int(input())
    S = [s for s in input()]
    ans = 10**9
    w = 0
    r = S.count("R")
    for i in range(N+1):
        ans = min(ans, max(w, r))
        if i == N:
            break
        if S[i] == "W":
            w += 1
        else:
            r -= 1
    print(ans)


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

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

a = Counter(c)
b = c[::-1]

cnt = 0
for i in range(a['W']):
    if b[i] == "R":
        cnt += 1
        
print(cnt)
n = int(input())
c = list(input())
cr = c.count('R')
cw = c.count('W')
if cr == 0 or cw == 0:
    print(0)
    exit()
print(c[:cr].count('W'))
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    ans = 0
    left = 0
    right = len(c) - 1
    while left < right:
        if c[left] == 'R':
            left += 1
            continue
        if c[right] == 'W':
            right -= 1
            continue
        left += 1
        right -= 1
        ans += 1

    return ans


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(c[:rc].count('W'))
from collections import deque

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

red = deque()
white = deque()

for i in range(len(c)):
    if c[i] == 'R':
        red.append(i)
    else:
        white.append(i)

ans = 0

while red and white:
    r = red.pop()
    w = white.popleft()
    if r < w:
        break
    else:
        ans += 1

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

m = s.count("R")
ans = s[:m].count("W")

print(ans)
def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: # c[i] == 'W'
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))
n = int(input())
c = input()
_trigger = False
ans = [0 for i in range(2)]
_count = c.count('R')
for i in range(len(c)):
  if c[i] == 'W':
    _trigger = True
    if _count >= i + 1:
      ans[1] += 1
  else:
    if _trigger == True and i + 1 >= _count:
      ans[0] += 1
print (min(ans))
import sys


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


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

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


if __name__ == "__main__":
    print(main())
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

c = input()

a = c.count('R')

b = 0
ans = max(a, b)

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

print(ans)
n = int(input())
s = input()
res = 2000000 
aw=s.count('W')
ar=s.count('R')
if (aw == 0 or ar == 0):
	res=0
pw=0
pr=0
for i in range(n-1):
	if (s[i] == 'R'):
		pr=pr+1
	else:
		pw=pw+1
	if (max(pw,ar-pr) < res):
		res = max(pw,ar-pr)

print(str(res))
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())
l = list(input())
r=0
for i in l:
    if i=="R":
        r+=1
cr=0
cw=0
if r==0:
    print("0")
else:
    for i in range(len(l)):
        if l[i]=="R":
            cr+=1
        else:
            cw+=1
        if cw== r-cr:
            break
    print(cw)
n=int(input())
k=list(input())
n1=k.count("R")
ideal_lis=["R"]*n1
ans = 0
for i in range(n1):
    if k[i]!=ideal_lis[i]:
        ans+=1
print(ans)
N=int(input())
s=input()
l=[]
c=0#Rの数
for i in range(N):
  l.append(s[i])
  if s[i]=="R":
    c+=1
a=0
for i in range(c):
  if l[i]=="W":
    a+=1
print(a)
# coding:utf-8
n = int(input())
c = input()
red = c.count('R')
print(c[:red].count('W'))
import math
import sys

def main():
    N=int(input())
    C=list(input())
    res=0
    #WRRW WRWRW
    R=0
    W=0
    for i in range(len(C)):
        if C[i]=="W":
            W+=1
        else:
            R+=1
    for i in range(len(C)):
        if i<R:
            if C[i]=="W":
                res+=1
    print(res)
if __name__=="__main__":
    main()
n = int(input())
s = input()

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

# 要はRRRRWWWWWの形にする
# r_num以内にあるRは動かさなくて良い
# r_numより外にあるRを動かす必要がある

for i in range(n):
    if i > r_num - 1 and s[i] == 'R':
        cnt += 1
print(cnt)
n=int(input())
c=list(input())
w=c.count('W')
ans=0
for i in range(n-w):
    if c[i]=='W':
        ans += 1

print(ans)
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)
import sys
N = int(input())
c = input()
n = int(N/2)
cnt_R = c.count('R')
c_1 = c[:cnt_R]
cnt = c_1.count('W')
print(cnt)
n = int(input())
s = input()
num_r=s.count('R')
if num_r==n or num_r==0:
    print('0')
    exit()

red=[]
for i in range(n):
    if s[i]=='R':
        red.append(i)
ans = num_r
for j in red:
    if j+1 <=num_r:
        ans-=1
print(ans)
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)
n = int(input())
c = input()
cnt = 0
ans = 0
for i in range(n):
    if(c[i]=='R'):
        cnt+=1
for i in range(cnt):
    if(c[i]=='W'):
        ans+=1
print(ans)
n = int(input())
c = list(input())
ans = 0
counta=0
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
	if c[i]=='R':
		a[i] = 1

w = a.count(0)
r = a.count(1)
for j in range(r):
	b[j] = 1
if a==b:
	pass
else:
	for k in a:
		counta+=1
		if k==0:
			ans+=1
		if counta==r:
			break
print(ans)
N = int(input())
S = input()
cnt_w = S.count("W")
cnt_r = S.count("R")
cl_chg = min(cnt_w, cnt_r)

sw = S[:cnt_r].count("W")
sr = S[cnt_r:].count("R")
swap = min(sw, sr)
print(min(cl_chg, swap))
N = int(input())
C = input()

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

ans = r_cnt
r2w = r_cnt
w2r = 0

for c in C:
    if c == 'W':
        w2r += 1
    elif c == 'R':
        r2w -= 1
    ans = min(ans, max(r2w, w2r))
print(ans)
N = int(input())
c = list(input())
Rcount = 0
for i in range(N):
    if c[i] == 'R':
        Rcount += 1
ans = 0
for i in range(Rcount):
    if c[i] == 'W':
        ans += 1
print(ans)
N = int(input())
c = [0 if s=='R' else 1 for s in input()]

l = 0
r = N - 1

ans = 0
while l < r:
    while l < N and c[l] == 0:
        l += 1
    while r > 0 and c[r] == 1:
        r -= 1
    if l < r:
        ans += 1
    l += 1
    r -= 1
print(ans)
# rr..wwにする します

n = int(input())
c = list(input())
w_count = c.count("W")
if w_count == 0 or w_count == n:
    print(0)
    exit()
ans1 = 0
for i in range(n - 1, n - w_count - 1, -1):
    if c[i] == "R":
        ans1 += 1
print(ans1)
n=int(input())
c=input()
i=c.count('R')
j=c.count('W',0,i)
print(j)
N = int(input())
c = input()
var = 0
i = 0
j = 0
while True:
  if i+j >= N:
    break
  else:
    if c[i] == "W":
      if c[-1-j] == "R":
        var += 1
        i += 1
        j += 1
      else:
        j += 1
    elif c[i] == "R":
      i += 1
print(var)
N = int(input())
C = input()

WL = [0]
RR = [C.count('R')]

for i in range(0, N):
    if C[i] == 'R':
        WL.append(WL[i])
        RR.append(RR[i] - 1)
    else:
        WL.append(WL[i] + 1)
        RR.append(RR[i])

MM = N
for i in range(0, N + 1):
    MM = min(MM, (max(WL[i], RR[i])))
print(MM)
N = int(input())
C = input()
R = C.count("R")
ans = 0

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

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

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

r = c.count("R")
ans = 0

for i in range(r):
    if c[i] == "R":
        continue
    else:
        ans += 1

print(ans)
N = input()
# C = list(map(lambda x: x == 'W', list(input())))
C = list(input())

countR = C.count('R')
countI = C[0:countR]. count('W')

print(countI)
# abc174_d.py

N = int(input())
S = input()
scnt = S.count("R")

print(S[:scnt].count("W"))
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)
import sys

n = int(input())

c = input()

count = 0
check = 0
wList = []
rList = []

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

if len(wList) == 0 or len(rList) == 0:
    print(0)
    sys.exit()

rMax = rList[-1]
wMin = wList[0]

for i in range(len(rList)):
    if rList[-1] < wList[0]:
        break
    else:
        count += 1
        del rList[-1]
        del wList[0]

print(count)
def solve():
  N = int(input())
  C = input()  # 'RWRRW...'
  # WR is bad
  # 1. exchange two
  # 2. flip one
  # RRRRWWWWWW
  # max(R) < min(W)
  W = []
  R = []
  for i, c in enumerate(C):
    if c == 'W':
      W.append(i)
    else:
      R.append(i)
  if not W or not R:
    return 0
  #print(W, R)
  for i in range(min(len(W), len(R))):
    if R[-(1+i)] < W[i]:
      return i
  return min(len(W), len(R))
print(solve())
n = int(input())
c  = str(input())
x = 0
for i in range(n):
  if c[i] == "R":
    x += 1
a = 0
for i in range(x):
  if c[i] == "W":
    a += 1
print(a)
n = int(input())
S = input()
c_w = 0
c_r = 0
for i in range(len(S)):
    if S[i] == 'W':
        c_w += 1
    else:
        c_r += 1
p_1 = c_w
p_2 = c_r
p_3 = 0
for i in range(c_r):
    if S[i] == 'W':
        p_3 += 1
print(min(p_1,p_2,p_3))
n=int(input())
s=input()
a=[0,s.count('R')]
ans=max(a)
for i in range(n):
  if s[i]=='R':
    a[1]-=1
  else:
    a[0]+=1
  ans=min(ans,max(a))
print(ans)
N = int(input())
C = list(input().strip())
count = 0
j = N - 1
for i in range(N):
  if C[i] == "W":
    while i < j:
      if C[j] == "R":
        C[i], C[j] = C[j], C[i]
        count += 1
        break
      else:
        j -= 1

print(count)
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
n = int(input())
c= input()

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

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

print(min([ans1,ans2,ans3]))
def main():
    N = int(input())
    cs = list(input())

    l = 0
    r = N - 1

    cnt = 0
    while l < r:
        while l <= N - 1 and cs[l] == 'R':
            l += 1

        while 0 <= r and cs[r] == 'W':
            r -= 1

        if l >= r:
            break

        cs[l], cs[r] = cs[r], cs[l]
        cnt += 1

    print(cnt)

main()
n = int(input())
c = input()
rcount = c.count('R')
print(rcount - c[:rcount].count('R'))
N = int(input())
c = list(input())
r = 0
w = 0
ans = 0
for i in c:
    if i == "R":
        r += 1
    else:
        w += 1
for i in range(r):
    if c[i] != "R":
        ans += 1
print(ans)
n=int(input())
from collections import deque
q =deque(input())

ans = 0
while q:
    while q and q[0] == 'R' and q:
        q.popleft()
    while q and q[-1] == 'W' and q:
        q.pop()
    if not q:break
    ans += 1
    q.popleft()
    q.pop()
print(ans)
n=int(input())
arr=list(input())
w=arr.count('W')
r=arr.count('R')
ans=min(w,r)
leftr=r-arr[:r].count('R')
ans=min(ans,leftr)
print(ans)
n = int(input())
s = str(input())
cnt = 0
for i in range(n):
    if s[i]=='R':
        cnt += 1
#print(cnt)
cnt_r = 0
for i in range(cnt):
    if s[i]=='R':
        cnt_r += 1
#print(cnt_r)
print(cnt - cnt_r)
n = int(input())
string = input()
r_cnt = string.count("R")
w_cnt = string.count("W")
j = 0
cnt = 0
for i in range(r_cnt):
    if string[i] == "W":
        cnt += 1
print(cnt)
import collections

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

r_n = collections.Counter(c)['R']

ans = r_n
for i in range(r_n):
    if c[i] == 'R':
        ans -= 1

print(ans)
N = int(input())
C = input()
a = b = ans = 0
for c in C:
    if c == 'R':
        a += 1
ans = max(a, b)
for c in C:
    if c == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a, b))
print(ans)
N = int(input())
s = str(input())

a = 0
b = 0

for i in range(N):
    if s[i] == 'R':
        a = a + 1
ans = max(a,b)
for i in range(N):
    if s[i] == 'R':
        a = a - 1
    else:
        b = b + 1
    now = max(a,b)
    ans = min(ans, now)
print(ans)
n=int(input())
L=list(input())
w=0
r=0
for i in range(n):
    if L[i]=="W":
        w+=1
    else:
        r+=1
s2=w
s1=r
s3=0
for i in range(r):
    if L[i]=="W":
        s3+=1
print(min(s1,s2,s3))
n = int(input())
cc = input().rstrip()

sc = ''.join(sorted(cc))
x = 0
for i in range(n):
    if cc[i] != sc[i]:
        x += 1
print((x + 1) // 2)
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:rc]
    wwc = s.count('W')
    print(wwc)
def main():
    n = int(input())
    c = str(input())

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

    w_count_ano = 0
    for i in range(w_count):
        if c[- 1 - i] == 'W':
            w_count_ano += 1

    count = w_count - w_count_ano
    print(count)


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

i=0
j=n-1
c= 0

while i!=j:
  while s[j]!='R' and j>i:
    j-=1
    
  while s[i]=='R' and j>i:
    i+=1
 
  if i!=j:
    c+= 1
    i+= 1
    j-=1
  if i>=j:
    break
    
print(c)
N = int(input())
c = input()

num_red = c.count('R')
print(num_red - c[:num_red].count('R'))
n=int(input())
s=input()
cr=0
for i in range(n):
    if s[i]=="R":
        cr+=1
ans=0
for i in range(cr):
    if s[i]=="W":
        ans +=1
print(ans)
n = int(input())
c = list(input())
red_count = c.count('R')
ans = 0
for i in range(red_count):
    if c[i] == 'W':
        ans += 1
print(ans)
N = int(input())
S = input()
i = 0
j = N - 1
ans = 0
while i < j:
    while i < N and S[i] == 'R':
        i += 1
    while j > 0 and S[j] == 'W':
        j -= 1
    if i >= j:
        break
    ans += 1
    i += 1
    j -= 1
print(ans)
n = int(input())
s = input()
r,w = 0,0
for i in range(n):
    if(s[i]=='W'):
        w+=1
    else:
        r+=1
ans = 0
if(w<=r):
    for i in range(n-1, n-w-1, -1):
        if(s[i]!='W'): ans+=1
else:
    for i in range(r):
        if(s[i]!='R'): ans+=1
print(ans)
n = int(input())
c = input()

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

print(ans)
n = int(input())
s = input()
k = s.count("R")
t = s[:k].count("R")
print(k-t)
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n=N()
c=input()
ans=0
w=[]
r=[]
for i,j in enumerate(c):
    if j=="W":
        w.append(i)
    else:
        r.append(i)
x=min(len(w),len(r))
for i in range(x):
    if w[i]<r[-1-i]:
        ans+=1
    else:
        break
print(ans)
N = int(input())
S = input()

reds_cnt = S.count('R')
whites_in_reds = S[:reds_cnt].count('W')
print(whites_in_reds)
N = int(input())
c = input()
 
r = c.count('R')
print(c[:r].count('W'))
n = int(input())
c = input()
rc = c.count('R')
print(c[rc:].count('R'))
n=int(input())
s=input()
arr=[i for i in s]

ar=sorted(arr)


ans=0
for i in range(len(arr)):
    if arr[i]!=ar[i]:
        ans+=1
if ans%2==0:
    print(ans//2)
else:
    print((ans//2)+1)
N = int(input())
C = list(input())
ans = 0
l = 0
for i in range(N-1, -1, -1):
    if C[i] == 'R':
        while l < N and C[l] != 'W':
            l += 1
        if l > i or l == N:
            break
        C[i], C[l] = C[l], C[i]
        ans += 1
print(ans)
n = int(input())
alis = list(input())
t = alis.count("R")
print(alis[0:t].count("W"))
N = int(input())
S = list(input())

#Wを全部右に寄せる
sW = 0
sR = 0
fW = N
fR = N-1
res = 0

while True:
  for i in range(sW,N):
    if S[i]=="W":
      fW = i
      break
  for i in range(sR,N):
    if S[N-i-1]=="R":
      fR = i
      break
  if fW<N-fR-1:
    S[fW] = "R"
    S[N-fR-1] = "W"
    sW = fW
    sR = fR
    res += 1
  else:
    break
    
print(res)
n = int(input())
a = list(input())
cnt_r = n-1
cnt_l = 0
cnt = 0
while True:
  if cnt_r == cnt_l:
    print(cnt)
    exit()
  if a[cnt_r] == 'W':
    cnt_r -= 1
    continue
  if a[cnt_l] == 'R':
    cnt_l += 1
    continue
  a[cnt_r], a[cnt_l] = a[cnt_l], a[cnt_r]
  cnt += 1
n = int(input())
c = list(input())
md = c.count('R')
rc, wc = c[md:].count('R'), c[:md].count('W')
if rc==wc: print(rc)
elif rc > wc: print(rc+(rc-wc))
else: print(wc+wc-rc)
n = int( input() )
c = list( input() )

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

print( ans )
N = int(input())
list1 = list(input())
RN = list1.count('R')
ii = 0
for i in range(N):
    if list1[i] == 'W' and RN != 0:
        RN += -1
        ii += 1
    elif list1[i] == 'R' and RN != 0:
        RN += -1
    elif RN == 0:
        break
print(ii)
N = int(input())
S = list(input())
R = [0]*N
W = [0]*N
for i in range(N):
    if S[i]=="R":
        R[i]+=1
    else:
        W[i]+=1

sumR = sum(R)

ans = sumR-sum(R[:sumR])

print(ans)
# -*- coding: utf-8 -*-
 
N = int(input())
C = input()

ans = 0
i = -1
j = N
while( True ):
  
  i += 1
  while( i<j ):
    if( C[i] == 'W' ):
      break
    else:
      i += 1
  
  j -= 1
  while( j>i ):
    if( C[j] == 'R' ):
      break
    else:
      j -= 1
  
  if ( i<j ):
    ans += 1
  else:
    break

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

cnt = 0
i = 0
j = n-1
while i < j:
    while c[i] == 'R' and i < j:
        i += 1
    while c[j] == 'W' and i < j:
        j -= 1
    if c[i] != 'W' or c[j] != 'R':
        break
    i += 1
    j -= 1
    cnt += 1

print(cnt)
N = int(input())
C = input()

r = 0
w = 0
for c in C:
    if c == 'R':
        r += 1
    else:
        w += 1

if w == 0 or r == 0:
    print(0)
    exit(0)

ans = 0
if r < w:
    for rx in range(r):
        if C[rx] != 'R':
            ans += 1
else:
    for wx in range(w):
        if C[N-1-wx] != 'W':
            ans += 1

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

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

ans = 0

r = c.count("R")
for i in range(r):
    if c[i] == "W":
        ans+=1
print(ans)
n=int(input())
s=input()
count=0
for i in range(n):
  if s[i]=='R':
    count+=1
for i in range(count):
  if s[i]=='R':
    count-=1
print(count)
n = int(input())
s = input()

rc = s.count('R')

ans = 0
for stone in s:
    if stone == 'R':
        rc -= 1
    else:
        if rc > 0:
            rc -= 1
            ans += 1

print(ans)
# -*- coding:utf-8 -*-
import sys
input = sys.stdin.readline
n = int(input())
c = str(input()).replace("\n","")
cl = list(c)
# print(cl)
rnum = cl.count("R")

if rnum == 0:
  print(0)
  sys.exit()

rnum_f = cl[:rnum].count("R")
print(min(rnum,rnum-rnum_f))
n = int(input())
c = list(input())
r = c.count("R")
ans = 0
for i in range(r):
    if c[i] == "W":
        ans += 1
print(ans)
n = int(input())
C = list(input())

r_num = C.count('R')
ans = C[:r_num].count('W')
print(ans)
import sys

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

r = c.count("R") 
rs = c[:r]
rsw = rs.count("W")

print(rsw)
n = int(input())
c_array = list(input())

w_num = c_array.count('W')
r_num = n-w_num
def get_ans(half):
    wl_num = c_array[:half].count('W')
    rr_num = c_array[half:].count('R')
    ans = min(wl_num, rr_num) + abs(wl_num-rr_num)
    return ans

ans = min(get_ans(r_num), w_num, r_num)
print(ans)
from collections import Counter
def main():
    N = int( input())
    C = list(input())
    CC = Counter(C)
    ans = min(CC["R"], CC["W"])
    r = CC["R"]
    count = 0
    for c in C[:r]:
        if c == "W":
            count += 1
    ans = min(ans, count)
    print(ans)
if __name__ == '__main__':
    main()
n = int(input())
c = list(input())
wpos = 0
rpos = n-1
count = 0
while wpos < rpos :
  while c[wpos] == "R":
    wpos += 1
    if wpos > rpos: break
  while c[rpos] == "W":
    rpos -= 1
    if wpos > rpos: break
  if wpos < rpos :
    count += 1
    c[wpos],c[rpos]=c[rpos],c[wpos]
print(count)
N = int(input())
c = list(input())

red=0
for i in c:
    if i=="R":
        red+=1
count = 0
for i in range(red):
    if c[i]=="W":
        count+=1
print(count)
N = int(input())
C = list(input())

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

ref_c = ["R"]*r_cnt + ["W"]*w_cnt

cnt = 0
for i in range(N):
    if C[i] != ref_c[i]:
        cnt += 1

ans = min(r_cnt, w_cnt, int(cnt/2))
print(ans)
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]))
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
s=SI()
allr=s.count("R")
lr=s[:allr].count("R")
print(allr-lr)