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())
s = input()
R_count = s.count("R")
 
new_s = s[R_count:N+1]
R_new = new_s.count("R")
print(R_new)

Solution (Python):
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 x=='W':
    W += 1
  else:
    R -= 1
    
  ans = min(ans,max(R,W))
  
print(ans)

Solution (Python):
N=int(input())
c=input()
print(c[:c.count('R')].count('W'))

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

def solve():
    N = int(readline())
    C = readline().rstrip()

    reds = [i for i in range(len(C)) if C[i] == 'R']
    whites = [i for i in range(len(C)) if C[i] == 'W']

    i = 0
    n = min(len(reds), len(whites))
    while i < n and reds[-1-i] > whites[i]:
        i += 1
    
    print(i)

solve()

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

counter = 0
k = 0

i = 0
j = n-1

while i < j and i < n and 0 <= j:
	if c[i] == 'W' and c[j] == 'R':
		counter += 1
		i += 1
		j -= 1
	elif c[i] == 'W' and c[j] == 'W':
		j -= 1
	elif c[i] == 'R' and c[j] == 'R':
		i += 1
	else:
		i += 1
		j -= 1 
print(counter)

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

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

Solution (Python):


import sys
import argparse
import logging

logging.basicConfig(filename='logger.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def f(c_list: list) -> int:
    '''
    >>> f(['W'])
    0
    >>> f(['R'])
    0
    >>> f(['W','W'])
    0
    >>> f(['R','W'])
    0
    >>> f(['R','R'])
    0
    >>> f(['W','R'])
    1
    >>> f(['W','W','R','R'])
    2
    >>> f(['W','W','R','R'])
    2
    >>> f(['W', 'R', 'W', 'W', 'R', 'W', 'R', 'R',])
    3
    '''
    logger.error(c_list)
    last_red_index = -1
    n_white = 0
    n_red = 0
    for index in range(0, len(c_list)):
        if c_list[index] == 'R':
            last_red_index = index
            n_red += 1
        if c_list[index] == 'W':
            n_white += 1
    logger.error('last_red_index: %d' % (last_red_index))

    
    plan1 = 0
    for index in range(0, last_red_index):
        if c_list[index] == 'W':
            plan1 += 1
    logger.error('plan1: %d' % (plan1))

    
    plan2 = n_white
    logger.error('plan2: %d' % (plan2))

    
    plan3 = n_red
    for index in range(0, n_red):
        if c_list[index] == 'R':
            plan3 -= 1
    logger.error('plan3: %d' % (plan3))

    return min(plan1, plan2, plan3)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
            '--doctest', action='store_true', default=False)
    args = parser.parse_args()
    if args.doctest:
        import doctest
        doctest.testmod(verbose=True)
        sys.exit()

    n = int(sys.stdin.readline().rstrip())
    c_list = list(sys.stdin.readline().rstrip())
    print(f(c_list))

Solution (Python):
n=int(input())
s=input()
k=s.count('R')
count=0
for i in range(k):
    if s[i]=='R':
        count+=1
print(k-count)

Solution (Python):
n = int(input())
c = input()
x = sorted(c)
ans = 0
for i in range(n):
    if c[i]!=x[i]: ans += 1
