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())
a = input()
al = len(a)

l = 0
r = al-1
cnt = 0

while True:
    if l >= r:
        break
    if a[l] == 'R':
        l += 1
        continue
    
    if a[r] == 'W':
        r += -1
        continue
    l += 1
    r += -1
    cnt += 1
    
print(cnt)

Solution (Python):








    






mod = int(1e9+7)

INF = 1<<50

def readInt():
    return list(map(int,input().split()))

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

def main():
    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)
    return

if __name__=='__main__':
    main()

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

c = list(input())
num_R=c.count("R")

num_left_R=c[:num_R].count("R")


print(num_R-num_left_R)

Solution (Python):

import sys


def solve(N, C):
    cnt = 0
    i = 0
    j = N - 1
    while i < N and j >= 0:
        while True:
            if C[i] == "W":
                break
            i += 1
            if i >= N:
                break
        while True:
            if C[j] == "R":
                break
            j -= 1
            if j < 0:
                break
        if i >= j:
            break
        else:
            cnt += 1
            i += 1
            j -= 1
    print(cnt)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    S = next(tokens)
    C = [S[i] for i in range(N)]
    solve(N, C)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
C = list(input())
nR = C.count('R')
nW = N - nR

mR = 0
for c in C[:nR]:
    if c=='W': mR += 1

print(mR)

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

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

W = []
R = []
for i in range(n):
    if C[i] == 'W':
        W.append(i)
    else:
        R.append(i)

W.reverse()


nR = []
nW = []
ans = 0
for i in range(len(R)):
    r = R.pop()
    if len(W) > 0:
        w = W.pop()
        if w < r:
            nR.append(w)
            nW.append(r)
            ans += 1
        else:
            R.append(r)
            W.append(w)
            nW += W
            nR += R
            break
    else:
        R.append(r)
        nW += W
        nR += R
        break

nR.sort()
nW.sort()
if len(nR) == 0 or len(nW) == 0:
    print(ans)
    exit()
for idx in nW:
    if idx < nR[0]:
        ans += 1
print(ans)

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

r_num = C.count('R')
ans = C[:r_num].count('W')
print(ans)

Solution (Python):
N = int(input())
c = list(input())
color = [i == 'R' for i in c]
ans = 0
checked = 0
for right in range(N - 1, -1, -1):
    if color[right]:
        for left in range(checked, right):            
            if not color[left]:
                color[right], color[left] = color[left], color[right]
                ans += 1
                checked = left
                break
        checked = left
print(ans)

Solution (Python):
import queue

N=int(input())
A=queue.deque(list(input()))

ans=0
while A:
    if A.popleft()=='W':
        if not A:
            break
        else:
            while A:
                if A.pop()=='R':
                    ans+=1
                    break
            
print(ans)

Solution (Python):
import collections
N = int(input())
c = input()
A = collections.Counter(c)["R"]
B = collections.Counter(c[A:])["R"]
print(B)

Solution (Python):
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n = I()
    c = list(S())
    i,j = 0,n-1
    ans = 0
    while i<j:
        while c[i]=='R':
            i += 1
            if i==n-1:
                break
        while c[j]=='W':
            j -= 1
            if j==0:
                break
        if i<j:
            c[i],c[j] = c[j],c[i]
            i += 1
            j -= 1
            ans += 1
    print(ans)
    exit()

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

def solve(N, C):
    R = 'R'
    W = 'W'
    if C.count('W') == 0:
        return 0
    if C.count('R') == 0:
        return 0

    w = 0
    r = len(C)-1
    count  = 0

    while w < r:
        while w < r and C[w] != W:
            w+=1
        while w < r and C[r] != R:
            r-=1
        if r <= w:
            return count
        else:
            
            C[w], C[r] = 'R', 'W'
            count+= 1
    return min(count, C.count("R"))

print(solve(N, C))

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

ans=0

for x in range(r):
  if a[x]=='R':
    ans+=1
    
print(r-ans)

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    N = II()
    C = list(input())
    l = 0
    r = N-1
    ans = 0
    while l < r:
        while C[l] != 'W' and l < N-1:
            l += 1
        while C[r] != 'R' and 0 < r:
            r -= 1
        if l < r:
            ans += 1
            l += 1
            r -= 1
        else:
            break
    print(ans)

    
main()

Solution (Python):
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
import collections
from heapq import *

N=int(input())
stones=list(input())

l=0
r=N-1
wchange=0
rchange=0
cnt=0
while l<r:
    if (wchange==0)and(stones[l]=="W"):
        wchange=1
    elif (wchange==0)and(stones[l]=="R"):
        l=l+1

    if (rchange==0)and(stones[r]=="R"):
        rchange=1
    elif (rchange==0)and(stones[l]=="W"):
        r=r-1

    if wchange+rchange==2:
        buf=stones[l]
        stones[l]=stones[r]
        stones[r]=buf
        cnt=cnt+1
        wchange=0
        rchange=0
    
print(cnt)

