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):
n=int(input())
c=input()
if 'W' not in c or 'R' not in c:
  print(0)
  exit()
rr=[0]*(n+1)
lw=[0]*(n+1)
tmp=0
for i in range(n):
  x=c[i]
  if x=='W':
    tmp+=1
  lw[i+1]=tmp
tmp=0
for i in range(n-1,-1,-1):
  x=c[i]
  if x=='R':
    tmp+=1
  rr[i]=tmp
ans=n
for i in range(n+1):
  lwi=lw[i]
  rri=rr[i]
  tmp=lwi+rri-min(rri,lwi)
  ans=min(tmp,ans)
print(ans)

Solution (Python):


def submit():
    n = int(input())
    s = list(input())

    if "W" not in s or "R" not in s:
        print(0)
        return
        
    l = 0
    r = n - 1
    swap = 0
    while True:
        while s[l] != "W":
            l += 1
        while s[r] != "R":
            r -= 1
    
        if r < l:
            break
        s[l] = "R"
        s[r] = "W"
        swap += 1

    print(swap)

submit()

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

"""
RRRWWWになれば幸せ

8
WRWW RWRR
Csum = [0, 1, 1, 2, 3x, 3, 4, 4, 4]

"""

Csum = [0] * (N+1)
for i in range(N):
  Csum[i+1] = Csum[i] + (1 if C[i] == 'W' else 0)
  

CW = Csum[N]
CR = N - CW

ans = 200001

for i in range(N+1):
  leftR = i - Csum[i]
  leftW = Csum[i]
  rightR = CR - leftR
  rightW = CW - leftW
  
  cnt = 0
  
  cnt += min(leftW, rightR)
  leftW -= cnt
  leftR += cnt
  rightR -= cnt
  rightW += cnt
  cnt += leftW + rightR
  
  ans = min(ans,cnt)
  
print(ans)

Solution (Python):
n=int(input())
c=str(input())
c=list(c)
t1=[0]*n
t2=[0]*n
for i in range(len(c)):
  if c[i]=="R":
    t1[i]=1
  else:
    t2[i]=1
if sum(t1)==len(c) or sum(t2)==len(c):
  print(0)
else:
  ans=0
  t=sum(t1)
  for i in range(n):
    if t2[i]==1:
      ans=ans+1
      t=t-1
    if t1[i]==1:
      t=t-1
    if t==0:
      break
  print(ans)

Solution (Python):
q = int(input())
ans = 0
pala = input()
comp = "R"*pala.count("R")+"W"*pala.count("W")

for i in range(q):
    if pala[i] != comp[i]: ans += 1

print(ans//2)

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, C):
    ans = 0
    ri = []
    for i,c in enumerate(C):
        if c == 'R':
            ri.append(i)

    for i, c in enumerate(C):
        if c == 'W' and ri and ri[-1] > i:
            ans += 1
            ri.pop()

    return ans


def main():
    N = read_int()
    C = read_str()
    print(slv(N, C))


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
c=input()
white=[]
red=[]
ans=0
for i in range(N):
    if c[i]=="W":
        white.append(i)
    else:
        red.append(i)
if len(white)==0 or len(red)==0:
    print(ans)
else:
    while len(white)!=0 and len(red)!=0:
        a=white.pop(0)
        b=red.pop()
        if a<b:
            ans+=1
        else:
            break
    print(ans)

Solution (Python):

def solve():
  N = int(input())
  C = input()  
  
  
  
  
  
  W = []
  R = []
  for i, c in enumerate(C):
    if c == 'W':
      W.append(i)
    else:
      R.append(i)
  if not W or not R:
    return 0
  
  for i in range(min(len(W), len(R))):
    if R[-(1+i)] < W[i]:
      return i
  return min(len(W), len(R))
print(solve())

Solution (Python):


input()
C = input()

num_red = C.count('R')

ret = 0

for c in C[0:num_red]:
    if c == 'W': ret += 1

print(ret)

Solution (Python):
n = int(input())
s = list(input())
ans = 0
cnt_w = s.count("W")
j = 1
for i in range(n - cnt_w):
    if s[i] == "W":
        while s[-j] == "W":
            j += 1
        s[i] = "R"
        s[-j] = "W"
        ans += 1