print(ans//2)

Solution (Python):
n = int(input())
s = str(input())
c1 = s.count("W")
c2 = len(s) - c1
ss = s[:c2]
c3 = ss.count("W")
print(min(c1, c3))

Solution (Python):
import collections
n = int(input())
c = list(input())
C = collections.Counter(c)
n_r = C['R']
n_w = C['W']
ans = [0,0]

for i in range(n_r):
    if c[i] == 'W':
        ans[0] += 1

c = c[::-1]

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

print(min(ans))

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	N = inputInt()
	C = inputStr()

	aida = []
	anzen = 0
	ai = 0
	yokei = 0
	flg = False
	for i,val in enumerate(C):
		ai += 1
		if val == "W":
			if flg == False:
				flg = True
		elif val == "R":
			anzen += 1
			if flg == False:
				aida.append(ai)
			else:
				yokei += 1
				aida.append(ai)

	if yokei == 0:
		print(0)
		sys.exit()

	ans = 0
	for i,val in enumerate(aida):
		if val <= anzen:
			continue
		ans += 1

	print(ans)
	
	




if __name__ == "__main__":
	main()

Solution (Python):
n = int(input())
s = input()
ans = 0
num = 0
for i in s:
    if i == 'W':
        num += 1
for i in range(n - num):
    if s[i] == 'W':
        ans += 1
print(ans)

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

Solution (Python):
n=int(input())
from collections import deque
q =deque(input())

ans = 0
while q:
    while q and q[0] == 'R' and q:
        q.popleft()
    while q and q[-1] == 'W' and q:
        q.pop()
    if not q:break
    ans += 1
    q.popleft()
    q.pop()
print(ans)

Solution (Python):
num = int(input())
mystr = input()
w = mystr.count("W")
w_ = mystr[num-w:].count("W")
print(w - w_)

Solution (Python):
def func_rfindr(str):
    return str.rfind('R')

def func_lfindw(str):
    return str.find('W')

def func_replace(target, pos, str):
    ret = ""
    if pos != 0:
        ret = target[0:pos]
    ret = ret + str
    if len(target) - 1 != pos:
        ret = ret + target[pos + 1:]
    return ret

N = int(input())
C = input()
ans = 0

posrr = func_rfindr(C)
poslw = func_lfindw(C)

while poslw != -1 and posrr != -1 and posrr > poslw:
    
    
    C = C[poslw + 1:posrr]
    ans = ans + 1
    posrr = func_rfindr(C)
    poslw = func_lfindw(C)

print(ans)

Solution (Python):
n = int(input())
C = input()
a, b = 0, n - 1
cnt = 0
while b - a > 0:
    if C[a] == "W" and C[b] == "R":
        cnt += 1
        a += 1
        b -= 1
    if C[a] == "W" and C[b] == "W":
        b -= 1
    if C[a] == "R" and C[b] == "R":
        a += 1
    if C[a] == "R" and C[b] == "W":
        a += 1
        b -= 1
print(cnt)

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

rCount=0
for i in range(N):
  if c[i]=='R':
    rCount+=1
wCount=0

for i in range(rCount):
  if c[i]=='W':
    wCount+=1
print(wCount)

Solution (Python):
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    ans = 0
    left = 0
    right = len(c) - 1
    while left < right:
        if c[left] == 'R':
            left += 1
            continue
        if c[right] == 'W':
            right -= 1
            continue
        left += 1
        right -= 1
        ans += 1

    return ans


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
c=str(input())
red=0
for i in range(n):
    if c[i]== 'R':
        red+=1
ans=0
if red == n:
    print(0)
else:
    for i in range(red,n):
        if c[i] == 'R':
            ans += 1
    print(ans)

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

r = c.count("R") 
rs = c[:r]
rsw = rs.count("W")

print(rsw)

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

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

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

Solution (Python):
i=input;n,c=i(),i();print(c[:c.count('R')].count('W'))

Solution (Python):
import sys

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

r = c.count("R") 
rs = c[:r]
rsw = rs.count("W")

print(rsw)

Solution (Python):

n = int(input())
c=str(input())
if c.count("W") >= c.count("R"):
    print(c[:-c.count("W")].count("W"))
else:
    print(c[c.count("R"):].count("R"))

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





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    C = iss()
    cnt = collections.Counter(C)
    red = cnt['R']
    print(red - collections.Counter(C[:red])['R'])


if __name__ == '__main__':
    main()

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

r_num = c.count("R")

for i in range(n):
    if c[i] == "W":
        break

print(max(c[i:].count("R")-c[i:r_num].count("R"), 0))

Solution (Python):
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] == 'W' and C[r] == 'R':
        C[l], C[r] = C[r], C[l]
        l += 1
        r -= 1
        c += 1
    elif C[l] != 'W': l += 1
    elif C[r] != 'R': r -= 1
print(c)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    S = input()
    r = S.count('R')
    ans = 0
    for c in S[:r]:
        ans += c != 'R'
    print(ans)
resolve()

Solution (Python):
import sys

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

r = c.count("R")
if r == 0 :
    print(0)
    sys.exit()   
