peterverebics/CodeNet_Python_118 huggingface dataset:
N = int(input())
S = input()
countW = S.count('W')
if countW==0:
	print(0)
	exit()
if countW==N:
	print(0)
	exit()
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))
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)
n = int(input())
line = list(input())
if 'W' not in line or 'R' not in line:
    print(0)
else:
    a = line.index('R')
    w = line[:a].count('W')
    r = line[a+1:].count('R')
    plan1 = abs(w-r)+min(w,r)
    plan2 = min(line.count('W'),line.count('R'))
    print(min(plan1,plan2))
N=int(input())
ls=list(input())
left=0
right=N-1
count=0
while True:
  while left<N and ls[left]=='R':
    left+=1
  while right>0 and ls[right]=='W':
    right-=1
  if left>right:
    break
  left+=1
  right-=1
  count+=1
print(count)
n = int(input())
A = list(input())

if A.count('R')==n:
    print(0)
elif A.count('W')==n:
    print(0)
else:
    w = A[:0].count('W')
    r = A[0:].count('R')
    mini = min(w,r)
    for i in range(1,n-1):
        if A[i] == 'W':
            w += 1
            mini = min(w,r)
        else:
            r -= 1
            mini = min(w,r)
    print(mini)
n = int(input())
c = input()

ans = 0
for i in range(1, len(c)//2+1):
    s = "W" * i + "R" * i
    num = c.count(s)
    if num == 0:
        break
    else:
        ans += num

print(ans)
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)
import sys
n = int(input())
c = list(input())
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break
n = int(input())

stone = input()
s = list(stone)
score = 0

if 'W' not  in stone:
    print(0)
    exit()
else:
    for i in range (n-1):
        if (s[i] == "W") and (s[i+1] == "R"):
            s[i], s[i+1] = s[i+1], s[i]
            score += 1
    print(score)
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
        A[i+1] += A[i]
ans = float("inf")
for i in range(1, n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)
n=int(input())
a=list(input())

# あかのインデックス
RR=[-1]
# しろのインデックス
WW=[]

for i in range(n):
    if a[i]=='R':
        RR.append(i)
    else:
        WW.append(i)
WW.append(float('inf'))

if a.count('R')==0 or a.count('R')==n:
    print(0)
    exit()
if a.count('W')==1:
    print(1)
    exit()

for i in range(len(RR)-1):
    if RR[-2-i]<WW[i+1]:
        print(i+1)
        exit()
N = int(input())
c = input()
w = []
r = []
for i, ci in enumerate(c):
    if ci == 'W':
        w.append(i)
    if ci == 'R':
        r.append(i)
# print(w, r)
answer = 0
lenw = len(w)
lenr = len(r)
while answer < min(lenr, lenw) and w[answer] < r[-answer]:
    answer += 1
print(answer)
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)
N = int(input())
C = list(input())
CC = C[::-1]
RC = C.count('W')
WC = C.count('R')
ans = min(WC, RC)
XC = 0
if ans==0:
    print(0)
else:
    while ans > XC:
        l = C.index('W')
        r = CC.index('R')
        if l > N-1-r:
            ans = min(XC, ans)
            break
        C[l],C[N-1-r] = C[N-1-r],C[l]
        CC[r],CC[N-l-1] = CC[N-l-1],CC[r]
        XC += 1
print(ans)
N=int(input())
c=list(input())
k=0
for i in range(N):
    if c[i]!='R':
        k=i
        break
R=c[k:].count('R')
W=c[k:k+R+1].count('W')
print(W)
N = int(input())
c = list(input())
w = c.count("W")
wr = c[w:].count("W")

print(w - wr)
n=int(input())
c=list(input())

rc=c.count('R')
mini=min(rc,n-rc)
for i in range(n):
  if c[i]=='R':
    rc-=1
  
  mini=min(mini,max(rc,n-rc))
  
print(mini)
from itertools import accumulate
N = int(input())
S = list(input())
W = [0]*N
R = [0]*N
ans = N