print(ans)

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

rtow = string.count("R")
wtor = 0

anslist = [max(rtow, wtor)]
for c in string:
    if c == "W":
        wtor += 1
    else:
        
        rtow -= 1
    anslist.append(max(rtow, wtor))

print(min(anslist))

Solution (Python):
def main():
    n = int(input())
    s = input()
    ans = 0
    L, R = 0, n-1
    while L < R:
        if s[L] != "W":
            L += 1
        elif s[R] != "R":
            R -= 1
        else:
            ans += 1
            L += 1
            R -= 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N = i()
c = s()
num = c.count('R')
print(c[:num].count('W'))

Solution (Python):
n=int(input())
c=input()
a=[]
for i in range(n):
    if(c[i]=='R'):
        a.append(0)
    else:
        a.append(1)

zero=0
one=0
for i in range(n):
    if(a[i]==0):
        zero+=1

ans=[zero]
for i in range(n):
    if(a[i]==0):
        zero-=1
    else:
        one+=1
    
    ans.append(max(zero,one))

print(min(ans))

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
c = input()
ans = 0
i = 0
j = N-1
while True:
    while i < N and c[i] == 'R':
        i += 1
    while j >= 0 and c[j] == 'W':
        j -= 1
    if i > j:
        break
    else:
        ans += 1
        i += 1
        j -= 1
print(ans)

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

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

print(ans)

Solution (Python):
n = int(input())
c = input()
l = 0
r = n-1
ans = 0
while l<r:
    if c[l] == "R": l += 1
    if c[r] == "W": r -= 1
    
    if c[l]=="W" and c[r]=="R":
        l += 1
        r -= 1
        ans += 1
        
print(ans)

Solution (Python):
n = int(input())
C = input()
idx_l = 0
idx_r = len(C) - 1
cnt = 0
while True:
    if idx_l >= idx_r:
        break
    if C[idx_l] == 'R':
        idx_l += 1
        continue
    if C[idx_r] == 'W':
        idx_r -= 1
        continue
    cnt += 1
    idx_l += 1
    idx_r -= 1
print(cnt)

Solution (Python):
N=int(input())
S=input()
le=S.count('R')
P=S[le:]
print(P.count('R'))

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

l = 0
r = N-1
ans = 0

while l < r:
    while C[l] == 'R' and l + 1 < N:
        l += 1
    while C[r] == 'W' and r + 1 >= 0:
        r -= 1
    if l < r:
        ans += 1
        l += 1
        r -= 1

print(ans)

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

A=[]
for i in range(n):
    if C[i]=="R":
        A.append(i)
count=len(A)

ans=0
for i in A:
    if i>=count:
        ans +=1
print(ans)

Solution (Python):
n = int(input())
C = input()
rc = C.count('R')
print(C[:rc].count('W'))

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

n = inn()
c = ins()
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
    if l>=r:
        break
    cnt += 1
    l += 1
    r -= 1
print(cnt)

Solution (Python):
N = int(input())
cs = input().rstrip()

L, R = 0, N-1
ans = 0
while True:
    while L < N and cs[L] != 'W':
        L += 1
    while R >= 0 and cs[R] != 'R':
        R -= 1

    if L < R:
        ans += 1
    else:
        break
    L += 1
    R -= 1

print(ans)

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

Solution (Python):
n=int(input())
c=input()
r=c.count("R")
w=n-r
ans=0
for i,j in zip(c,"R"*r+"W"*w):
    if i!=j:
        ans+=1
