peterverebics/CodeNet_Python_118 huggingface dataset:
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<N-countW:
        missW+=1
    if now=="R" and i>=N-countR:
        missR+=1
# print(countR, countW)
X=min(missW, missR)

ans=min(missW, missR)+abs(missR-missW)

print(ans)
N = int(input())
c = list(input())
pre = c[0:N//2]
suf = c[N//2:N]
ans = 0

pre_cnt = pre.count('W')
suf_cnt = suf.count('R')

ans = pre_cnt and suf_cnt

print(ans)
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
c = S()
ans = 0
if set(c)==1:
    print(0)
    exit()
temp1,temp2 = 0,N-1
while 1:
    if c[temp1]=='R':
        temp1 += 1
    else:
        if c[temp2]=='W':
            temp2 -= 1
    if temp1>=temp2:
        break
    ans += 1
    temp1 += 1
    temp2 -= 1
print(ans)
n = int(input())
c = input()
na = len(c)
red = 0
whi = 0

cou_start = 0
cou = 0
for i in reversed(range(0,na)):
    if c[i] == "W":
        whi += 1
        if cou_start == 1:
            cou += 1
    else:
        red += 1
        
    #print(red,whi,cou)
    
    if red >= 2 and whi >= 1:
        cou_start=1
        

pri = min(whi,red)
if cou != 0:
	pri = min(cou,pri)
  
print(pri)
N = int(input())
data = input()
intdata = []
ans = 0
for d in data:
  if d == "R":
    intdata.append(0)
  else:
    intdata.append(1)

sortdata = sorted(intdata)

if len(intdata) % 2 == 0:
  amari = 0
else:
  amari = 1

for i in range(int(len(intdata)/2) + amari):
  if intdata[i] != sortdata[i]:
    ans += 1

print(ans)
k=int(input())
n=0
a=0
ss=0
if k%7==0:
  print(1)
elif k%2==0:
  print(-1)
elif k%5==0:
  print(-1)
else:
  while a==0 and n<=1000000:
    n+=1
    ss=10*(ss%k)+1
    if ss%k==0:
      a=1
  if a==1:
    print(n)
  else:
    print(-1)
def dist(s, r):
  wcount = 0
  for i in range(r):
    wcount += (s[i] == "W")
  rcount = 0
  for i in range(r, n):
    rcount += (s[i] == "R")
  return max(wcount, rcount)

n = int(input())
s = input()

minstep = n
for i in range(n):
  minstep = min(dist(s, i), minstep)

print(minstep)
N = int(input())
c = list(input())
num_r = 0
for ci in c:
    if ci == 'R':
        num_r += 1
ans = 0
if num_r != N:
    for i in range(num_r+1):
        if c[i] == 'W':
            ans += 1
print(ans)
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('L')

    cnt += 1

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

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

count = N

numW = S[:0].count('W')
numR = S[0:].count('R')

if(numW == N):
    print(0)

else:
    for i in range(N):
        if(S[i] == 'W'):
            numW += 1
        else:
            numR -= 1

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

    print(count)
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(b)
    ans += 1
  C.appendleft(b)

print(ans)
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)
from re import match

n  = int(input())
ci = input()

if len(match('R*W*', ci).group(0)) == n:
    print(0)
    exit()

fst = ci.find('R')
rng = len(match('^R+', ci[fst:]).group(0))
Rs  = ci.count('R')
Ws  = n - Rs

'''
first <= Ws
'''

Rs2 = Rs - fst
Ws2 = Ws - fst

if Rs2 == 0:
    print(fst)

elif Ws2 == 0:
    print(Rs)

else:
    print(fst + Rs2 - rng)
N = input()
# C = list(map(lambda x: x == 'W', list(input())))
C = list(input())

countR = 0
countI = 0
for n, c in enumerate(C):
    if countI == 0 and c == 'W' :
        countI = n
    if c == 'W' :
        countR += 1

RZ = len(C) - countI +1
RZW = RZ - countR
if countR == 0 :
    RZW = 0
print(RZW)
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)
N = int(input())
C = input()

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

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

