peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w):]; list_w1 = mozi2[:(a-num_w)]
list_r2 = mozi2[(a-num_r):]; list_r1 = mozi2[:(a-num_r)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)
n=int(input())
s = input()
ans = 0
for i in s:
	if i=="R":
		ans+=1

for i in range(0,ans):
	if i=="R":
		ans-=1

print(ans)
from collections import Counter
N = int(input())
c = input()
counter = Counter(c)

if counter["R"] == 0 or counter["W"] == 0:
    print(0)
else:
    first_r = 0
    for i in range(N):
        if c[i] == "R":
            first_r = i+1
            break
    if first_r <= counter["R"]:
        print(min(counter["R"]-1,counter["W"]))
    else:
        print(min(counter["R"], counter["W"]))
N = int(input())
a = list(input())
if N%2==0:
  x = a[0:int(N/2)]
  y = a[int(N/2):N]
else:
  x = a[0:int(N/2)]
  y = a[int(N/2)+1:N]
count_ri = x.count('W')
count_le = y.count('R')
if a.count('W') ==0 or a.count('R')==0:
  print(0)
elif x.count('W')==0 and y.count('R')==0:
  print(0)
elif count_ri==count_le:
  print(count_ri)
elif count_ri>count_le:
  print(count_le)
elif count_ri<count_le:
  print(count_ri)
import math
N = int(input())
S = str(input())
print(S[:math.floor(N/2)].count('W'))
N = int(input())
c = list(input())

left_white = 0
Rcount = c.count("R")
for i in range(0,len(c)):
    if c[i] == "R":
        left_white = i
        break
#print(i,''.join(c[i:]))
if left_white >= Rcount:
    print(c.count("R"))
elif i == 0:
    print(0)
else:
    print(c[i+1:].count("R"))
n = int(input())
c = input()
def try_count(c, color):
    try:
        if c.count(color)!=0:
            return c.count(color)
        else:
            return n
    except:
        return 0
all_r = try_count(c, 'R')
all_w = try_count(c, 'W')
left_w = try_count(c[:all_w], 'W')
# print(all_r,all_w,left_w)
print(min(all_r,all_w,left_w))
n = int(input())
arr = list(input())
arr = [1 if i == "R" else 0 for i in arr]
rarr = list(reversed(arr))
a = sum(arr)
if a == 0 or a == n:
    ans = 0
else:
    widx = arr.index(0)
    ridx = n - rarr.index(1)
    arr = arr[widx:ridx]
    rsum = sum(arr)
    ws = arr[:-rsum].count(0)
    rs = arr[-rsum:].count(1)
    ans = max(ws,rs)

print(ans)
import sys
input = sys.stdin.readline

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

n = I()
mychr = input().rstrip()

result = float('inf')
red = 0
for i in mychr:
    if i == "R":
        red += 1

R = 0
W = 0

for index, i in enumerate(mychr):
    if i == "R":
        R+=1
    else:
        W+=1
    temp = max(W,red-R)
    result = min(result, temp)

print(result)
n = int(input())
s = input()
ans = 0
i = 0
while True:
    r = 0
    w = 0
    if s[i] == 'W':
        w += 1
    else:
        r += 1
    i += 1
    while i < n and not (s[i] == 'W' and s[i - 1] == 'R'):
        if s[i] == 'W':
            w += 1
        else:
            r += 1
        i += 1
    ans += min(r, w)
    if i == n:
        break

print(ans)
N = int(input())
C = input()
w = sum([True for c in C if c == "W"])
r = N - w

count = 0
for i, c in enumerate(C):
  if i < w and c == 'W':
    count += 1
print(count)
n = int(input())
c = input()

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

for i in range(n):
    if c[i] == 'W' and i >= wcount:
        count += 1
print(count)
n = int(input())
c = input()

r = c.count("R")
cnt = 0
for i, j in enumerate(c):
    if i + 1 == r:
        break
    if j == "W":
        cnt += 1
print(cnt)
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w+1):]; list_w1 = mozi2[:(a-num_w+1)]
list_r2 = mozi2[(a-num_r+1):]; list_r1 = mozi2[:(a-num_r+1)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)
import sys

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