print(ans//2)

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

l = 0
r = n - 1

ans = 0
while l < r:
    while c[l] != "W" and l + 1 < n:
        l += 1

    while c[r] != "R" and r - 1 >= 0:
        r -= 1

    if l < r:
        ans += 1
        l += 1
        r -= 1

print(ans)

Solution (Python):
def f(c):
    return 1*(c=="R")

N=int(input())
C=list(map(f,input()))

R=C.count(1)
S=C[:R].count(0)
print(S)

Solution (Python):
N = int(input())
c = list(str(input()))
for i in range(N):
    if c[i] == "R":
        c[i] = 1
    else:
        c[i] = 0
a = sum(c)
d = c[:a]
e = sum(d)
print(a - e)

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
s=SI()
count=0
for i in range(n):
    if s[i]=="R":
        count+=1
for i in range(count):
    if s[i]=="R":
        count-=1
print(count)

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

cnt = c.count('R')
res = 0
for i in range(cnt):
    if c[i] == 'W':
        res += 1
print(res)

Solution (Python):
n = int(input())
c = input()
white = c.count("W")
red = c.count("R")
if white == 0 or red == 0:
    print(0)
    exit()

ans = 0
count = 0
if white > red:
    for x in c:
        if x == "W":
            ans += 1
            count += 1
        else:
            count += 1
        if count == red:
            print(ans)
            exit()
else:
    for x in reversed(c):
        if x == "R":
            ans += 1
            count += 1
        else:
            count += 1
        if count == white:
            print(ans)
            exit()

Solution (Python):
n = int(input())
c = list(input())
rn = c.count("R")
rnl = c[:rn].count("R")
print(rn-rnl)

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  s=S()

  l=0
  r=n-1

  ans=0
  while l<r:
    if s[l]=='W' and s[r]=='R':
      l+=1
      r-=1
      ans+=1
    else:
      if s[l]=='R':
        l+=1
      elif s[r]=='W':
        r-=1

  return ans


print(main())

Solution (Python):
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
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()

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

head=0
end=n-1

ans=0
ret=False
while head<end:
    while c[head]!="W":
        head+=1
        if head==end:
            ret=True
            break
    
    if ret==True:
        break
    
    while c[end]!="R":
        end-=1
        if head==end:
            ret=True
            break
    
    if ret==True:
        break
    
    ans+=1
    head+=1
    end-=1

print(ans)

Solution (Python):
import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = list(input())

C = Counter(A)
ans = 0
for i in range(C['R']):
    if A[i] == 'W':
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

ans = 0
l = 0
r = n - 1
while True:
    while c[l] != 'W' and l <= n - 1:
        l += 1
    if l >= r:
        print(ans)
        exit()
    while c[r] != 'R' and r >= 0:
        r -= 1
    if l >= r:
        print(ans)
        exit()
    c[l] = 'R'
    c[r] = 'W'
    ans += 1

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

s = input()
count_R = 0
count_W = 0
for ss in s:
    if ss == "R":
        count_R += 1
    else:
        count_W += 1
t_countR = 0
for i in range(count_R):
    if s[i]=="W":
        t_countR += 1

print(t_countR)

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


N = int(input())
C = list(input())[:-1]
r = 0
w = 0
for s in C:
    if s == "R":
        r += 1
    elif s == "W":
        w += 1
ans = 0
if w == 0 or r == 0:
    print(0)
else:
    for i in range(r):
        if C[i] == "W":
            ans += 1
    print(ans)

Solution (Python):
n=int(input())
c=list(input())
x=c.count("R")
m=c[:x]
y=m.count("W")
print(y)

Solution (Python):
import collections
N=int(input())
c=str(input())
cc=collections.Counter(c)

c2=c[:cc['R']]
cc2=collections.Counter(c2)


print(cc2['W'])

Solution (Python):
n = int(input())
s = input()
l = 0
r = n - 1

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

print(ans)

Solution (Python):
n=int(input())
C=input()
L=0
R=n-1
ans=0
while True:
    while L<n:
        if C[L]=="W":
            break
        else:
            L+=1
    while R>=0:
        if C[R]=="R":
            break
        else:
            R-=1
    if L<R:
        ans+=1
        L+=1
        R-=1
    else:
        break
print(ans)

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

l = 0
r = n-1
count = 0
while r > l:
    while r >= 0 and c[r] != "R":
        r -= 1
    while l < n and c[l] != "W":
        l += 1
    
    if r < 0 or l >= n:
        break
    elif r < l:
        break
    else:
        count += 1
        r -= 1
        l += 1
    
print(count)

Solution (Python):
n = int(input())
c = list(input())
r = c.count('R')

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

print(ans)

Solution (Python):
from collections import Counter
N = input()
C = input().rstrip()
dic = Counter(C)
l = dic["R"]
dic2 = Counter(C[:l])
l2 = dic2["R"]
print(l-l2)

Solution (Python):
from collections import deque
N = int(input())
c = deque(input())
ans = 0
while c:
    a = c.popleft()
    if a == "R":
        continue
    else:
        if c:
            while c:
                b = c.pop()
                if b == "W":
                    continue
                else:
                    ans += 1
                    break
        else:
            break
print(ans)

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

ans = 0
l, r = 0, N - 1
while l < r:
    if A[l] == 'W' and A[r] == 'R':
        l += 1
        r -= 1
        ans += 1
    else:
        if A[l] == 'R':
            l += 1
        if A[r] == 'W':
            r -= 1
print(ans)

Solution (Python):
n=int(input())
s=input()
result=0
d={"RW":0,"WR":0}
for i in range(n):
    if s[i]=="R":
        result+=1
        d["RW"]+=1
        
for i in range(n):
    if s[i]=="R":
        d["RW"]-=1        
    else:
        d["WR"]+=1
    maximum,minimum=max(d["RW"],d["WR"]),min(d["RW"],d["WR"])
    sub_result=maximum
    result=min(sub_result,result)
print(result)

Solution (Python):
N = int(input())
c = input()
white = 0
white_ends = 0

for i in range(N):
  if c[i] == "W":
    white += 1
for i in range(N-white, N):
  if c[i] == "W":
    white_ends += 1
print(white-white_ends)

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

Solution (Python):
n=int(input())
s=input()
from collections import Counter
c=Counter(s)
w=c['W']
r=c['R']
if w==0 or r==0:
    print (0)
else:
    z=0
    for i in range(r):
        if s[i]=='W':
            z+=1
    print (z)

Solution (Python):
n = int(input())
data = list(input())
w = 0
r = 0
for i in range(n):
    if data[i] == "W":
        w+=1
    else:
        r +=1
wW = 0
for i in range(r):
    if data[i] ==  "W":
        wW+=1
rW = 0
for i in range(r+1,n):
    if data[i] == "R":
        rW+=1
print(max(rW,wW))

Solution (Python):
import collections
n = int(input())
c = input()
c_ls = []
Ws = collections.deque()
for i in range(n):
    c_ls.append(c[i])
    if c[i] == "W":
        Ws.append(i)
ans = 0
for i in range(n-1,-1,-1):
    if c_ls[i] == "R" and len(Ws):
        w = Ws[0]
        if i > w:
            c_ls[i] = "W"
            c_ls[w] = "R"
            ans += 1
            Ws.popleft()
    elif c_ls[i] == "W" and len(Ws) == 0:
        ans += 1

print(ans)

Solution (Python):
def resolve():
    N = int(input())
    C = input()
    p = C.count("R")
    C1 = C[p:]
    q = C1.count("R")
    print(q)
resolve()

Solution (Python):
N = int(input())
C = input()
C = list(C)
left = 0
length = len(C) - 1
right = length


def checkLeft():
    global left

    while C[left] == "R" and left < length:
        left += 1


def checkRight():
    global right
    while C[right] == "W" and right > 0:
        right -= 1


checkLeft()
checkRight()

cnt = 0
while left < right:
    C[left] = "R"
    C[right] = "W"
    checkLeft()
    checkRight()
    cnt += 1
    
print(cnt)

Solution (Python):
n = int(input())
c = input()
ans = 0
a = 0
b = n-1
while(a < b):
  while(a < n and c[a] == 'R'):
    a += 1
  while(b >= 0 and c[b] == 'W'):
    b -= 1
  if a < b:
    ans += 1
    a += 1
    b -= 1
print(ans)

Solution (Python):
N=int(input())
C=input()
w=0
r=0
for c in C:
  if c=='W':
    w+=1
  else:
    r+=1
    
x=0
for c in C[:r]:
  if c=='W':
    x+=1
    
print(x)

Solution (Python):
N = int(input())
C = input()
s = 0
t = N - 1

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

Solution (Python):
import sys, math

if(__name__ == "__main__"):
    """
    N, D = map(int, input().strip().split() )
    D_sq = D**2
    xy_list = []
    for i in range(N):
        xy = list( map(int, input().strip().split() ) )
        xy_list.append(xy)
    """
    N = int( input().strip() )
    color_str = input().strip()
    colors = [ 0 ] * N
    
    for i in range(N):
        if(color_str[i] == "W"):
            colors[i] = 1
    left = 0
    right = N-1
    times = 0
    while(left < right):
        while(left < N-1 and colors[left]==0):
            left += 1
        while(right > -1 and colors[right]==1):
            right -= 1
        if(left < right):
            colors[left], colors[right] = colors[right], colors[left]
            times += 1
    print(times)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    c = input()
    r = deque()
    for i in range(n)[::-1]:
        if c[i] == "R":
            r.append(i)
    if len(r) in (0, n):
        print(0)
        return
    ans = 0
    for i in range(n):
        if c[i] == "W":
            while r:
                j = r.popleft()
                if j > i:
                    break
            else:
                print(ans)
                return
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    n = int(input())
    C = input()
    r = C.count('R')
    print(C[:r].count('W'))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = input()
x = S.count("W")
y = S[N - x:].count("W")
print(x - y)

Solution (Python):
import random


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


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




n=int(input())
s=input()
l=0
r=n-1
c=0
while(l<r):
    if s[l]=='R':
        l+=1
    if s[r]=='W':
        r-=1
    if s[l]=='W' and s[r]=='R':
        c+=1
        l+=1
        r-=1

print(c)

Solution (Python):
n = int(input())
c = input()
ans = 0
j = n-1
for i in range(n):
    if i >= j:
        break
    if c[i] == 'R':
        continue
    while i < j and c[j] != 'R':
        j -= 1
    if i == j:
        break
    ans += 1
    j -= 1

print(ans)

Solution (Python):
N = int(input())
c = input()
countR = 0
for k in range(len(c)):
  if c[k] == 'R':
    countR += 1

ans = 0
for k in range(countR):
  if c[k] == 'W':
    ans += 1
print(ans)

Solution (Python):
n = int(input())
c = str(input())
l = 0
r = n-1
answer = 0
while l < r:
    if c[l] == "W" and c[r] == "R":
        answer += 1
        l += 1
        r -= 1
    elif c[l] == "W" and c[r] == "W":
        r -= 1
    elif c[l] == "R" and c[r] == "R":
        l += 1
    else:
        l += 1
        r -= 1
print(answer)

Solution (Python):
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()


n = inp()
c = input()
cntR = 0
for i in range(n):
    if c[i] == 'R':
        cntR += 1
ans = cntR
for i in range(cntR):
    if c[i] == 'R':
        ans -= 1
print(ans)



end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Solution (Python):
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

n = Ii()
c = sys.stdin.readline()
rct = c.count('R')
ans = rct - c.count('R',0,rct)
print(ans)

Solution (Python):
from collections import Counter

_ = int(input())
s = input()
counter = Counter(s)
red = counter.get('R', 0)
white = counter.get('W', 0)

mismatches = 0
for i in range(red):
    if s[i] != 'R':
        mismatches += 1

print(mismatches)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = list(input())
fl = False
rig_w = -1
for i in range(n)[::-1]:
    if fl and s[i] == 'W':
        rig_w = i
        break
    elif s[i] == 'R':
        fl = True
res1 = 0

if rig_w != -1:
    res1 = s[:rig_w+1].count('W')

r_count = s.count('R')
res2 = s[:r_count].count('W')

print(min(res1,res2))

Solution (Python):
import heapq
N = int(input())
c = input()

w = [i for i in range(N) if c[i]=='W']
r = [-i for i in range(N) if c[i]=='R']
heapq.heapify(w)
heapq.heapify(r)
ans = 0
for i in range(N):
    if w and r:
        a = heapq.heappop(w)
        b = -heapq.heappop(r)
        if a-b==1:
            break
        else:
            heapq.heappush(w,b)
            heapq.heappush(r,-a)
            ans += 1
print(ans)

Solution (Python):
n=int(input())
c=list(map(str,input()))

r1=c.count('R')

b=list()
for i in range(r1):
    b.append(c[i])
r2=b.count('R')
print(r1-r2)

Solution (Python):
n = int(input())
first = str(input())

w_num = first.count('W')
r_num = first.count('R')

print(first[:r_num].count('W'))

Solution (Python):
N = int(input())
c = list(str(input()))
count_R = 0
for ci in c:
    if ci == 'R':
        count_R += 1
count_over_R = 0
for ci in c[count_R:]:
    if ci == 'R':
        count_over_R += 1
print(count_over_R)

Solution (Python):
N = int(input())
S = list(input())
num_R = S.count('R')
num_R_in_pre_R = S[0:num_R].count('R')
print('{}'.format(num_R-num_R_in_pre_R))

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):
def main():
    N = int(input())
    cs = list(input())

    l = 0
    r = N - 1

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

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

        if l >= r:
            break

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

    print(cnt)