rs = c[:r]
rsw = rs.count("W")

print(rsw)

Solution (Python):
n = int(input())
c = input()
col = [0,0]
ans = 0
for l in c:
  if l=='R':
    col[0] += 1
  else:
    col[1] += 1
ans = min(col)
cnt = 1
new_c = 'R'*col[0]+'W'*col[1]
for a,b in zip(c,new_c):
  if a!=b:
    cnt += 1
print(min(cnt//2,ans))

Solution (Python):
n,c=input(),input();print(c[:c.count('R')].count('W'))

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

r = c.count("R")
cnt = 0
for i, j in enumerate(c):
    if i == r:
        break
    if j == "W":
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
a=list(input())
x = a.count('R')
ans = 0

for i in range(x):
    if a[i] == 'W':
        ans += 1
print(ans)

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

k = c.count('R')

print(c[:k].count('W'))

Solution (Python):
input()
s = input()
cnt = 0
for x in s:
    if x == 'R':
        cnt += 1
ans = 0
for i in range(cnt):
    if s[i] == 'W':
        ans += 1
print(ans)

Solution (Python):
N = int(input())
c = input()
print(c[c.count("R"):].count("R"))

Solution (Python):
N = int(input())
c = input()
x = c.count("R")
print(c[x:].count("R"))

Solution (Python):
n=input()
c=input()
print(c[:c.count("R")].count("W"))

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

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

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

ans = 0
w = C.count("W")
r = C.count("R")

CC = r*"R" + w*"W"

for i in range(N):
    if C[i] != CC[i] and CC[i] == "R":
        ans += 1

print(ans)

Solution (Python):
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    
    
    
    

    wc = c.count('W')
    rc = c.count('R')
    ans = c[:rc].count('W')

    return min(wc, rc, ans)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

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

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np

Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
 
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
 
    return K * x
def main():  
    n = int(input())
    s = input()
    print(s.count("R")-s[:s.count("R")].count("R"))
        
                
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
C = list(input().strip())
count = 0
j = N - 1
for i in range(N):
  if C[i] == "W":
    while i < j:
      if C[j] == "R":
        C[i], C[j] = C[j], C[i]
        count += 1
        break
      else:
        j -= 1

print(count)

Solution (Python):
N = int(input())
c = input()
 
r = c.count('R')
print(c[:r].count('W'))

Solution (Python):
N = int(input())
c = list(input())
c.reverse()
cnt = c.count('W')
ans3 = 0
for i in range(N):
    if c[i] == 'R' and cnt > 0:
        ans3 += 1
        cnt -= 1
    if c[i] == 'W':
        cnt -= 1
    
print(ans3)

Solution (Python):
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            s[i], s[j] = s[j], s[i]
            counter += 1
        i += 1
        j -= 1
    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1
    print(counter)
 
s = list(s)
find_cost(s)

Solution (Python):
import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, n-1

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

print(ans)

Solution (Python):
N=int(input())
List=input()
AList=list(List)
RCNT=AList.count("R")
BList=sorted(List)
ANUM=0
BNUM=0
ans=0
i=0
while i<N:
    if AList[i]!=BList[i]:
        ans+=1
    i+=1
print(ans//2)

Solution (Python):
input()
s = input()

def find_cost(s):
    counter, i, j = 0, 0, len(s)-1
    while i < j:
        while i < len(s) and s[i] != 'W':
                i += 1
        while j >= 0 and s[j] != 'R':
                j -= 1
        if i < j:
            
            s[i], s[j] = s[j], s[i]
            
            counter += 1
        i += 1
        j -= 1

    

    for i in range(0, len(s) - 2):
        if s[i] == 'W' and s[i + 1] == 'R':
            counter += 1

    print(counter)

s = list(s)
find_cost(s)

Solution (Python):
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
c = list(input())
r = c.count('R')
print(c[:r].count("W"))

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

Solution (Python):
N = input()

C = list(input())

countR = C.count('R')
countI = C[0:countR]. count('W')

print(countI)

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

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

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

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

ans = 1e10
for i in range(0,n+1):
  ans = min(ans,w[i]+r[i]-min(w[i],r[i]))
print(ans)

Solution (Python):
N=int(input())
C=input()
l=0
r=N-1
ans=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
    l+=1
    r-=1
    ans+=1
print(ans)

Solution (Python):


'''
Author: andyli
Time: 2020-08-02 19:55:50
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    s = input()

    a = ''.join(list(sorted(list(s))))

    cnt = 0
    for i in range(n):
        if a[i] != s[i]: cnt += 1
    print(cnt>>1)
    return



BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        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)
def input(): return sys.stdin.readline().rstrip('\r\n')




if __name__ == '__main__':
    main()

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

red = li.count("R")
white = li.count("W")



target = li[:red]
ans = red - target.count("R")
print(ans)

Solution (Python):
N=int(input())
c=input()
rl=c.count('R')
wf=c[:rl].count('W')  
print(wf)

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


rcnt = c.count('R')
wcnt = c.count('W')

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    cnt = 0
    for i in range(rcnt):
        if c[i] == 'R':
            cnt += 1
    
    print(rcnt - cnt)

Solution (Python):
N = int(input())
C = input()
l = 0
r = N-1
ans = 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
    l += 1
    r -= 1
    ans += 1
print(ans)

Solution (Python):
def main():
    N = int(input())
    s = input()

    r_list = [0]*N
    r_sum = 0
    w_list = [0]*N
    w_sum = 0
    for i in range(N):
        if s[i] != "R":
            r_sum += 1
        r_list[i] = r_sum
        if s[-(i+1)] != "W":
            w_sum += 1
        w_list[i] = w_sum
    
    m = w_list[-1]
    for i in range(N-1):
        r = r_list[i]
        w = w_list[-i-2]
        t = max(r, w)
        if m > t:
            m = t
    
    t = r_list[-1]
    if m > t:
        m = t

    print(m)

main()

Solution (Python):
s,s=input(),input()
print(s[:s.count('R')].count('W'))

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

Solution (Python):
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input().strip()
def mi():return map(int,input().split())
def li():return list(mi())
mod=1000000007

n=ii()
s=si()

    
l=0
r=n-1
ans=0
while(l<r):
    f=0
    for i in range(l,n):
        if s[i]=='W':
            l=i
            f=1
            break
    f1=0
    for i in range(r,-1,-1):
        if s[i]=='R':
            r=i
            f1=1
            break
    if(l>=r or f==0 or f1==0):
        break
    ans+=1
    l+=1
    r-=1

print(ans)

Solution (Python):


import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
C = readline().decode().rstrip()

l, r = 0, N - 1
cnt = 0

while l < r:
    if C[l] == 'R':
        l += 1
    elif C[r] == 'W':
        r -= 1
    else:
        l += 1
        r -= 1
        cnt += 1

print(cnt)

Solution (Python):
N=int(input())
c=input()
ans=0
if len(set(list(c)))==1:
    ans=0
    print(ans)
else:
    
    ans=100000000000000000
    W=0
    R=c.count("R")
    for i in range(N):
        if c[i]=="W":
            W+=1
        elif c[i]=="R":
            R-=1
        if max(R,W)<ans:
            ans=max(R,W)
    print(ans)

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):
def main():
    N=int(input())
    c=list(input())
    
    
    
    
    
    
    res=0
    cR=c.count('R')
    cW=c.count('W')
    
    l,r=0,N-1
    while l!=r:
        if c[l]=='W':
            if c[r]=='R':
                c[l],c[r]='R','W'
                res+=1
            else:
                r-=1
        else:
            l+=1
        
    print(min(cR,cW,res))
    
 
if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
c=str(input())
r=c.count('R')
if r==0:
  print(r)
else:
  cp=c[0:r]
  k=cp.count('R')
  print(r-k)

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

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()
print(min(len(red), len(white)))

Solution (Python):
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)

Solution (Python):
n = int(input())
s = list(input())
r, w = 0, 0
for i in s:
    if i == 'R': r -= -1
    else: w -= -1
for i in range(r):
    if s[i] == 'R': r += -1
print(r)

Solution (Python):
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()
    c = str(input())

    x = 1
    ans = 0
    y = 0

    for i in range(N):
        if y != 0:
            break
        if c[i] == "W":
            for j in range(x, N):
                ii = -j
                if c[ii] == "R" and j < N-i:
                    ans += 1
                    x = j+1
                    break
                if j>= N-i:
                    y += 1
                    break



    print(ans)

if __name__ == "__main__":
	main()

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

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

print(ans)

Solution (Python):
n = int(input())
c = list(input())
sc = list(reversed(c))
ans = 0
r = 0
flg  = False

if 'W' not in set(c) or 'R' not in set(c):
    print(ans)


else:
    for i in range(n):
        if flg:
            break
        if c[i] == 'W':
            for j in range(r, n):
                r += 1
                if sc[j] == 'R':
                    if n >= i+j+2:
                        c[i] = 'R'
                        c[-1*j-1] = 'W'
                        ans += 1
                        break
                    else:
                        flg = True
                        break

                
            

    print(ans)

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

left=0
right=N
ans=0
while True:
    
    for il in range(left,N):
        if c[il]=="W":
            break
    else:
        il=N
        
    for ir in range(right-1,-1,-1):
        if c[ir]=="R":
            break
    else:
        ir=-1
    
    
    if il<ir:
        c[il]="R"
        c[ir]="W"
        left=il+1
        right=ir
        ans+=1
    else:
        break
        
print(ans)

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

w = 0
r = n - 1
ans = 0
flag = True

while flag:
    while c[w] == 'R':
        w += 1
        if w == n-1:
            flag = False
            break
    if not flag:
        break
    while c[r] == 'W':
        r -= 1
        if r == 0:
            flag = False
            break
    if not flag:
        break
    if w < r:
        ans += 1
        w += 1
        r -= 1
        if w == n-1 or r == 0:
            break
    else:
        break


print(ans)

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

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

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

    print(ans)

Solution (Python):
N = int(input())
A = input()
a = A.count("R")
b = A.count("W", 0, a)
print(b)

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

r = sum([x=='R' for x in c])
for i in range(r):
	if c[i] == 'W':
		a += 1
print(a)

Solution (Python):
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start:
        r_pos = range_start 
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

Solution (Python):
from queue import deque
def main():
    R, W = "R", "W"
    N = int(input())
    C = input()

    counter = dict()
    for c in C:
        counter[c] = counter.get(c, 0) + 1
    r = counter.get(R, 0)

    _counter = dict()
    for c in C[r:]:
        _counter[c] = _counter.get(c, 0) + 1
    _r = _counter.get(R, 0)

    ans = _r
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
TMP = K

RW = list(input())
W=0
cnt=0



while K >=0:
    if RW[K-1]=='W':
        K=K-1
        continue
    else:
        while W<K:
           
            if RW[W]=="W":
                RW[K-1], RW[W] = RW[W], RW[K-1]
                
                cnt += 1
                
                break
            else:
                W=W+1
        K=K-1
        

K=TMP
sw = False
while K >=1:
    if sw == False:
        if RW[K-1]=="R":
            sw = True
    else:
        if RW[K-1]=="W":
            cnt += 1
            

    K=K-1

print(cnt)

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

reds_cnt = S.count('R')
whites_in_reds = S[:reds_cnt].count('W')
print(whites_in_reds)

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

r = c.count('R')
w = c.count('W')
l = c[r:].count('R')
ans = min(r, w, l)
print(ans)

Solution (Python):


import sys

def resolve():
    N = int(input())
    C = sys.stdin.readline().strip()

    ans = 0
    R = [0] * N
    W = [0] * N

    if C[0] == "W":
        W[0] += 1
    else:
        R[0] += 1

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

    if W[-1] == 0 or R[-1] == 0:
        print(0)
        return

    print(W[R[-1]-1])

if __name__ == "__main__":
    resolve()

Solution (Python):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random

k=int(input())
s=input()
w=0
r=0
for i in s:
    if i=="W":
        w+=1
    else:
        r+=1
count=0
ans="R"*r + "W"*w
for i in range(k):
    if s[i]!=ans[i]:
        count+=1
print(int(M.ceil(count/2)))