for i in range(N):
    if S[i] == "W":
        W[i] = 1
    else:
        R[i] = 1
R.reverse()
R = list(accumulate(R))
W = list(accumulate(W))
if R[0] == 0 or W[N-1] == 0:
    ans = 0
else:
    sakai = R[N-1]
    ans = max(W[sakai-1], R[N-sakai-1])
print(ans)
n = int(input())
c = input()
cnt = 0
for i in range(n):
    if c[i] == 'W' and i > c.find('R') and c.find('R') != -1:
        r = c.find('R')
        l = list(c)
        l[i] = 'R'
        l[r] = 'W'
        cnt += 1
        c = ''.join(l)

print(cnt)
N = int(input())
c = list(input())
count = 0

if len(c) % 2 == 1:
  c.append('W')
l = c[0:len(c)//2]
if c.count('W') == 0 or c.count('R') == 0:
  print(0)
else:
  print(l.count('W'))
n = int(input())
c = input()
lists = list(c)
cnt = 0
while 1:
    if lists[cnt] == "W":
        cnt += 1
        if cnt == len(lists):
            break
    else:
        break
number = 0
for i in range(len(lists) - cnt):
    if lists[i + cnt] == "W":
        number += 1
print(number)
n = int(input())
c = input()
count = 0
for i in range(n//2):
  if 'W' == c[i]:
    count += 1
print(count)
n = int(input())
c = list(input())
w = c.count('W')
w2 = c[:w].count('W')
r2 = c[w:].count('R')
print(min(w2,r2))
from collections import Counter
import copy 
n=int(input())
c=input()
cl=copy.deepcopy(c)
cl=list(cl)
d=Counter(c)
ans=0


if d["R"]==0 or d["W"]==0:
  print(0)
  exit()
swap=0
for i in range(n):
  indexes = [j for j, x in enumerate(cl) if x == "R"]
  if cl[i]=="W":
    cl[indexes[-1]]="W"
    cl[i]="R"
    swap+=1
  else:
    break
  if swap>=n//2:
    break


d=Counter(cl[cl.index("W"):])
ans+=swap+d["R"]
print(ans)
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 = B[N - a]
else:
    ans = B[a]
print(ans)
N = int(input())
C = input()
A = []
for c in C:
    if c=='W':
        A.append(0)
    else:
        A.append(1)
l = 0
r = N - 1
ans = 0
while l < r:
    if not A[l] and A[r]:
        ans+=1
        l +=1
        r-=1
    elif not C[l]:
        r-=1
    elif C[r]:
        l+=1
print(ans)
n = int(input())
s = list(input())
ans = 0
right = n-1
for i in range(n//2+1):
    if s[i] == "W":
        while right >= i:
            if s[right] == "R":
                s[right] = "W"
                s[i] = "R"
                ans += 1
                right -= 1
                break
            else:
                right -= 1


print(ans)
N = int(input().strip())
C = [c for c in input().strip()]

if "W" not in C or "R" not in C:
    print(0)
    import sys; sys.exit(0)

cnt = 0

i = 0
j = len(C) - 1
while i < j:
    while C[i] != "W":
        i += 1
    while C[j] != "R":
        j -= 1
    cnt += 1
    C[i] = "R"
    C[j] = "W"
    i += 1
    j -= 1

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

if n % 2 == 0:
  half = int(n / 2)
  odd =0
else:
  half = int((n-1) / 2)
  odd = 1
pre_w_num = 0
for i in range(half):
  if c[i] == "W":
    pre_w_num = pre_w_num + 1
post_r_num = 0
for j in range(half):
  if c[-1 *(j+1)] == "R":
    post_r_num = post_r_num +1
if pre_w_num >= post_r_num:
  ans = pre_w_num
else:
  ans = post_r_num
if odd == 1:
  print(c[half])
  if c[half] == 'R':
    ans = ans +1
print(ans)
n = int(input())
stones = list(input())
w_num = 0
r_num = 0
for i in stones:
    if i == 'W':
        w_num += 1
    else:
        r_num += 1
goal = 'R' * w_num + 'W' * r_num

index = 0
poplist = list()
for i in stones:
    if i == goal[index]:
        poplist.append(index)
    index += 1
for i in sorted(poplist, reverse=True):
    stones.pop(i)
w_num = 0
r_num = 0
for i in stones:
    if i == 'W':
        w_num += 1
    else:
        r_num += 1
print(min(w_num, r_num))
n = int(input())
c = list(input())

if n % 2 == 0:
  half = int(n / 2)
else:
  half = int((n-1) / 2)
pre_w_num = 0
for i in range(half):
  if c[i] == "W":
    pre_w_num = pre_w_num + 1
post_r_num = 0
for j in range(half):
  if c[-1 *(j+1)] == "R":
    post_r_num = post_r_num +1
if pre_w_num <= post_r_num:
  ans = pre_w_num
else:
  ans = post_r_num
print(ans)
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[:rc].count('W'), c[wc-1:].count('R'), n - rc, n-wc))
N = int(input())
S = input()
A = int(S.count("R"))
if A == N:
  print(A)
  exit()
s = S[:A]
B = int(s.count("R"))
print(A-B)
n = int(input())
s = list(input())

if len(set(s)) == 1:
    print(0)
elif n % 2 == 0:
    r = s[:n//2].count('W')
    w = s[n//2:].count('R')
    print(max(r, w))
else:
    r = s[:n//2].count('W')
    w = s[n//2+1:].count('R')
    print(max(r, w))
s = int(input())
n = input()
str_list = list(n)
w_cnt = str_list.count('W')
r_cnt = str_list.count('R')
if w_cnt == 0 or r_cnt == 0:
    print(0)
else:
    w_result = str_list[w_cnt:]
    r_result = str_list[:r_cnt]
    r = w_result.count('R')
    w = r_result.count('W')
    if w <= r:
        print(w)
    else:
        print(r)
N = int(input())
c = input()

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


i = 0
j = N - 1

count = 0

while (True):
    while (c[i] != "W"):
        i = i + 1

    while (c[j] != "R"):
        j = j - 1
    count += 1
    i = i + 1
    j = j - 1
    if (i > j or i == j or i >= N or j < 0):
        break

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

if "WR" not in C:
  print(0)
elif C[:2]=="WR":
  print(C.count("R")-1)
else:
  print(C.count("R"))
N = int(input())
C = input()

left = N - 1

count = 0

for right in range(N):
    if right == left:
        break

    if C[right] == 'W':
        while C[left] == 'W' and right <= left:
            left -= 1
        if C[left] == 'W':
            break
        count += 1
        left -= 1
print(count)
N = int(input())
C = input()

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

ans = N
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 = input()
s1 = [0]
for i in range(n):
    if c[i] == 'W':
        s1.append(s1[-1] + 1)
    else:
        s1.append(s1[-1])

s2 = [0]
for i in range(n):
    if c[i] == 'R':
        s2.append(s2[-1] + 1)
    else:
        s2.append(s2[-1])
s2.reverse()
ans = 1001001001
for i in range(n+1):
    ans = min(ans, s1[i] + s2[i])
print(ans)
N = int(input())
RW = input()

j = N-1
count = 0
for i in range(N):
    if RW[i]=='W':
        while i<j:
            if RW[j]=='R':
                count += 1
                break
            j -= 1

print(count)
n = int(input())
k = list(input())
ws = 0
rs = 0
moves = 0
for i in range(0, n-1):
    if k[i] == "W":
        ws += 1
    else :
        rs += 1
if ws == 0 or rs == 0:
    print(0)
if rs < ws:
    for i in range(0, rs-1):
        if k[i] == "W":
            moves += 1
else:
    for i in range(n-1, ws):
        if k[i] == "R":
            moves += 1
print(moves)
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c[i] == "R":
        for j in range(len(c)-1, i, -1):
            if c[j] =="W":
                c[i], c[j] = c[j], c[i]
                cou += 1
                break
print(cou)
N = int(input())
c = input()
tmp = 0
ans = 0
count = 0
if(N % 2 == 0):
    tmp = N - (N//2) + 1
else:
    tmp = N - (N//2)
for i in range(N):
    if(c[i] == "W"):
        count += 1
if(count == N):
    print("0")
    exit()
for i in range(tmp):
    if(c[i] == "W"):
        ans += 1
print(str(ans))
n = int(input())
c = input()

ans = 0

l = 0
r = n-1

lsl = 0
lsr = 0

while l < n:
  lc = c[l]
  if lc == 'W':
    while 0 <= r:
      rc = c[r]
      if rc == 'R' and l < r:
        ans += 1
        lsl = l
        lsr = r
        r -= 1
        break
      r -= 1
  l += 1
#print('mid : ', ans, lsl, lsr)
if (lsr - lsl) > 1:
  for i in range(lsl+1, lsr):
    if c[i] == 'W':
      ans += 1
print(ans)
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i <= b:
    r+=1
  if c[i] == 1 and i > b:
    w+=1
 

print(max(w,r))
n=int(input())
c=list(input())
ans=0
for i in range(n//2):
    if c[i]=="W" and c[-i-1]=="R":
        ans+=1
    elif c[i]==c[-i+1]=="R":
        continue
    else:
        ans+=c[i:-i-1].count("R")
        break
print(ans)
n = int( input() )
c = list( input() )

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

print( ans )
# -*- coding: utf-8 -*-
import math
n = int(input())
color = list(input())

i = 0
j = n-1
count = 0

while(i<j):
  found1 = 0
  found2 = 0
  for k in range(n-1-i):
    if color[i+k] == 'W':
      i = i+k+1
      found1 = 1
      break
  for k in range(j):
    if color[j-k] == 'R':
      j = j-k-1
      found2 = 1
      break

  if found1*found2 == 0:
    break
  else:
    count += 1
      

print(count)
N=int(input())
white=0
red=0
W=list(str(input()))
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
if white==0 or red==0:
  print("0")
  exit()
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())
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(cnt):
        if list[N-cnt-1]=="R":
            ans +=1

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


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

wl = 0
for i in range(N):
  if S[i] == "W":
    wl += 1

rl = N - wl
    
l = 0
if N % 2 == 0:
  for i in range(N//2):
    if S[i] == "W":
      l += 1
else:
  for i in range(N//2+1):
    if S[i] == "W":
      l += 1

print(min([wl, rl, l, rl-(wl-l)]))
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
ans = B[N - a - 1]
print(ans)
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while i != j and i < j:
    if d[i] == 'W':
        while d[j] != 'R' and i < j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)
n = int(input())
c = list(input())
w = c.count('W')
w2 = c[:w].count('W')
print(w2)
n = int(input())
s = input()
w = s.count('W')
an1 = s[-w:].count('R')
an2 = s[:w].count('R')

print(min(an1, an2))
n = int(input())
moji = input()
c = []
for i in range(len(moji)):
    c.append(moji[i])
j = len(c)-1
count = 0
for i in range(len(c)//2):
    if c[i] == "W":  # and c[i+1] == "R":
        while j >= 0:
            if c[j] == "R":
                c[i] = "R"
                c[j] = "W"
                count += 1
                break
            j -= 1
    # print(c)

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

le = len(c)
if le % 2 == 0:
    i = le // 2
else:
    i = le // 2 + 1


ans = c[:i].count("W")
print(ans)
N = int(input())
C = input()

wr = 0
wflag = 0

wsum = 0
wtemp = 0
for c in C:
    if c == "W":
        wtemp += 1
        wflag = 1
    elif wflag:
        wr += 1
        wsum += wtemp
        wtemp = 0
        wflag = 0        

print(wsum-wr//2)
n = int(input())
s = input()
c = 0
tmp = 0
r = 0
for i in range(n-1):
  if s[i] == "W":
    tmp += 1
    if s[i+1] == "R":
      c += tmp
      r += 1
      tmp = 0
print(c - r//2)
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    li[i] = "R"
    li[j] = "W"
    ans += 1
  print(ans)


if __name__ == '__main__':
  main()
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, N - 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())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
    A[i+1] += A[i]
ans = float("inf")
for i in range(1, n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)
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 = B[N - a - 1]
else:
    ans = B[N - a - 1] - a
print(ans)
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[:rc].count('W'), c[wc:].count('R'), n - wc, n - rc))
import sys

N = int(input())
C = list(input())

count = 0

i = 0
j = len(C) - 1

if not 'R' in C or not 'W' in C:
    print(0)
    sys.exit()

while i + 1 <= j - 1:
    while C[i] == 'R':
        i += 1
    while C[j] == 'W':
        j -= 1
    C[i], C[j] = C[j], C[i]
    count += 1

print(count)
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

    s = s[L + 1:r]

    cnt += 1

if L != -1:
    cnt += L + 1

print(cnt)
import math
n = int(input())
# c = list(input().split())
c = input()
whiteCount = 0

for i in range(math.ceil(n/2)):
    if c[i] == "W":
        whiteCount += 1
print(whiteCount)
import collections as c
n = int(input())
s = list(input())
cnt = 0

while c.Counter(s[:cnt+1])["W"]<c.Counter(s[cnt:])["R"]:
    cnt += 1
    
print(cnt)
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(n - 1):
  if s[i] == 'W' and s[i + 1] == 'R':
    ans += 1
print(ans)
N = int(input())
tmpN = N
C = input()
if N % 2 == 1:
  N += 1
N = int(N / 2)
result = C.count('R',N)

if C.count('R') == tmpN:
  print('0')
else:
  print(result)
N = int(input())
c = input()
ans = 0
fs = 0
ls = N - 1
for _ in range(N):
    for i in c[fs:ls]:
        if i == 'W':
            break
        fs += 1
    for i  in c[fs:ls:-1]:
        if i == 'R':
            break
        ls -= 1
    if fs >= ls:
        break
    ans += 1
    fs += 1
    ls -= 1
    #print(c[fs:ls] + 1)
    if (ls - fs) < 1:
        break
print(ans)
import collections
n = int(input())
c = list(input())
C = collections.Counter(c)
C_2 = collections.Counter(c[:n//2])
tmp_1 = min(C['W'],C['R'])
tmp_2 = min(C_2['W'],C['R']-C_2['R'])
ans = min(tmp_1,tmp_2)
print(ans)
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2),N):
    if C[i] == 'R':
        R += 1
if W>=R:
    print(R)
else:
    print(W)
import math
n=int(input())
k=list(input())
if len(set(k))==1:
    print("0")
print(round(math.log2(n)))
N = int(input())
C = list(map(str, input()))

W = N - C.count('W')
R = N - C.count('R')

CH = R - C[:R].count('R')
print(min(W,R, CH))
N = int(input())
C = input()

if C[0]=="W":
  w = C.find("R")
  r = C[w:].find("W")
  t = C.count("R")
  
  if w<=t-r:
    print(t-w)
  else:
    print(t)
    
else:
  r1 = C.find("W")
  w  = C[r1:].find("R")
  r2 = C[r1+w:].find("W")
  t = C.count("R")
  
  if w<=t-r1-r2:
    print(t-r1-r2)
  else:
    print(t)
N = int(input())
C = input()

a = N // 2

if N & 2 == 0:
    right_W = C[:a].count ('W')
else:
    right_W = C[:a+1].count('W')
left_R = C[a:].count ('R')

ans = min(right_W, left_R)

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

firstR=S.find('R')
Sother=S[firstR+1:]
otherR=Sother.count('R')
print(firstR+otherR-1)
n = int(input())

s = list(input())

count_red = s.count('R')
count_white = 0

A = []
for i in range(n):
    if s[i] == 'R':
        count_red -= 1
    if s[i] == 'W':
        count_white += 1
    A.append(max(count_red, count_white))
print(min(A))
N = int(input().strip())
S = input().strip()
if S.count('W') == 0 or S.count('R') == 0:
    print(0)
else:
    count = 0
    
    SS = S[:len(S)//2]
    A = sorted(S)[:len(S)//2]
    
    for ss,a in zip(SS,A):
        if ss != a:
            count+=1
    print(count)
N = int(input())
C = input()

a = N // 2

right_W = C[:a].count ('W')
left_R = C[a:].count ('R')

ans = min(right_W, left_R)

print(ans)
a = int(input())
b = input()
b.count('R')
c = b.find('R')
d =b[c+1:].count('R')
if b.count('W') == 0:
    print(0)
elif b.find('R') < b.find('W'):
    print(0)
elif (a - b.find('R'))==b.count('R') and b.count('R') == b.count('W'):
    print(b.find('R'))
else:
    print(c + (d-c))
n = int(input())
c = input()

# 1文字ずつのListに変換
list_c = ','.join(map(lambda x: '"{}"'.format(x), list(c)))

# print(list_c)

all_change = 0

if list_c.count('W') < list_c.count('R') :
    all_change = list_c.count('W')
else :
    all_change = list_c.count('R')

print(all_change)
n = input()
wr = input()

j = len(wr)-1
ans = 0
for i in range(0,len(wr)):
  if wr[i] == 'W':
    while j>=1:
      if wr[j] == 'R':
        ans+=1
        break
      j-=1
print(ans)
from collections import deque
n = int(input())
c = input()
d = deque()
a = 0; b = 0
for i in range(n):
    d.append(c[i])
for _ in range(len(d)):
    if d[0] == "R":
        d.popleft()
    else:
        break
for _ in range(len(d)):
    if d[-1] == "W":
        d.pop()
    else:
        break
for i in range((len(d)+1)//2):
    if d[-i-1] == "R": a += 1
for i in range((len(d)+1)//2):
    if d[i] == "W": b += 1
print(min(a, b))
X = input()
count_w, n, count = X.count('W'), len(X), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    C = input()
    sum_r, sum_w = 0, 0
    for c in C:
        if c == 'R':
            sum_r += 1
    ans = 10000000
    for i in range(n-1):
        if C[i] == 'W':
            sum_w += 1
        else:
            sum_r -= 1
        if C[i:i+2] == "WR":
            ans = min(ans, max(sum_w, sum_r))
    print(ans)

if __name__=='__main__':
    main()
n=int(input())
s=[c for c in input()]

left=0
right=n-1
ans=0
while left<n and s[left]=='W':
    while left<right and s[right]=='W':
        right-=1
    
    if left==right:
        break

    s[left]='R'
    s[right]='W'
    ans+=1
    left+=1

while left<n and s[left]=='R':
    left+=1

for i in range(left,n-1):
    if s[i]=='W' and s[i+1]=='R':
        s[left]='R'
        s[i+1]='W'
        left+=1
        ans+=1

print(ans)
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[rc-1:].count('R'), c[:wc].count('W'), n-rc, n-wc))
n = int(input())
c = input()
r = 0
w = 0
l = 0
ans = 0
for i in range(n):
    if c[i] == "W":
        w += 1
    else:
        r += 1
        if i < n / 2:
            l += 1
res = 0
if r == 0 or w == 0:
    print(0)
    exit()
elif w < r:
    ans += r - w
    r = w

ans += r - l
print(ans)
N = int(input())
C = list(input())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
print(C1)
print(C2)
count = 0
if (C1.count('W') == C2.count('R')):   #左右対象のとき
    count = C1.count('W')
else:
    count = C.count('W')
print(count)
import sys
N = int(input())
c = list(input())
#print(c)
myr_cnt = c.count('R')
if myr_cnt == 0:
    print(1)
    sys.exit()
#print(myr_cnt)
myw_cnt = 0
for i in range(myr_cnt):
    if c[i] == 'W':
        myw_cnt += 1
print(myw_cnt)
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] + 'W' + c[idx+1:]
    cnt += 1
print(cnt)
n = int(input())
s = input()
wc = s[:n//2].count('W')
rc = s[n//2:].count('N')
# print(wc)
# print(rc)
print(max(wc, rc))