Solution (Python):



def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
c = list(input())
r = 0
w = 0
for i in range(n):
    if c[i] == "R":
        r += 1
    else:
        w += 1
ans = 0
for i in range(r):
    if c[i] != "R":
        ans += 1
print(ans)

Solution (Python):
import os
import sys
from io import BytesIO, IOBase


BUFSIZE = 8192

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)
input = lambda: sys.stdin.readline().rstrip("\r\n")



def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush





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

    b, e = 0, n-1
    res = 0

    while b<e:
        while b < n and s[b] == 'R': b += 1
        while e > -1 and s[e] == 'W': e -= 1
        if b>=e: break
        res+=1
        b+=1
        e-=1
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):

import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192


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)
input = lambda: sys.stdin.readline().rstrip("\r\n")



class TreeNode:
    def __init__(self, k, v):
        self.key = k
        self.value = v
        self.left = None
        self.right = None
        self.parent = None
        self.height = 1
        self.num_left = 1
        self.num_total = 1


class AvlTree:

    def __init__(self):
        self._tree = None

    def add(self, k, v):
        if not self._tree:
            self._tree = TreeNode(k, v)
            return
        node = self._add(k, v)
        if node:
            self._rebalance(node)

    def _add(self, k, v):
        node = self._tree
        while node:
            if k < node.key:
                if node.left:
                    node = node.left
                else:
                    node.left = TreeNode(k, v)
                    node.left.parent = node
                    return node.left
            elif node.key < k:
                if node.right:
                    node = node.right
                else:
                    node.right = TreeNode(k, v)
                    node.right.parent = node
                    return node.right
            else:
                node.value = v
                return

    @staticmethod
    def get_height(x):
        return x.height if x else 0

    @staticmethod
    def get_num_total(x):
        return x.num_total if x else 0

    def _rebalance(self, node):

        n = node
        while n:
            lh = self.get_height(n.left)
            rh = self.get_height(n.right)
            n.height = max(lh, rh) + 1
            balance_factor = lh - rh
            n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
            n.num_left = 1 + self.get_num_total(n.left)

            if balance_factor > 1:
                if self.get_height(n.left.left) < self.get_height(n.left.right):
                    self._rotate_left(n.left)
                self._rotate_right(n)
            elif balance_factor < -1:
                if self.get_height(n.right.right) < self.get_height(n.right.left):
                    self._rotate_right(n.right)
                self._rotate_left(n)
            else:
                n = n.parent

    def _remove_one(self, node):
        """
        Side effect!!! Changes node. Node should have exactly one child
        """
        replacement = node.left or node.right
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = replacement
            else:
                node.parent.right = replacement
            replacement.parent = node.parent
            node.parent = None
        else:
            self._tree = replacement
            replacement.parent = None
        node.left = None
        node.right = None
        node.parent = None
        self._rebalance(replacement)

    def _remove_leaf(self, node):
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = None
            else:
                node.parent.right = None
            self._rebalance(node.parent)
        else:
            self._tree = None
        node.parent = None
        node.left = None
        node.right = None

    def remove(self, k):
        node = self._get_node(k)
        if not node:
            return
        if AvlTree._is_leaf(node):
            self._remove_leaf(node)
            return
        if node.left and node.right:
            nxt = AvlTree._get_next(node)
            node.key = nxt.key
            node.value = nxt.value
            if self._is_leaf(nxt):
                self._remove_leaf(nxt)
            else:
                self._remove_one(nxt)
            self._rebalance(node)
        else:
            self._remove_one(node)

    def get(self, k):
        node = self._get_node(k)
        return node.value if node else -1

    def _get_node(self, k):
        if not self._tree:
            return None
        node = self._tree
        while node:
            if k < node.key:
                node = node.left
            elif node.key < k:
                node = node.right
            else:
                return node
        return None

    def get_at(self, pos):
        x = pos + 1
        node = self._tree
        while node:
            if x < node.num_left:
                node = node.left
            elif node.num_left < x:
                x -= node.num_left
                node = node.right
            else:
                return (node.key, node.value)
        raise IndexError("Out of ranges")

    @staticmethod
    def _is_left(node):
        return node.parent.left and node.parent.left == node

    @staticmethod
    def _is_leaf(node):
        return node.left is None and node.right is None

    def _rotate_right(self, node):
        if not node.parent:
            self._tree = node.left
            node.left.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.left
            node.left.parent = node.parent
        else:
            node.parent.right = node.left
            node.left.parent = node.parent
        bk = node.left.right
        node.left.right = node
        node.parent = node.left
        node.left = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    def _rotate_left(self, node):
        if not node.parent:
            self._tree = node.right
            node.right.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.right
            node.right.parent = node.parent
        else:
            node.parent.right = node.right
            node.right.parent = node.parent
        bk = node.right.left
        node.right.left = node
        node.parent = node.right
        node.right = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    @staticmethod
    def _get_next(node):
        if not node.right:
            return node.parent
        n = node.right
        while n.left:
            n = n.left
        return n