#print(R)
#print(W)
#print(R_)

ans = N

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

    while True:
        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') + 1 != len(c):
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1
        else:
            return count + 1


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

print(checkFunction(c))
N = int(input())
C=list(input())
X=0
Y=0
for i in range(N):
  if C[i]=='W':
    for ii in range(Y, N-i-Y):
      if C[N-1-ii]=='R':
        C[i]='R'
        C[N-1-ii]='W'
        X=X+1
        Y=ii
        break
  if i+Y==N-1:
    break
print(X)
N = int(input())
c = input()
W = 0
R = c.count('R')
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)
def checkFunction(c):
    count = 0

    while True:
        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') + 1 != len(c):
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1
        return count + 1


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

print(checkFunction(c))
N = int(input())
c = input()
W = 0
R = 0

for x in c:
  if x=='R':
    R += 1
    
ans = R
for x in c:
  if c=='W':
    W += 1
  else:
    R -= 1
    
  ans = min(ans,max(R,W))
  
print(ans)
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.rfind('WR')
        wnum = a[rightmostW:].count('R')
        print(wnum + 1)

if __name__ == '__main__':
    main()
N = int(input())
c= list(input()) 
if c.count('R') == N:
	print(0)
	exit()
div=0
addcnt = 0
if N %2 == 1:
	div =1
	Q = c[int(N/2)]
	# print(Q)
	if Q == 'R':
		addcnt +=1
		# print('QQQ!')
clist_L = c[:int(N/2)]
clist_R = c[int(N/2)+div:]
Lcnt = clist_L.count('W')
Rcnt = clist_R.count('R')
if Lcnt - Rcnt <=0:
	print(Rcnt)
else:
	print(Lcnt-Rcnt+addcnt)
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+1)
N = int(input())
C=list(input())
X=0
for i in range(N):
  if C[i]=='W':
    for ii in range(N-1-i):
      if C[ii]=='R':
        C[i]='R'
        C[ii]='w'
        X=X+1
        break
print(X)
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = input()
r = seq.count('R')
ans = 0
cnt = 0
for i in xrange(n):
    if seq[i] == 'R':
        cnt += 1
    else:
        ans += 1
        cnt += 1
    if cnt == r:
        break
print(ans)
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 = list(input())
W = 0
R = 0
for i in range(int(N/2)+1):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W>R:
    print(R)
else:
    print(W)
import math

#import sympy

