Problem:
 Score : 400 points    Problem Statement An altar enshrines N stones arranged in a row from left to right. The color of the i -th stone from the left (1 \leq i \leq N) is given to you as a character c_i ; R stands for red and W stands for white.  You can do the following two kinds of operations any number of times in any order:   Choose two stones (not necessarily adjacent) and swap them.  Choose one stone and change its color (from red to white and vice versa).   According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?      Constraints  2 \leq N \leq 200000  c_i is R or W .         Input Input is given from Standard Input in the following format:  N  c_{1}c_{2}...c_{N}       Output Print an integer representing the minimum number of operations needed.        Sample Input 1 4
WWRR      Sample Output 1 2  For example, the two operations below will achieve the objective.   Swap the 1 -st and 3 -rd stones from the left, resulting in RWWR .  Change the color of the 4 -th stone from the left, resulting in RWWW .        Sample Input 2 2
RR      Sample Output 2 0  It can be the case that no operation is needed.       Sample Input 3 8
WRWWRWRR      Sample Output 3 3

Solution (Python):


import re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]

def to10(A):
    ret=0
    for a in range(len(A)-1,-1,-1):
        ret+=X[a]*2**(N-1-a)
    return ret


N=int(input())
C=input()
whitecount=0
for c in C:
    if c=="W":whitecount+=1
ans=0
for a in range(N-1,N-1-whitecount,-1):
    if C[a]=="R":ans+=1
print(ans)

Solution (Python):
import itertools

N = int(input())
C = [1 if x == 'W' else 0 for x in input()]

rcount = C.count(0)
ans = rcount
W_acc = itertools.accumulate(C)
R_count = C.count(0)
for i, c in enumerate(W_acc, 1):
    ans = min(ans, abs(rcount - i) + c)
print(ans)

Solution (Python):
n = int(input())
c = list(input())

ans = 0
left = 0
right = n - 1

while left < right:
  while left < n and c[left] != 'W':
    left += 1
  while right >= 0 and c[right] != 'R':
    right -= 1
  if left < right:
    c[left], c[right] = c[right], c[left]
    ans += 1

print(ans)

Solution (Python):
N = int(input())
C = input()

Rc = C.count("R")
leftRc = C[:Rc].count("R")

print(Rc-leftRc)

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left, bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

W_cnt = C.count('W')
R_cnt = C.count('R')
difc = ['R']*R_cnt + ['W']*W_cnt
cnt = 0
for i, j in zip(difc, C):
    if i != j:
        cnt += 1