main()

Solution (Python):
N=int(input())
C=input()
R=[]
W=[]
for i in range(N):
  c=C[i]
  if c=="R":
    R.append(i)
  else:
    W.append(i)
ans=0
for i in range(N):
  if i>=len(R) or i>=len(W):
    break
  if W[i]>R[-i-1]:
    break
  ans+=1
print(ans)

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

Solution (Python):
n = int(input())
s = input()
white = 0
red = 0
white_ren = 0
red_ren = 0
for i in range(n):
    if s[i] == "W":
        white += 1
    else:
        red += 1
for i in range(red):
    if s[i] == "R":
        red -= 1
for i in range(white):
    if s[-i - 1] == "W":
        white -= 1
remain = white + red
ans1 = min(red, white)
remain -= 2 * ans1
print(remain + ans1)

Solution (Python):
N = int(input())
C = list(input())
"""
白、赤の順で並んでいる箇所

べき論を求めるのがよさそう。
赤石が全て左半分に来るようにすればよい。
赤石の数を求める⇒赤石はi番目より左になくてはいけない、と定義する。
i番目より右にある赤石の数を求める
"""
RCnt = C.count("R")

RCnt2 = C[:RCnt].count("R")
print(RCnt-RCnt2)

Solution (Python):
N = int(input())
l = list(input())
count = 0
minus = 0
for i in l:
    if i == 'R':
        count += 1