class SegmentTree1:
    def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)



class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: a + b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)



class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]


class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD



def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m



def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z



def product(l):
    por = 1
    for i in range(len(l)):
        por *= l[i]
    return por



def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        
        
        if (arr[mid] < key):
            count = mid + 1
            left = mid + 1

        
        else:
            right = mid - 1

    return count



def countdig(n):
    c = 0
    while (n > 0):
        n //= 10
        c += 1
    return c
def binary(x, length):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    
    
    leftGreater = n

    
    while (l <= r):
        m = int(l + (r - l) / 2)
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        
        
        else:
            l = m + 1

    
    
    return (n - leftGreater)



n=int(input())
e=str(input())
rc=e.count('R')
ans=0
cur=0
sr=0
for i in range(n):
    if e[i]=='R':
        sr+=1
        if cur<=rc-sr:
            continue
        else:
            ans+=1
    else:
        cur+=1
print(ans)

Solution (Python):
N = int(input())
C = input()
S = [0]*(N+1)
for i in range(1, N+1):
    if C[i-1] == "R":
        S[i] = S[i-1]+1
    else:
        S[i] = S[i-1]

R_cnt = S[-1]
print(R_cnt - S[R_cnt])

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

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

ws = [i for i in range(N) if c[i] == 'W']
rs = [i for i in range(N) if c[i] == 'R']

if len(ws) == 0 or len(rs) == 0:
    print(0)
else:
    ans = 0
    while ws and rs and ws[0] < rs[-1]:
        del ws[0]
        del rs[-1]
        ans += 1
    print(ans)

Solution (Python):
N = int(input())
C = input()
R = C.count("R")
count = 0
for i in C[:R]:
  if i == "R":
    count += 1
print(R-count)

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

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

if __name__ == '__main__':
    main()

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

r = N-1
w = 0

op = 0
while w < r : 
    while w < N and arr[w] != 'W' :
        w += 1
    while r >= 0 and arr[r] != 'R' :
        r -= 1

    if w < N and r >= 0 and w < r :
        op += 1
        arr[r], arr[w] = arr[w], arr[r]
        r -= 1
        w += 1  

print(op)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
c = list(input())
i = 0
j = n - 1
ans = 0
while i < j:
    while i < n and c[i] != 'W':
        i += 1
    while j > 0 and c[j] != 'R':
        j -= 1
    if i < j:
        ans += 1
        c[i] = 'R'
        c[j] = 'W'
print(ans)

Solution (Python):
N=int(input())
C=input()
from heapq import heappop,heappush
sr=[]
for i,c in enumerate(C):
    if c=='R':
        heappush(sr,-i)
r=C.count('R')
x=0
while sr and -sr[0]>=r:
    heappop(sr)
    x+=1
print(x)

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

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
    ans += 1
    l += 1
    r -= 1
print(ans)

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

num = 0
x = N
flag = False
for i in range(N):
    if c[i] == "W":
        for j in reversed(range(x)):
            if j <= i:
                flag = True
                break
            elif c[j] == "R":
                c[i] = "R"
                c[j] = "W"
                x = j
                num += 1
                
                break

    if flag:
        break

print(num)

Solution (Python):
N = int(input())
C = [c == "R" for c in input()]
count_red = C.count(True)
print(C[:count_red].count(False))

Solution (Python):
n = int(input())
cs = input()
nr = cs.count("R")
nw = cs.count("W")
cnt = 0
cnt1 = 0
for i in range(nr):
    if cs[i] == "W":
        cnt += 1




print(cnt)

Solution (Python):









n = int(input())
c = list(input())
w_count = c.count("W")
if w_count == 0 or w_count == n:
    print(0)
    exit()
ans1 = 0
for i in range(n - 1, n - w_count - 1, -1):
    if c[i] == "R":
        ans1 += 1










print(min(ans1, w_count, n - w_count))

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

c_r = c.count("R")

for i in range(c_r):
    if c[i] == "R":
        c_r -= 1

print(c_r)

Solution (Python):
N = int(input())
C = list(input())
RtoW = sum(map(lambda x: x=="R",C))
WtoR = 0
ans = RtoW
for i in range(N):
    if C[i] == "R":
        RtoW -= 1
    else:
        WtoR += 1
    ans = min(ans,max(RtoW,WtoR))

print(ans)

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    C = readline().strip()

    left = 0
    right = N - 1

    ans = 0
    while True:
        while left < N and C[left] == 'R':
            left += 1
        while right >= 0 and C[right] == 'W':
            right -= 1

        if left < right:
            ans += 1
            left += 1
            right -= 1
        else:
            break

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = list(input())
from collections import defaultdict
d=defaultdict(int)
for i in range(n):
    d[s[i]]+=1
ans=0
for x in s[:d['R']]:
    if x=='W':
        ans+=1
print(ans)

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

rcnt = c.count("R")
rstart = c[:rcnt].count("R")
print(rcnt - rstart)