left = None  # 一番左の W　を記録
right = None  # 一番右の R を記録
count = 0

for i in range(len(c)):
    if c[i] == 'W':
        left = i
    if c[len(c) - 1 - i] == 'R':
        right = len(c) - 1 - i

    if (left is not None) and (right is not None) and (left < right):
        # print(f'left{left}, right {right}')
        count += 1
        left = None
        right = None

print(count)
N=int(input())
S=input()
ans=0
i=0
j=N-1
while i<j:
  while i<N:
    if S[i]=='W':
      break
    else:
      i+=1
  while j>0:
    if S[j]=='R':
      break
    else:
      j-=1
  if i<=j:
    ans+=1
    i+=1
    j-=1
print(ans)
N=int(input())
white=0
red=0
W=list(str(input()))
if "W" not in W or "R" not in W:
  print("0")
  exit()
for i in range(N//2):
  if W[i]=="W":
    white+=1
for i in range(N//2):
  if W[N-1-i]=="R":
    red+=1
Z=min(white,red)
rest=abs(white-red)
Z=Z+rest
if (N/2)%1!=0:
  if W[N//2+1]=="W":
    Z+=1
print(Z)
N=int(input())
C=input()
from collections import Counter
count=Counter(C)
#print(count)
countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<countW:
        missW+=1
    if now=="R" and i>countR:
        missR+=1
# print(countR, countW)
X=min(missW, missR)
if X!=0:
    ans=X+abs(missR-missW)
else:
    ans=0
print(ans)
n = int(input())
c = input()

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

print(t)
n = int(input())
string = input()
count = 0
for i in range(n+1):
    left = string[:i]
    right = string[i:]
    tmp_max = max(left.count("W"), right.count("R"))
    if count < tmp_max:
        count = tmp_max
print(count)
import sys
input = sys.stdin.readline

n = int(input())
n2 = n//2
c = input()

if c.count("R") == n:
    print(0)
else:
    cnt = c.count("R", n2, n)
    print(cnt)
N = int(input())
S = input()

count = N

for i in range(1, N):
    numW = S[:i].count('W')
    numR = S[i:].count('R')

    if(max(numW, numR) < count):
        count = max(numW, numR)

print(count)
K = int(input())
if K % 2 == 0 or K % 5 ==0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 0
    while True:
        count += 1
        n = n % K
        if n == 0:
            print(count)
            exit()
        else:
            n_before = 10 * n_before % K
            n = n + n_before
print(count)
#D
import re
N=int(input())
c = (input())
combi=re.findall("WR",c)
print(len(combi))
n = int(input())
stone = input()
red_stone = stone.count("R")
white_stone = n - red_stone

left_red_stone = stone[:red_stone].count("R")
right_white_stone = stone[white_stone:].count("W")

if left_red_stone == red_stone:
  print(0)
elif left_red_stone <= right_white_stone:
  print(red_stone-left_red_stone)
else:
  print(white_stone-right_white_stone)
n = int(input())
c = list(input())

ans = 0
x = 0
for i in range(n):
    if c[i] == "W":
        if i >= 1 and c[i-1] == "R":
            x = 0
        x += 1
    elif c[i] == "R":
        if x >= 1:
            ans += 1
            x -= 1
        else:
            pass
        
print(ans)
n = int(input())
s = input()
cur = [0, 0]
pref = []
for i in range(n):
	if s[i] == 'W':
		cur[0] += 1
	else:
		cur[1] += 1
	pref += [cur[:]]

# print(pref)

res = pref[-1][0]
for i in range(1, n):
	# print(i, res)
	rem = i - pref[i-1][1]
	ans = rem
	# print('a', ans, rem)

	rightred = pref[-1][1] - pref[i-1][1]

	if rightred >= rem:
		ans += rightred-rem
	else:
		ans += rem-rightred

	res = min(res, ans)

print(res)
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('W')].count("W"))
n = int(input())
s = input()
l_1 = []

cnt = 0
for i in s[::-1]:
    if i =='R':
        cnt += 1
    else:
        l_1.append(cnt)

l_1.reverse()

def get_res(l_1):
    for i,j in enumerate(l_1):
        if i+1 >= j:
            return j
    return len(l_1)

print(get_res(l_1))
N = int(input())
altar = input().rstrip()
alter = 0
for i in range(len(altar)-1):
  if altar[i]=='W' and altar[i+1]=='R':	alter+=1
print(alter)
n = int(input())
li_c = input()
r_index = [i for i,x in enumerate(li_c) if x=="R"]
w_index = [i for i,x in enumerate(li_c) if x=="W"]
r_num = len(r_index)

R = r_num - len([r for r in r_index if r<1])
W = 1-len([r for r in r_index if r<1])
ans = max(R, W)
for i in range(1, n):
    if li_c[i]=="R":
        R -= 1
    else:
        W += 1
    ans = min(ans, max(R, W))
print(ans)
N = int(input())
c = list(input())

if c.count('W') == 0:
	print(0)
else:
	if len(c)%2 == 0:
		print(min(c[0:len(c)//2].count('W'), c[len(c)//2:].count('R')))
	else:
		print(min(c[0:len(c)//2].count('W'), c[len(c)//2+1:].count('R')))
N = int(input())
c = input()
W = 0
R = c.count('R')
if R == 0 or W == 0:
  print(0)
  exit()

ans = N
t = 0
for i in range(N):
  if c[i] == 'W':
    W += 1
  else:
    R -= 1
  t = max(R,W)
  ans = min(ans, t)
print(ans)
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
    
print(min(C.count("R"),C.count("W")))
N = int(input())
C = []
for c in list(input()):
  a = 0
  if c == "R":
    a = 1
  C.append(a)
L = -1
R = N
cnt = 0
while L < R:
  L += 1
  if L < R:
    break
  if C[L] != 0:
    continue
  while L < R:
    R -= 1
    if L < R:
      break
    if C[R] != 1:
      continue
    cnt += 1
    break     
print(cnt)
n=int(input())
s=input()
red=s.count('r')
print(red-s[:red].count('r'))
N = int(input())

C = input()

mid = N//2

Wcount = C.count("W", 0, mid)
print(Wcount)
from bisect import bisect_right as br

n = int(input())
c = list(input())
cFixed = [x for x in c]
cFixed.sort()
ans = 0
for i in range(n):
	if c[i] != cFixed[i]:
		j = br(c,"R")-1
		c[i] = c[j]
		c[j] = "W"
		ans += 1


print(ans)
input()
l =list(input())
cw = l.count('W')
cr = l.count('R')

if cr < cw:
  ans = l[:cr].count('W')
else:
  ans = l[cw:].count('R')
print(ans)
n = int(input())
red = []
white = []
s = input()

for i in range(n):
    if s[i] == "R":
        red.append(i)
    else:
        white.append(i)

roop_min_num = min(len(red), len(white))

res = 0
for i in range(roop_min_num):
    if white[i] < red[-i]:
        res += 1
print(res)
n = int(input())
c = str(input())
# print(list(c))

import collections
a = collections.Counter(c)
t = a["W"]
# print(a)
m = min(a["W"],a["R"])
# print(m)

co = 0

for i,j in enumerate(c):
    if co >=m or i>=t:
        break
    else:

        if j == "W":
            co +=1
        # print(i,j)
        
# print(m,co)
print(min(m,co))
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]

for i in range(num):
  rw_count = r_num
  wr_count = 0
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)
from collections import Counter
N = int(input())
C = input()


l = 0
r = N - 1

cnt = 0
while l < r:
    while l < r and C[l] == 'R':
        l += 1

    while l < r and C[r] == 'W':
        r -= 1

    cnt += 1
    l += 1
    r -= 1


d = Counter(C)
min_ = min(d['W'], d['R'])
print(min(min_, cnt))
N=int(input())
S=str(input())
start=0
end=N-1
count=0
flag=0
while flag==0 and start<N:
    if S[start]=="W":
        for i in range(end,start,-1):
            if i==start+1:
                flag=1
            if S[i]=="R":
                end=i-1
                start+=1
                break
        count+=1
    else:
        start+=1
print(count)
n = int(input())
string = list(input())

def change(string):
  result = 0
  while len(string) > 0:
    while "W" in string:
      if string.pop(0) == "W":
        break
    while("R" in string):
      if string.pop(-1) == "R":
        break
    result += 1
  return result


if string.count("R") == 0 or string.count("R") == len(string):
  print(0)
elif string.index("W") not in range(0, string.count("R")):
  print(0)
else:
  print(change(string))
n = input()
s = input()
L = 0
r = len(s)

cnt = 0
while True:
    L = s.find('W')
    if L == -1:
        break
    r = s.rfind('R')
    if r == -1:
        break

    if (L > r):
        break

    s = s[L + 1:r].lstrip('R').rstrip('W')

    cnt += 1

if L != -1 and L > r:
    cnt += L + 1

print(cnt)
N = int(input())
c = list(map(str,input()))

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W > count_R:
    print(count_W)
else:
    print(count_R)
n = int(input())
c = input()

ans = 0
s = c.count('R')
e = n // 2
f = c.count('WR')

if f == 0:
    ans = 0

elif n % 2 == 0:
    sr = c.count('W',0,e)
    sw = c.count('R',e,n)

    if sr >= sw:
        ans = sr
    else:
        ans = sw

else:
    sr = c.count('W',0,e)
    sw = c.count('R',e+1,n)

    if sr >= sw:
        ans = sr
    else:
        ans = sw
    
print(ans)
N = int(input())
C = input()

w = C.count("W")
ans = min(w, N-w)

left = 0
right = N-1
while C[left] != "W" and left < N-1:
    left += 1
while C[right] != "R" and 1 <= right:
    right -= 1

m = 0
while left < right:
    while C[left] != "W" and left < N-1:
        left += 1
    while C[right] != "R" and 1 <= right:
        right -= 1
    m += 1
    left += 1
    right -= 1

print(min(ans, m))
n = int(input())
cl = input()

print(min(cl[:n//2].count('W'), cl.count('W'), cl.count('R')))
n = int(input())
s = input()
nw = len(s.replace('R',''))
nr = n - nw

tmp_w = 0
ret = n
w_left = 0
for i, c in enumerate(s):
    if c == 'W':
        w_left += 1
    r_right = nr + w_left - i - 1
    ret = min(ret, max(r_right, w_left))
print(ret)
import sys
import math

n = 8
c = list('WRWRRWWR')
ans = 0
left, right = 0, n-1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)
N=int(input())
c=input()
mid=len(c)//2
rl=c[mid:].count('R')
wf=c[:mid].count('W')
if rl<wf:
  print(rl)
else:
  print(wf)
ans = 0
n = int(input())
c = input()
print(c)
check  = c[0]
count = 0
flag=0
for i in c:
    if(i=="R"):
        count+=1
for i,k in enumerate(c):
    print(check,k)
    if check=="W" and k=="R":
        ans+=1
        check = "W"
        if i<count:
            flag+=1
    else:
        check  = k
print(ans-flag)
N = int(input())
c = list(map(str,input()))

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W < count_R:
    print(count_W)
else:
    print(count_R)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
word = input()
count = 0
res = 0
if word[0] == 'R':
    is_red = True
else:
    is_red = False

count_white = 0
count_red = 0
for i in range(N):
    if i < N // 2 and word[i] == 'W':
        count_white += 1
    elif i >= N // 2 and word[i] == 'R':
        count_red += 1

res = min(count_white, count_red)
print(res)
n = int(input())
s = input()
a = [c for c in s]
ans = 0
t1 = a.count('W')
t2 = a.count('R')
ans += (t1*t2)//n
if(ans != 0):
  ans += 1
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 r<0):
        r-=1
    if l < r:
        ans += 1
        l += 1
        r -= 1
    else:
        break

print(ans)
c = list(input())
# print(c)
R_c = c.count('R')
ans = 0
# W_c = c.count('W')
# print(R_c,W_c)
for i in range(R_c):
    if c[i]=='W':
        ans += 1
print(ans)
N = int(input())
S = input()
Cnt = 0
if S == "W"*N:
    print(0)
else:
    for i in range(N//2):
        if S[i] == "W":
            Cnt += 1
    print(Cnt)
N=int(input())
C=input()
from collections import Counter
count=Counter(C)
#print(count)
countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<countW:
        missW+=1
    if now=="R" and i>countR:
        missR+=1
# print(countR, countW)
ans=min(missW, missR)+abs(missR-missW)
print(ans)
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
    print(res)
else:
    i, j = 0, len(s)-1
    while i<=j:
        while i <= j and s[i] != 'W': i+=1
        while i <= j and s[j] != 'R':j -= 1
        if s[i] == 'W' and s[j] == 'R':
            res += 1
            i += 1
            j -= 1
    print(res)
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[:r_num].count("R"), 0))
n = int(input())
c = input()
y = (n + 1) // 2
x = 0
for i in range(y):
    if c[i] == "W":
        x += 1
print(x)
from collections import deque

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

ans = 0
while len(C)>1:
  a,b = C.popleft(), C.popleft()
  if b=="R" and a=="W":
    C.appendleft("W")
    ans += 1
  C.appendleft(b)

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

#全白
res = s.count("R")
ans = min(res,len(s)-res)
count = 0
res = 0
for i in range(n-1,-1,-1):
    if count and s[i] == "W":
        res += count
        count = 0
    elif s[i] == "R":
        count += 1

ans = min(ans,res)

print(ans)
N = int(input())
stones = input()
count_R = stones.count('R')

if N == count_R:
    answer = 0
elif N - count_R >= count_R:
    answer = count_R
else:
    answer = count_R - 1

print(answer)
from heapq import heappop
def main():
    N = int(input())
    S = input()
    W = []
    R = []
    ans = 0
    for i,s in enumerate(S):
        if s == 'W':
            W.append(i)
        else:
            R.append(-i)
    while (W and R):
        l = heappop(W)
        r = -heappop(R)
        if l <= r:
            ans += 1
        else:
            break
    print(ans)



if __name__ == "__main__":
    main()
n = int(input())
c = input()
h = (n + 1) // 2
print(min(c[:h].count('W'), c[h:].count('R')))
import sys
input = sys.stdin.readline

n = int(input())
n2 = n//2
c = input()

if c.count("R") == n:
    print(0)
elif n%2 == 0:
    cnt = c.count("R", n2, n)
    print(cnt)
else:
    cnt = c.count("R", n2+1, n)
    print(cnt)
n = int(input())
A = input()
a = A.count('W')
b = A.count('R')
c = A[:n//2]
d = A[n//2:]
e = c.count('W')
f = d.count('R')
g = max(e,f)
print(min(a,b,g))
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
for i in range(ans):
    if c[i] == 'R':
        t -= 1
ans = ans + t
print(ans)
N = int(input())
S = input()
countW = S.count('W')
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))
n = int(input())
c = list(input())

cnt = 0
start = False

for i in range(1,n-1):
    if c[i] + c[i+1] == 'WR':
        cnt+=1
        start = True
    elif c[i] + c[i+1] == 'RR' and start:
        cnt+=1
    else:
        start = False

if c[0]+c[1] == 'WR' and cnt ==0:
    cnt+=1

allw =0

for i in c:
    if i == 'W':
        allw+=1

if cnt<allw:           
    print(cnt)
else:
    print(allw)
n = int(input())
c = input()

cnt1 = 0
for v in c[: n // 2 + 1]:
    if v == "W":
        cnt1 += 1
print(cnt1)
N = int(input())
stones = list(input())
W_left = 0
W_right = 0
R = 0
count = 0

for i in range(N // 2):
    if stones[i] == 'W':
        W_left += 1

for j in reversed(range(N)):
    if stones[j] == 'R':
        if W_left > 0:
            count += 1
            W_left -= 1
        else:
            R += 1
    elif stones[j] == 'W' and R > 0:
        W_right += 1

if W_right > count:
    print(count + R)
else:
    print(count)
N=int(input())
rw=input()
count=0
s=len(rw)
i=0
j=s-1

while i<=j:
  while (rw[i]=='R' and i<s-1):
        i+=1
  while (rw[j]=='W' and j>0):
        j-=1
  if rw[i]=='W' and rw[j]=='R':
      count+=1
  i+=1
  j-=1


print(count)
N = int(input())
s = input() #s_1 s_2を分割して取得し、sに値を入れる
count_white = 0
white_flag = 0
white_renzoku = 0

count_red = 0
red_flag = 0
red_renzoku = 0
for i in range(int(N/2)):
  if s[i]=='W':
    count_white = count_white+1
  if s[N-1-i]=='R':
    count_red = count_red+1
white_irekae = count_white
red_irekae = count_red

if white_irekae >= red_irekae:
  print(white_irekae)
else:
  print(red_irekae)
N = int(input())
list=[]
list = (str(input()))
cnt = 0

for i in range(N-1):
    if list[i] == 'W':
        for j in range(N-1):
            if list[N-j-1] == 'R' and (N-j-1) > i:
                cnt +=1
                break
ans = cnt
for k in range (cnt-1):
    if list[N-k-1] == 'W':
        ans -= 1
print(ans)
N = int(input())
seq = input()

left = 0
right = N-1
c = 0

for _ in range(int(N/2)+1):
  if left >= N or right < 0:
    break
  if seq[left] == "R":
    left += 1
    continue
  if seq[right] == "W":
    right -= 1
    continue
  left += 1
  right -= 1
  c += 1

print(c)
def main():
    input()  # n
    stones = input()
    white_counter = []
    white_stones = 0
    red_stones = 0
    for color in stones:
        if color == 'W':
            white_stones += 1
        else:
            red_stones += 1
        white_counter.append(white_stones)
    print(white_counter[red_stones - 1])


if __name__ == '__main__':
    main()
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
cs = input()
r = cs.count("R")
print(cs[:r].count("R"))
n=int(input())
c=input()
n_R=c.count('R')
n_W=0
temp=n_R
ans=1000000007
for i in range(n):
    if c[i]=='W':
        n_W+=1
    else:
        n_R-=1
    temp=max(n_W,n_R)
    ans=min(temp,ans)
ans=min(ans,c.count('W'))
print(ans)
N = int(input())
S = input()

prev = S[0]
cur = 'R'
count = 0
wNum = 0
changedPoint = 0
for i in range(N-1, -1, -1):
    cur = S[i]
    if cur == 'R':
        for j in range(wNum, i):
            if S[j] == 'W':
                wNum = j + 1
                changedPoint = j
                break
        if wNum != 0:
            count += 1

    prev = cur
    if changedPoint >= i:
        break

print(count)
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
if a >= N - a:
    ans = min(N - a, B[N - a])
else:
    ans = min(a, B[a])
print(ans)
n=int(input())
a=list(input())
b=0
c=0
d=0
for i in range(-1,-(n+1),-1):
    if a[i]=="R":
        c=i+n
        break
for i in range(c,n):
    if a[i]=="W":
        d+=1
for i in range(len(a)):
    if a[i]=="W":
        b=i
        break
del a[:b]

print(min(d,a.count("R")))
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            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))
a = int(input())
s = input()
ns = a//2
new = s[0:ns]
ans = 0

for i in range(ns):
    if s[i] == 'W':
        ans += 1 

print(ans)
N=int(input())
c=list(input())
R=c.count('R')
W=0
ans=10**10
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans=min(ans,max(W,R))
print(ans)
n = int(input())
c = str(input())
# c = [1 if i == 'R' else 0 for i in input()]

cnt = 0
while 'WR' in c:
    c = c.replace('WR', 'RR', 1)
    idx = c.rfind('R')
    c = c[:idx]
    cnt += 1
print(cnt)
n = int(input())
c = input()

wi = c.find('W')
ri = c.rfind('R')

if wi == -1 or ri == -1:
    print(0)
else:
    ans = 0
    while wi < ri:
        wi += 1
        wi = c[wi:].find('W')
        ri = c[:ri].rfind('R')
        ans += 1

    print(ans, c)