for i in l[:count]:
    if i == 'R':
        minus += 1
print(count - minus)

Solution (Python):
n=int(input())
s=input()
rcount=0
wcount=0
n=len(s)
ans1=0
ans2=0
for i in range(0,n):
    if(s[i]=='R'):
        rcount+=1
    else:
        wcount+=1
for i in range(0,rcount):
    if(s[i]!='R'):
        ans1+=1
for i in range(rcount,n):
    if(s[i]!='W'):
        ans2+=1
print(min(ans1,ans2))

Solution (Python):
n=int(input())
c=list(input())
s=c.count("W")
d=c[:n-s].count("W")
print(d)

Solution (Python):
n = int(input())
c = input()
ans, count = 0, 0
for i in range(n-1):
    if c[i] == 'W' and c[i+1] == 'R':
        ans += count+1
        count = 0
    elif c[i] == 'W' and c[i+1] == 'W':
        count += 1

c2 = ''.join(sorted(c))
count2 = 0

for i, j in zip(c, c2):
    if i != j:
        count2 += 1
print(min(ans, count2//2))

Solution (Python):
N = int(input())
S = input()
Red = [0]
White = [0] * (N + 1)
r = 0
w = 0
for s in S:
    if s == 'R':
        r += 1
    Red.append(r)
for i, s_ in enumerate(S[::-1]):
    if s_ == 'W':
        w += 1
    White[N-i-1] = w

ans = float('inf')
for i in range(N + 1):
    x = i - Red[i]
    y = N - i - White[i]
    m = min(x, y)
    M = max(x, y)
    ans = min(ans, M)
print(ans)

Solution (Python):
from collections import deque
from itertools import groupby
N = int(input())
S = input()

B = [len(list(x[1])) for x in groupby(S)]

q = deque(B)
if S[0] == 'R':
    q.popleft()
if S[-1] == 'W':
    q.pop()

ans = 0
while q:
    if len(q) == 1:
        break
    l, r = q.popleft(), q.pop()
    if l == r:
        if len(q) >= 2:
            q.popleft()
            q.pop()
        ans += l
    elif l < r:
        if len(q):
            q.popleft()
            q.append(r-l)
        ans += l
    else:
        if len(q):
            q.pop()
        q.appendleft(l-r)
        ans += r

print(ans)