#n,d=map(int,input().split())
n=int(input())
c=input()
rnum=c[0:int(len(c)/2)].count("W")
wnum=c[int(len(c)/2):-1].count("R")
lennum=int(len(c)/2)
print(max(rnum,wnum))
n = int(input())
s = input()
cnt = 0
for i in range(n//2):
  if s[i]=='W': cnt+=1
print(cnt)
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 _ in range(len(d)//2):
    if d[-1] == "R": a += 1
    d.pop()
for _ in range(len(d)):
    if d[0] == "W": b += 1
    d.popleft()
print(min(a, b))
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[:wc]
    wwc = wc-s.count('R')
    if wwc <= rc:
      print(wwc)
    else:
      print(rc)
n = int(input())
c = input()

c1 = 0
for v in c[: n // 2]:
    if v == "W":
        c1 += 1
c2 = 0
for v in c[n // 2 :]:
    if v == "R":
        c2 += 1
c3, c4 = 0, 0
for v in c:
    if v == "W":
        c3 += 1
    else:
        c4 += 1
print(min(c1, c2, c3, c4))
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
s = input().strip()
l,r = 0,n-1
ct = 0
if s.count('W') == 0:
    print(ct)
    exit()
while l < r:
    while s[l] == 'R':
        if l >= r:
            break
        l += 1
    while s[r] == 'W':
        if l >= r:
            break
        r -= 1
    ct += 1
    l += 1
    r -= 1
print(ct)
n = int(input())
if n%2==0 or n%5==0:
    print(-1)
    exit()

ans,c = 0,0

while 1:
    c+=1
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            break
    ans = ans//10
    if ans==0:
        break
print(c)
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
ans = 0
for i in range(n - 1):
  idx = n - 1 - i
  if s[idx] == 'W' and s[idx + 1] == 'R':
    ans += 1
    s[idx] = 'R'
print(ans)
N = int(input())
C = input()
C = C[:len(C)//2]
print(C.count("W"))
n = int(input())
c = list(input())
w = 0
r = c.count("R")
ans = n
for i in range(n) :
    if c[i] == "W" :
        w += 1
    else :
        r -= 1
    if ans >= max(w,r) :
        ans = max(w,r)

print(ans)
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-4:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)
N = int(input())
A = input()
a = A.count('W')
b = A.count('R')
c = 'R'*a+'W'*b
n = 0
m = 0
for i in range(N):
  if A[i] != c[i]:
    if A[i] == 'W':
      n+=1
    if A[i] == 'R':
      m+=1
e = min(n,m)+abs(n-m)
print(min(a,b,e))
n = int(input())
m = input()
runlength = []
count = 1
for i in range(len(m)):
    if i == n-1:
        runlength.append([m[i],count])
        break
    if m[i] ==  m[i+1]:
        count += 1
    elif m[i] != m[i+1]:
        runlength.append([m[i],count])
        count = 1


count = 0


for i,j in runlength:
    if i == "W":
        count += j

count -= 1
print(count)
# -*- coding: utf-8 -*-
N = int(input())
c = input()

#t = c.count("R")
print(c.count("R")-c[:2].count("R"))
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)
import sys
input=sys.stdin.readline

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

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

temp=0
for i in c:
    if i=='R':
        temp+=1
temp=min(temp,n-temp)
ans=min(ans,temp)
k = int(input())
s = input()

res = 0
j = k - 1
for i in range(k//2):
    if s[i] == 'W' and s[j] == 'R':
        res += 1
        j -= 1
    elif s[i] == 'W' and s[j] == 'W':    
        res += 1
        j -= 1

if k % 2 and s[k//2]:res += 1
print(res)
input()
s = input()
pref = 0
total = s.count('R')
res = int(1e9)
for i in range(total):
    pref += s[i] == 'R'
    res = min(res, total - pref)
print(res)
n=int(input())
c=list(input())
count=0

for i in range(n):
    if c[i]=='W':
        for j in range(n-1,i+1,-1):
            if c[j]=='R':
                c[j]='W'
                count+=1
print(count)
N=int(input())
S= list(input())
W_count=S.count('W')
R_count=S.count('R')
if((W_count==0) or (R_count==0)):
    print(0)
else:
    if(W_count==R_count):
        print(R_count-S[:len(S)//2].count('R'))
    else:
        if(len(S)%2==0):
            print(S[:len(S)//2].count('R')-S[:len(S)//2].count('W'))
        else:
            print(S[:len(S)//2+1].count('R')-S[:len(S)//2+1].count('W'))
n = int(input())
C = input()
t = sum(c == 'R' for c in C)
print(sum(c == 'R' for c in C[:t]))
N = int(input())
s = input()

times = len(s)
R, L = 0, s.count("R")
for c in s:
    if c == "W":
        R += 1
    else:
        L -= 1
    if times > max(R, L):
        times = max(R, L)
print(times)
n=int(input())
c=list(input())

rall=c.count('R')
wlef=c[:rall+1].count('W')

print(wlef)
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 = c[wi:].find('W') + wi + 1
        ri = c[:ri].rfind('R')
        ans += 1

    print(ans)
N = int(input())
C=list(input())
X=0
Y=0
for i in range(N):
  if C[i]=='W':
    for ii in range(Y, N-i-Y):
      if C[N-1-ii]=='R':
        C[i]='R'
        C[N-1-ii]='W'
        X=X+1
        Y=ii
        break
  if i+Y==N-2:
    break
print(X)
N = int(input())
c = list(input())
print(c)
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())
str_list = list(input())
flag = 0

if (str_list[0] == 'W' and str_list[1] == 'R') and str_list[n-1] == 'R':
    str_list[0] = 'R'
    str_list[n-1] = 'W'
    flag += 1
elif (str_list[0] == 'W' and str_list[1] == 'W') and str_list[n-1] == 'R':
    str_list[0] = 'R'
    str_list[n-1] = 'W'
    flag += 1

for i in range(n-1):
    if str_list[i] == 'W' and str_list[i+1] == 'R':
        str_list[i+1] = 'W'
        flag += 1

print(flag)
n=int(input())
s=input()
print(s[:n//2].count('W'))
N = int(input())
S = input()

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

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

a = S[:r+1].count('W')

print(a)
n = int(input())
S = list(input().split())
str_list = []
for s in S:
  str_list.append(list(s))
count = 0
for i in range(1, n+1):
  if str_list[0][-i] == 'R':
    count += 1
  else:
    break
if n % 2 == 0:
  b = n // 2
else:
  b = (n + 1) // 2
c = str_list[0][:b].count('W')
print(max(count, c))
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
for i in range(N):
    if C[-i]=="R":
        C=C[:-i]
        break    
    

print(min(C.count("R"),C.count("W")))
from copy import deepcopy
N = int(input())
c = list(input())
n = 0
OK = False
while not OK:
    ni = 0
    OK = True
    for i in range(N - 1):
        if c[i] == 'W' and c[i + 1] == 'R':
            c[i] = 'R'
            ni += 1
            OK = False
    ni = (ni + 1) // 2
    n += ni
print(n)
n = int(input())
c = input()

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

harf = round(len(c)/2)
wCnt = c[:harf].count('W')
rCnt = c[-harf:].count('R')
print(wCnt if wCnt >= rCnt else rCnt)
a=int(input())
b=input()
c=int(a/2)
d=0
e=a-1
i=0
while i+1<e:
    if b[i]=='W':
        for j in range(i,e+1)[::-1]:
            if b[j]=='R':
                d=d+1
                e=j-1
                break
    i=i+1
print(d)
def solve():
    N = int(input())
    C = input()

    left = 0
    right = len(C) -1
    while left < right and C[left] == 'R':
        left += 1
    while left < right and C[right] == 'W':
        right -= 1

    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while left < right and C[right] == 'W':
            right -= 1
        ans += 1
        left += 1
        right -= 1
    print(ans)

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

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
if N%2!=0 and C[mid-1] == "W":
  Wcount -= 1
print(Wcount)
#!/usr/bin/env python3

# from numba import njit

# input = stdin.readline

# @njit
def solve(n,s):
  flag = False
  whiteCount = 0
  for i in range(n-1,-1,-1):
    if s[i] == "R":
      flag = True
    if s[i] == "W" and flag:
      whiteCount += 1
  res = 0
  for i in range(n):
    if s[n-i-1] == "W" and i+1 > whiteCount:
      res += 1
  
  return res



def main():
  N = int(input())
  s = input()
  print(solve(N,s))
  return

if __name__ == '__main__':
  main()
n = input()
wr = input()

j = len(wr)
ans = 0
for i in range(0,len(wr)):
  if wr[i] == 'W':
    while j>=1:
      j-=1
      if wr[j] == 'R':
        ans+=1
        break
print(ans)
N=int(input())
C=list(input())
ans=0

w=0
r=0
for i in range(N//2):
    print(i,C[i])
    if C[i]=='W':
        w+=1
    if C[i-2]=='R':
        r+=1

if w==0 or r==0:
    ans=0
else:
    ans=max(w,r)

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

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
if C[mid-1] == "W":
  Wcount -= 1
print(Wcount)
n=int(input())
s=input()
if s.count('R')==0 or s.count('W')==0:
    print(0)
else:
    w=s.index('W')
    i=w
    while(i<len(s) and s[i]=='W'):
        i+=1
    a= i-w+1
    if i==len(s):
        print(0)
    else:
        b=s[i:].count('R')
        if a<b:
            print(b-1)
        else:
            print(b)
N = int(input())
#stones = list(input())
stones = input()
print(stones)
a = stones.count('W')
b = stones.count('R')

left_side =stones.count('W', 0, a)
print(left_side)
# !/usr/bin/python3


def solve(a, n):
    count = 0

    end = n-1
    for i in range(n):
        if a[i] == 'W':
            for j in range(end, i-1, -1):
                if i == j: return count
                if a[j] == 'R':
                    count += 1
                    end -= 1
                    break

    return count


if __name__ == "__main__":
    n = int(input())
    a = input()

    print(solve(a, n))
n = int(input())
c = list(input())
ans = 0
if c.count('W') == n or c.count('W') == 0:
    ans =0 
else:
    if n % 2 == 0:
        a = n //2
        c_for = c[:a]
        c_back = c[a:]
        ans = max(c_for.count('W'),c_back.count('R'))
        
    else:
        a = n//2
        a = n //2
        c_for = c[:a]
        c_back = c[a+1:]
        ans = max(c_for.count('W'),c_back.count('R'))
print(ans)
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 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
    print(reds, whites)
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()
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(counter["R"]-1)
    else:
        print(counter["R"])
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[sakai])
print(ans)
import re
N = int(input())
C = input()
wLen = len(C.replace('R', ''))
rLen = len(C.replace('W', ''))
if wLen == 0 or rLen == 0:
  print(0)

else:
  tmp = C
  tmpRes = min(wLen, rLen)
  for i in range(tmpRes):
    tmp = re.sub('^R*', '', tmp)
    tmp = re.sub('W*$', '', tmp)
    tmpLen = len(tmp) - max(len(re.sub('^W*', '', tmp)), len(re.sub('R*$', '', tmp)))
    tmp = tmp[int(tmpLen): int(len(tmp) - tmpLen)]
    if len(tmp) == 0:
      tmpRes = i + 1
      break
  print(tmpRes)
N = int(input())
C = list(input())
lW = 0
rW = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        lW += 1
for i in range(int(N/2),N):
    if C[i] == 'W':
        rW += 1
if lW>=rW:
    print(lW)
else:
    print(rW-lW)
n=int(input())
c=input()
rcnt=[0]*(n+1)
wcnt=[0]*(n+1)
for i in range(n):
    if c[i]=="W":
        wcnt[i+1]=wcnt[i]+1
        rcnt[i+1]=rcnt[i]
    else:
        rcnt[i+1]=rcnt[i]+1
        wcnt[i+1]=wcnt[i]
ans=n+100
for i in range(n):
    cw=wcnt[i+1]
    cr=rcnt[-1]-rcnt[i+1]
    ans=min(ans,cw+cr-min(cr,cw))
ans=min(ans,wcnt[-1])
print(ans)
import collections
n=int(input())
cnt=0
lst=list(str(input()))
y=collections.Counter(lst[:(n//2)])
Ry=y["R"]
Wy=y["W"]
z=collections.Counter(lst[(n//2):])
Rz=z["R"]
Wz=z["W"]
if Rz>Ry:
  cnt+=min(Rz, Wy)
else:
  cnt+=min(Ry, Wz)
print(cnt)
N = int(input())

ans = 0
i = 0

c = input()

# leftRed = str.count("R", 0,N/2-1)
leftWhite = c.count("W", 0,int(N/2))
rightRed = c.count("R", int(N/2),N)
# rightWhite = str.count("W", N/2,N-1)

ans += min(leftWhite, rightRed)
if leftWhite > rightRed:
    ans += (leftWhite - rightRed)

print(ans)
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c[i] == "R":
        cou += 1
print(cou)
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')

    if w_num == 0 or r_num == 0:
        ans = 0
    else:
        ans = min(wl_num, rr_num) + abs(wl_num-rr_num)
    return ans

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

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

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

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

    print(ans)
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'R':
        l += 1

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

    ans += 1
    l += 1
    r -= 1

    if l >= r:
        break
    # print(l, r)
print(ans)
n = int(input())
s = input()
ans = 0
for i in s[0:n//2]:
    if i == "W":
        ans += 1
if n % 2 != 0:
    if s[0:n//2+1] == "R":
        ans += 1
print(ans)
N = int(input())
S = input()
n=0
while S.find("W")<S.rfind("R"):
  S = S[S.find("W")+1:S.rfind("R")]
  n+=1
print(n)