print(min(W_cnt, R_cnt, cnt//2))

Solution (Python):
n = int(input())
c = input()
w = c.count('W')
r = c.count('R')
t = 'R'*r + 'W'*w
ans = 0
for i in range(n):
    if c[i]!=t[i]:
        ans += 1
print(ans//2)

Solution (Python):
k = input()
cs = input()
rs=cs.count("R")
print(cs[:rs].count("W"))

Solution (Python):

n = int(input())
cl = list(input())

ans = 0
front = 0
back = n-1
while True:

    detected_w = 999999999
    for i in range(front,n):
        if cl[i] == 'W':
            detected_w = i
            break
    else:
        print(ans)
        exit()

    detected_r = -1
    for i in range(back,-1,-1):
        if cl[i] == 'R':
            detected_r = i
            break
    else:
        print(ans)
        exit()

    
    if detected_w < detected_r:
        ans += 1
        front = detected_w+1
        back = detected_r-1
    else:
        print(ans)
        exit()

Solution (Python):


n = int(input())
c = list(input())
l, r = 0, n - 1
ans = 0
while True:
    while l < n and c[l] != "W":
        l += 1
    while r >= 0 and c[r] != "R":
        r -= 1
    if l >= r:
        break
    ans += 1
    c[l], c[r] = "R", "W"
    l += 1
    r -= 1
print(ans)

Solution (Python):













from __future__ import division, print_function
mod1=int(1e9+7)




"""fact=[1]












from sys import stdin, stdout
import bisect            
from bisect import bisect_left as bl              
from bisect import bisect_right as br             
import itertools
from collections import Counter
import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            
    return j







"""*******************************************************"""
def main():
    n=inin()
    a=sin()
    temp=a.count('R')
    print(a[temp:].count('R'))















py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()

Solution (Python):
N = int(input())
C = input()

def solve():
    red = C.count('R')
    white = C[:red].count('W')
    return white

if __name__ == "__main__":
    print(solve())

Solution (Python):
n = int(input())
c = input()
s = [0]
for i in range(n):
  if c[i] == 'R':
    s.append(s[i])
  else:
    s.append(s[i] + 1)
r = n - s[n]
ans = 10**10
for i in range(n + 1):
  ans = min(ans, max(s[i], r - i + s[i]))
print(ans)

Solution (Python):







INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
c = sys.stdin.readline().rstrip()
co = collections.Counter(c)
if not "R" in co or not "W" in co:
    print(0)
    exit()
ret = 0
for i in range(co["R"]):
    if c[i] != "R":
        ret += 1
print(ret)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
S = list(S())

R_place = []
for i in range(N):
  if S[i] == "R":
    R_place.append(i)

if not R_place:
  print(0)
  exit()

ans = 0
for i in range(N):
  if S[i] == "W":
    x = R_place.pop()
    if x <= i:
      print(ans)
      exit()
    ans += 1
    if not R_place:
      print(ans)
      exit()
print(ans)

Solution (Python):
N = int(input())
S = str(input())

P = S.count('R')

D = S[0:P]

Q = D.count('R')

print(P-Q)

Solution (Python):
(N, ) = [int(n) for n in input().split()]
C = input()

nR = sum([1 for c in C if c == 'R'])
nD = sum([1 for c in C[0:nR] if c == 'W'])

print(nD)

Solution (Python):


import sys
input=sys.stdin.readline

n=int(input())
s=input()
ws=s.count('W')
rs=s.count('R')
ans=min(ws,rs)
posw=[]
posr=[]
for i in range(n):
    if s[i]=='W':
        posw.append(i)
    else:
        posr.append(i)
posr=posr[::-1]
for i in range(min(len(posw),len(posr))):
    if posw[i]>posr[i]:
        ans=min(ans,i)
        break
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
c = STR()
arr = [0 if i == 'R' else 1 for i in c]
wnum = sum(arr)
rnum = n - wnum
ans = 0
for i in range(rnum):
    if arr[i] == 1:
        ans += 1
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    C = input()
    forward = 0
    back = N - 1
    cnt = 0
    while forward < back:
        if C[forward] == 'R' and C[back] == 'W':
            forward += 1
            back -= 1
        elif C[forward] == 'R' and C[back] == 'R':
            forward += 1
        elif C[forward] == 'W' and C[back] == 'W':
            back -= 1
        else:
            cnt += 1
            forward += 1
            back -= 1
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())

L=["R"]
for c in input():
    L.append(c)
L.append("W")



ans=0
left=0
right=len(L)-1

while left<right:
    while L[left]=="R":
        left+=1
    while L[right]=="W":
        right-=1

    if left<right:
        L[left],L[right] = L[right],L[left]
        ans+=1

print(ans)

Solution (Python):
n=int(input())
s=input()
r=s.count("R")
w=s.count("W")
cnt=0
for i in range(r):
    if s[i]=="R":
        cnt+=1
print(r-cnt)

Solution (Python):
N = int(input())
c = [i for i in input()]

ret = 0
i, j = 0, N - 1
while i < j :
  while i < N and c[i] != 'W' :
    i += 1
  while 0 <= j and c[j] != 'R' :
    j -= 1
  if i < j :
    ret += 1
    c[i], c[j] = c[j], c[i]
    
print(ret)

Solution (Python):
N = int(input())
C = input()

l_W = [0]*(N+1)
r_R = [0]*(N+1)

for i in range(N):
  l_W[i+1] = l_W[i] + (C[i]=='W')
  r_R[N-i-1] = r_R[N-i] + (C[N-i-1]=='R')
  
times = [max(l,r) for l,r in zip(l_W,r_R)]

print(min(times))

Solution (Python):
from collections import Counter
n = int(input())
c = list(input())
cc = Counter(c)
ans = 0
i = 0
while(cc["R"] and i < n):
    if c[i] == "W":
        ans += 1
        cc["R"] -= 1
    if c[i] == "R":
        cc["R"] -= 1
    i += 1
print(ans)

Solution (Python):
n=int(input())
c=list(input())

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

print(wlef)

Solution (Python):
from math import sqrt
def main():
    n = int(input())
    C = [s for s in input()]
    al = "".join(C).count("R")
    now = 0
    for c in C[:al]:
        if c == "R":
            now += 1
    print(al - now)
    return 

if __name__ == "__main__":
    main()

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()

c = str_inp()
r_amount = c.count("R")
ans = 0
for i in range(r_amount):
    if c[i] == "W":
        ans += 1
print(ans)

Solution (Python):
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))

Solution (Python):
def main():
    n = int(input())
    c = [1 if x=="W" else 0 for x in list(input())]
    white_num = sum(c)
    white_num_of_left = 0
    for _c in c[:n-white_num]:
        if _c == 1:
            white_num_of_left += 1
    print(white_num_of_left)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(input())

w = a.count("W")
r = a.count("R")
aa = a[:r]

r2 = aa.count("R")
print(r-r2)

Solution (Python):
n = int(input())
c = input()

r_num = 0

for i,l in enumerate(c):
  if l=="R":
    r_num +=1

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

print(cnt)

Solution (Python):
n = int(input())
s = str(input())
l = len(s)
p = 0
for i in range(l):
    if s[i] == "R":
        p += 1
ss = s[:p]
q = 0
for j in range(p):
    if ss[j] == "R":
        q += 1
print(p-q)

Solution (Python):
import sys

readline = sys.stdin.readline


def ns(): return readline().rstrip()


def ni(): return int(readline().rstrip())


def nm(): return map(int, readline().split())


def nl(): return list(map(int, readline().split()))


N = ni()
C = ns()

r_index = []
for i in range(N):
    if C[i] == "R":
        r_index.append(i)
if len(r_index) == 0 or len(r_index) == N:
    print(0)
    exit()

ans = 0
for i in range(len(r_index)):
    if r_index[i] >= len(r_index):
        ans += 1
print(ans)

Solution (Python):
N = int(input())
C = list(input())
Rc = 0
Wc = 0
for i in range(N):
    if C[i]=="R":
        Rc+=1
    else:
        Wc+=1
out = 0
for i in range(Rc):
    if C[i]=="W":
        out += 1
print(out)

Solution (Python):
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)

Solution (Python):
n=int(input())
c=list(input())
num=c.count("R")
ans=num
for i in range(num):
    if c[i]=="R":
        ans-=1
print(ans)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    S=STR()
    r=0
    for s in S:
        if s=='R':
            r+=1
    
    w=0
    for i in range(r):
        if S[i]=='W':
            w+=1
    
    print(w)


if __name__=='__main__':
    do()

Solution (Python):
n = int(input())
c = input()
l_c = len(c)
r = 0
ans = 0

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

for i in range(r,l_c):
    if c[i] == 'R':
        ans += 1

print(ans)

Solution (Python):
N = int(input())
C = input()
White = C.count("W")
Red = C.count("R")
left_white = 0
left_red = 0
right_white = White
right_red = Red
ans = Red
for n,c in enumerate(C):
    if c == "W":
        left_white += 1
        right_white -= 1
    else:
        left_red += 1
        right_red -= 1
    ans = min(ans,max(left_white,right_red))
print(ans)

Solution (Python):
N = int(input())
S = input()

cumw = [0]
for c in S:
    cumw.append(cumw[-1] + int(c=='W'))

cumr = [0]
for c in S[::-1]:
    cumr.append(cumr[-1] + int(c=='R'))
cumr.reverse()

ans = N
for a,b in zip(cumw,cumr):
    ans = min(ans, max(a,b))
print(ans)

Solution (Python):
import heapq

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

W, R = [], []
heapq.heapify(W)
heapq.heapify(R)

ans = 0
for i in range(N):
    if C[i] == "W": heapq.heappush(W,i+1)
    if C[i] == "R": heapq.heappush(R,-(i+1))

if len(W) == 0 or len(R) == 0:
    print(0)
    exit()

ans = 0
while W[0] < -R[0]:
    w, r = heapq.heappop(W), -heapq.heappop(R)
    heapq.heappush(W,r)
    heapq.heappush(R,-w)
    ans += 1

print(ans)

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

Solution (Python):
def resolve():
    N = int(input())
    C = list(input())
    idx_a, idx_d = 0, N - 1
    cnt = 0
    while idx_a < idx_d:
        if C[idx_a] != "W":
            idx_a += 1
            continue
        if C[idx_d] != "R":
            idx_d -= 1
            continue
        cnt += 1
        idx_a += 1
        idx_d -= 1
    print(cnt)

resolve()

Solution (Python):
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''







import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby



def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')




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