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 = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k >= n-1:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if j +i == n:
        k = j
        break
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
      
print(num)

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

w = 0
r = c.count('R')
ans = max(w, r)
for i in range(n):
    if c[i] == 'W':
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
print(ans)

Solution (Python):

def main():
    n = int(input())
    c = [i for i in input()]
    ans = 0
    cnt = 0
    cnt2 = 0
    for i in range(n):
        if c[i] =="R":
            cnt += 1
    for i in range(cnt):
        if c[i] == "R":
            cnt2 += 1
    ans = cnt - cnt2
    
    print(ans)


if __name__ == "__main__":
    main()

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

x = c.count("R")

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

print(ans)

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

W=0
R=C.count("R")
ans=R
for i in range(N):
    
    if C[i]=="R":
        R-=1
    else:
        W+=1
    if  ans>max(W,R):
        ans=max(W,R)
print(ans)

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

print(ans)

Solution (Python):
N = int(input())
c = input()
W = 0
R = c.count('R')
if R == 0 or R == N:
  print(0)
  exit()
ans = N
t = 0
for i in range(N):
  if c[i] == 'W':
    W += 1
  else:
    R -= 1
  t = max(R,W)
  ans = min(ans, t)
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
c = list(input())
count = Counter(c)
ans = float('inf')
w = 0
r = 0

if count.get('R'):
    r = count['R']

ans = max(w, r)

for i in range(n):
    if c[i]=='W':
        w += 1
    else:
        r -= 1
    ans =min(max(w,r), ans)
print(ans)

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

tmp = 0
for i in range(N):
    if C[i] == "R":
        tmp += 1

ans = 0
for i in range(tmp):
    if C[i] == "W":
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input().rstrip()

i=0
j=n-1
c= 0

while i!=j:
  while s[j]!='R' and j>i:
    j-=1
    
  while s[i]=='R' and j>i:
    i+=1
 
  if i!=j:
    c+= 1
    i+= 1
    j-=1
  if i>=j:
    break
    
print(c)

Solution (Python):
N = int(input())
S = input()
i = 0
j = N - 1
ans = 0
while i < j:
    while i < N and S[i] == 'R':
        i += 1
    while j > 0 and S[j] == 'W':
        j -= 1
    if i >= j:
        break
    ans += 1
    i += 1
    j -= 1
print(ans)

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

Solution (Python):
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
    if stone[l]=='W':
        if stone[r]=='R':
            ans += 1
            l += 1
            r -= 1
        else:
            r -= 1
    else:
        l += 1
        if stone[r]=='W':
            r -= 1
print(ans)

Solution (Python):
n = int(input())
stone = list(input())
l = 0
r = n-1
ans = 0
while l < r:
    if stone[l]=='W':
        if stone[r]=='R':
            ans += 1
            l += 1
            r -= 1
        else:
            r -= 1
    else:
        l += 1
        if stone[r]=='W':
            r -= 1
print(ans)

Solution (Python):
N = int(input())
S = input()
w = 0
r = 0
for s in S:
    if s == "W":
        w += 1
    else:
        r += 1

res = r
rcnt = [0 for i in range(N+1)]
wcnt = [0 for i in range(N+1)]

for i in range(N):
    if S[i] == "W":
        wcnt[i+1] = wcnt[i] + 1
        rcnt[i+1] = r
    else:
        r -= 1
        rcnt[i+1] = r
        wcnt[i+1] = wcnt[i]
    res = min(res, max(wcnt[i+1], rcnt[i+1]))
print(res)

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

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

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

print(ans)

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



div = c.count('R')

c_for = c[:div]
c_lat = c[div:]

ans = 0

replace = min(c_for.count('W'), c_lat.count('R'))
change = max(c_for.count('W'), c_lat.count('R')) - replace

ans = replace + change


print(ans)

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

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

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

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

ans = r
for i in range(n):
    if S[i] == "W":
        w += 1
    elif S[i] == "R":
        r -= 1
    ans = min(ans,max(r,w))
print(ans)

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

r = S.count('R')
w = len(S)-r

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

ans = 0
for i in range(len(S)):
    if S[i] == "R":
        r -= 1
    else:
        r -= 1
        w -= 1
        ans += 1
    if r == 0 or w == 0:
        break
print(ans+r)

Solution (Python):


N = input()
stones = input()




 
  




count =0

 
  
   
    
    
    
    
  
   
  
  



red = 0
white = 0
for i in range(len(stones)):
  if stones[i] == "R":
    red +=1
for i in range(red):
  if stones[i] =='W':
    white+=1
print (white)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    c = input()
    start = 0
    end = N - 1
    ans = 0
    is_end = True
    while(start != end):
        if is_end:
            if c[end] == 'R':
                is_end = False
            end -= 1
        else:
            if c[start] == 'W':
                is_end = True
                ans += 1
            start += 1
    if not is_end and c[start] == 'W':
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

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

R_cnt = 0

for i in range(N):
    if C[i] == "R":
        R_cnt += 1

ans = 0

for i in range(R_cnt):
    if C[i] == "W":
        ans += 1

print(ans)

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

stones = input()

a = stones.count('W')
b = stones.count('R')
 
left_side =stones.count('W', 0, b)
 
print(left_side)

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

a=0
b=0

a = c.count("R")
ans = c.count("R")
for i in range(N):
    if c[i] == "R":
        a -= 1
    else:
        b += 1

    now = max(a,b)
    ans = min(ans, now)

print(ans)

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

from collections import Counter
cnt=Counter(c)
num_of_red = cnt['R']
num_of_white_replace_to_red = c[:num_of_red].count('W')
print(num_of_white_replace_to_red)

Solution (Python):




def main():
    n = int(input())
    c = input()
    all_r = c.count('R')
    all_w = c.count('W')
    trade = all_r - c[:all_r].count('R')
    print(min(all_r,all_w,trade))

    return 

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
c = input()
x = 0
for i in range(n):
    if c[i] == "R":
        x += 1

y = 0
if x != 0:
    for j in range(x):
        if c[j] == "W":
            y += 1

print(y)

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

r = 0
temp = 0

for i in c:
    if i == 'R':
        r += 1
    
w = n - r

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

print(r - temp)

Solution (Python):
n = int(input())
s = input()
w = s.count("W")
r = s.count("R")

left_w = 0
right_r = r
count = [left_w+right_r]
for i in range(0, n):
    if s[i] == "W":
        left_w += 1
    else:
        right_r -=1
    
    count.append(max(left_w,right_r))
print(min(count))

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

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

ans = R
for i in range(1,N+1):
  if C[i-1] == "W":
    w += 1
  else:
    r -= 1
  ans = min(ans, max(w,r))
  
print(ans)

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

num_r = s.count("R")
count = 0

for i in range(num_r):
    if s[i] != "R":
        count += 1
    
print(count)

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

Solution (Python):

import sys


def main():
    N = int( sys.stdin.readline() )
    c_list = list(sys.stdin.readline().rstrip())
    

    num_R = c_list.count("R")
    cnt = 0

    for i in range(num_R):
        if c_list[i] == "W":
            cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):

import sys


def main():
    N = int( sys.stdin.readline() )
    c_list = list(sys.stdin.readline().rstrip())
    

    cnt = 0
    L = 0
    R = len(c_list) - 1

    while L < R:
        if (c_list[L] == "W") and (c_list[R] == "R"):
            c_list[L], c_list[R] = c_list[R], c_list[L]
            cnt += 1
            L += 1
            R -= 1
        elif c_list[L] == "R":
            L += 1
        elif c_list[R] == "W":
            R -= 1
    
    
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
c = input()
r_count = c.count('R')
ans = 0

if r_count == 0:
    print(0)
    exit()

for ci in c:
    if ci == 'W':
        ans += 1
    r_count -= 1
    if r_count == 0:
        print(ans)
        exit()
print(ans)

Solution (Python):
n = int(input())
a = list(input())
cnt_r = n-1
cnt_l = 0
cnt = 0
while True:
  if cnt_r == cnt_l:
    print(cnt)
    exit()
  if a[cnt_r] == 'W':
    cnt_r -= 1
    continue
  if a[cnt_l] == 'R':
    cnt_l += 1
    continue
  a[cnt_r], a[cnt_l] = a[cnt_l], a[cnt_r]
  cnt += 1

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

cour = c.count("R")
count = 0

for i in range(cour):
    if c[i] == "W":
        count += 1

print(count)

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

cntr=c.count('R')

cnt=0
for i in range(0,cntr):
  if c[i]=='W':
    cnt+=1

print(cnt)

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

c = list(input())

red = c.count('R')
white = n - red
redinred = 0
whiteinred = 0

for i in range(red):
  if c[i] == 'W':
    whiteinred += 1
  else:
    redinred += 1

redinwhite = red - redinred

trade = min(whiteinred, redinwhite)
change = abs(whiteinred - redinwhite)

print(trade + change)

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

Solution (Python):
N = int(input())
C = input()
T = 'R' * C.count('R') + 'W' * C.count('W')
ans = sum([1 for a, b in zip(C, T) if a != b]) // 2
print(ans)

Solution (Python):


N=int(input())
S=list(input())

R=S.count("R")

W=S[:R].count("W")

print(W)

Solution (Python):
n = int(input())
stone = input()
r = stone.count("R")
print(stone.count("W", 0, r))

Solution (Python):

N = int(input())
c = input()
white_l = 0
red_r = 0
for i in range(N):
    if c[i]=='R':
        red_r += 1
ans = red_r
for i in range(N):
    if c[i]=='W':
        white_l += 1
    else:
        red_r -= 1
    ans = min(ans, max(red_r,white_l))
print(ans)

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

num_R = c.count('R')

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

Solution (Python):
n = int(input())
c = list(input())
r = [0]
w = [0]
for i in range(n):
    if c[i] == "W":
        w.append(w[-1]+1)
    else:
        w.append(w[-1])
    if c[i] == "R":
        r.append(r[-1]+1)
    else:
        r.append(r[-1])

ans = float('inf')
for i in range(n+1):
    r_left = r[i]
    r_right = r[-1] - r[i]
    w_left = w[i]
    w_right = w[-1] - w[i]
    
    ans = min(ans,max(r_right,w_left))

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
s = list(ins())
n = s.count("R")
ans = 0
for i in range(n):
    if s[i] != "R":
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
s = list(ins())
n = s.count("R")
t = sorted(s)
ans = 0
for i in range(n):
    if s[i] != t[i]:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
s = list(ins())
t = sorted(s)
ans = 0
for i in range(n):
    if t[i] != "R":
        break 
    if s[i] != t[i]:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
stones = input()
r = stones.count("R")
w = stones.count("W")
ans = stones[0:r].count("W")
print(ans)

Solution (Python):



input()
stones = input()
red_count = 0
for stone in stones:
	if stone == 'R':
		red_count += 1

white_count = 0
for stone in stones[:red_count]:
	if stone == 'W':
		white_count += 1

print(white_count)

Solution (Python):
def solve():
    N = int(input())
    S = input()
    C = [c for c in S]

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

if __name__ == "__main__":
    solve()

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

for i in range(N):
  if a[i] == "W":
    wc += 1
  else:
    rc += 1

if rc == 0:
  print("0")
else:
  for i in range(rc):
    if a[i] == "W":
      c += 1
  print(c)

Solution (Python):
n=int(input())
A=list(input())
w=0 ; r=A.count("R") ; ans=10**7
for i in range(n+1):
    ans=min(ans, max(w,r))
    if i==n:print(ans);exit()
    if A[i]=="R":
        r-=1
    else:
        w+=1

Solution (Python):
N= int(input())
stone_str = input()
r_cnt = stone_str.count('R')
print(stone_str.count('W', 0, r_cnt))

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

R_ = line.count("R")
W_ = line.count("W")

final_line = "R" * R_ + "W" * W_

dic = {"W":0, "R":0}

for idx, c in enumerate(line):
    if c != final_line[idx]:
        dic[c] += 1
        
print(max(dic.values()))

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

a = c.count("R")

count = 0
for b in c[0:a]:
    if b == "R":
        count += 1


print(a - count)

Solution (Python):
def main(s):
  a = 0 
  b = 0 
  for i in s:
    if i == "R":
      a += 1
  ans = max(a,b) 
  for i in s:
    if i == "R":
      a -= 1
    else:
      b += 1
    now = max(a,b)
    ans = min(ans, now)
  print(ans)
  
if __name__ == '__main__':
  n = int(input())
  s = input()
  main(s)

Solution (Python):
import queue

N = int(input())
S = list(input())

R, W = queue.PriorityQueue(), queue.PriorityQueue()
for i in range(N):
    if S[i] == 'R':
        R.put(-i)
    else:
        W.put(i)

steps = 0
while True:
    if R.qsize() == 0 or W.qsize() == 0:
        break
    r, w = -R.get(), W.get()
    if r < w:
        break
    steps += 1

print(steps)

Solution (Python):
if __name__ == '__main__':

    n = int(input())
    A = list(input())

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

    
    B = sorted(A)

    
    a = b = 0
    for w,r in zip(A,B):
        if w != r:
            if w == "W":
                a += 1
            else:
                b += 1

    
    com = min(a,b)
    bg = max(a,b)
    dif = bg - com
    ans = com + dif
    print(ans)

Solution (Python):




def main():
    N = int(input())
    C = list(input())
    Rc = len(list(filter(lambda x:x=="R",C)))
    Wc = len(C) - Rc
    c = 0
    for i in range(Rc):
        if C[i] == "W":
            c+=1
    
    
    print(c)
    pass

if __name__ == '__main__':
    main()

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

red = a.count("R")
whi = a.count("W")
l_red = 0
l_whi = 0

ans = min(l_whi, red) + abs(l_whi - red)
for i in range(N):
  if a[i] == "R":
    l_red += 1
    red -= 1
  else:
    l_whi += 1
    whi -= 1
  if min(l_whi, red) + abs(l_whi - red) < ans:
    ans = min(l_whi, red) + abs(l_whi - red)
print(ans)

Solution (Python):
N = int(input())
c = list(input())
a=0; b=0; ans = 0

for i in range(N):
    if c[i] == "R":
        a += 1
ans = max(a,b)

for i in range(N):
    if c[i] == "R":
        a -= 1
    else:
        b += 1
    now = max(a,b)
    ans = min(ans,now)
print(ans)

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

Solution (Python):
'''
Created on 2020/08/22

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  c=pin()[:-1]
  r=0
  w=0
  for i in c:
    if i=="R":
      r+=1
    else:
      w+=1



  nL=0
  nR=r 
  num=max(nL,nR)
  for i in c:
    if i=="R":
      nR-=1
    else:
      nL+=1
    if num>max(nL,nR):
      num=max(nL,nR)
  print(num)
  return 
main()

Solution (Python):
N = int(input())
s = input()
ans = min(s.count('R'), s.count('W'), s[N-s.count('W'):].count('R'))
print(ans)

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

Solution (Python):





N = int(input())
C = input()
Rednum = C.count('R')


NewC = C[:Rednum]

Whinum = NewC.count('R')

print(Rednum - Whinum)

Solution (Python):
n = int(input())
s = input()
nr = s.count('R')
nw = len(s)-nr
a = ('R'*nr)+('W'*nw)
c = 0
for i in range(n):
  if(s[i:i+1] != a[i:i+1]):
    c += 1
print(c // 2)

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

print(cs[:cs.count('R')].count('W'))

Solution (Python):



def solve(N, S):
    l = 0
    r = len(S) - 1
    answer = 0
    while l < r:
        if S[l] == "R":
            l += 1
        elif S[r] == "W":
            r -= 1
        else:
            
            l += 1
            r -= 1
            answer += 1

    return answer


def main():
    N = int(input())
    S = input()
    answer = solve(N, S)
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    pedras = input()

    r = 0
    for p in pedras:
        if p == 'R':
            r += 1

    st2 = 'R'*r + 'W'*(n - r)

    resp = 0

    for i in range(n):
        if pedras[i] == 'R' and st2[i] == 'W':
            resp += 1

    print(resp)
main()

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

w = 0
r = s.count('R')
ans = min(N, r)

for i in range(N):
    if s[i] == 'R':
        r -= 1
    else:
        w += 1
    ans = min(ans, max(w, r))

print(ans)

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

cntR = c.count('R')

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

Solution (Python):
import sys
import math
sys.setrecursionlimit(500000)
INF = float('inf')

def main():
    n = int(input())
    c = input()
    red_stones = c.count('R')
    return c[red_stones:].count('R')

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    c = list(S())
    alldic = collections.Counter(c)
    allnum = alldic["R"]
    leftdic = collections.Counter(c[:allnum])
    leftnum = leftdic["R"]
    ans = allnum-leftnum
    print(ans)
main()

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

for i in c:
    if i=="R":
        red += 1

br = 0
ans = 10**12 if red else 0
for i in range(red):
    if c[i]=="R":
        br += 1
    white = i+1 - br
    disappear = red - br - white
    ans = min(ans, white+disappear)

print(ans)

Solution (Python):
n=int(input())
s = input()
Ra = s.count('R')
t = s[:Ra]
Rb = t.count('R')
print(Ra-Rb)

Solution (Python):


import sys



N = int(input())







C = input()


















a = C.count("R")
b = C[:a].count("R")
print(a - b)

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

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

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

Solution (Python):



def main():
    n = int(input())
    s = input()
    
    
    
    
    
    w = 0
    r = 0
    for i in range(len(s)):
        if s[i] == 'R':
            r += 1
    
    

    res_min = r
    for i in range(1, len(s) + 1):
        if s[i-1] == 'R':
            r -= 1
        elif s[i-1] == 'W':
            w += 1

        res_min = min(res_min, max(w, r))

    print(res_min)


if __name__ == '__main__':
    main()

Solution (Python):

def check(N, c):
    RinRight = c.count('R')
    WinLeft = 0
    r = RinRight
    for i in range(N):
        if c[i] == 'R':
            RinRight -= 1
        else: 
            WinLeft +=1
        r = min(r, max(RinRight,WinLeft))

    return r


N = int(input())
c= input()
print(check(N,c))

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

r_count = 0
for i in range(N):
    if c[i]=="R":
        r_count+=1

r_remain = 0
for i in range(r_count,N):
    if c[i]=="R":
        r_remain+=1

print(r_remain)

Solution (Python):
N = int(input())
stone = input()
R = stone.count('R')
ans = stone.count('W', 0, R)
print(ans)

Solution (Python):
import sys
import numpy as np  

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

a = 0  
b = 0  
for i in range(len(C)):
    if C[i] == 'R':
        a += 1
mn = a
for i in range(len(C)):
    if C[i] == 'R':
        a -= 1
    else:
        b += 1
    mn = min(mn, min(a, b) + abs(a-b))
print(mn)

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

Solution (Python):
N = int(input())
S = list(input())
t1 = S.count('R')
S_R = S[:t1]
t2 = S_R.count('R')
print(t1-t2)

Solution (Python):
n = int(input())
c = list(input())
 
nR = c.count("R")
 
if nR == 0 or nR == len(c):
    print(0)
else:
    print(c[:nR].count("W"))

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

R_num = s.count("R")
print(s[:R_num].count("W"))

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

ans = 0
low = 0
high = n-1

while low<high:
    if c[low] == 'W':
        
        while low<high and c[high]=='W':
            high -= 1
        
        if c[high] == 'R':
            ans+=1
            c[high], c[low] = c[low], c[high]
            
    low += 1    

print(ans)

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

Solution (Python):
N = int(input())
C = str(input())
white = C.count('W')
Ccut = C[N-white:]
print(Ccut.count('R'))

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

count = 0

for i in range(0, r):
  if lst[i] == 'R':
    count += 1
    
print(r-count)

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

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

Solution (Python):
N=int(input())
S=input()
ans=0
i=0
j=N-1
while i<j:
  while i<N:
    if S[i]=='W':
      break
    else:
      i+=1
  while j>0:
    if S[j]=='R':
      break
    else:
      j-=1
  if i<j:
    ans+=1
    i+=1
    j-=1
print(ans)

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

Solution (Python):
import heapq


def main():
    _ = int(input())
    A = list(input())
    R_inds = []
    W_inds = []
    for i in range(len(A)):
        if A[i] == "R":
            R_inds.append(i*(-1))
        else:
            W_inds.append(i)

    if len(R_inds) == 0 or len(W_inds) == 0:
        print(0)
        return

    heapq.heapify(R_inds)
    heapq.heapify(W_inds)
    cnt = 0
    r_i = abs(heapq.heappop(R_inds))
    w_i = heapq.heappop(W_inds)
    while r_i > w_i:
        cnt += 1
        r_i = abs(heapq.heappushpop(R_inds, w_i*(-1)))
        w_i = heapq.heappushpop(W_inds, r_i)

    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
c=input()
n_R=c.count('R')
n_W=0
temp=n_R
ans=n_R
for i in range(n):
    if c[i]=='W':
        n_W+=1
    else:
        n_R-=1
    temp=max(n_W,n_R)
    ans=min(temp,ans)
ans=min(ans,c.count('W'))
print(ans)

Solution (Python):
from collections import Counter

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

b = Counter(s)

ans = min(b["R"],b["W"])

a = 0
for i in range(b["R"]):
    if s[i] == "W":
        a += 1
        
print(min(ans,a))

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

wr = rw = 0
for i in range(len(C_)):
    if C[i] != C_[i]:
        if C[i] == 'R' and C_[i] == 'W':
            rw += 1
        else:
            wr += 1

print(max(wr, rw))

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

    wr = rw = 0
    for i in range(len(C_)):
        if C[i] != C_[i]:
            if C[i] == "R" and C_[i] == "W":
                rw += 1
            else:
                wr += 1

    print(max(wr, rw))
    
if __name__ == "__main__":
    main()

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

nR = c.count("R")

if nR == 0 or nR == len(c):
    print(0)
else:
    print(c[:nR].count("W"))

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

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

Solution (Python):
n = int(input())
S = [c for c in input()]
ans = 0
i = 0
j = n-1
while i < j:
    if S[i] == "W":
        if S[j] == "R":
            S[i] = "R"
            S[j] = "W"
            j -= 1
            i += 1
            ans += 1
        else:
            j -= 1
    else:
        i += 1
print(ans)

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

wr = c.count('WR')
r = c.count('R')
w = c.count('W')

if wr == 0:
    print(0)
else:
    c_sorted = 'R'*r + 'W'*w
    ans = 0
    for i in range(n):
        if c[i] != c_sorted[i]:
            ans += 1
        else:
            ans += 0
    print(ans//2)

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

R = 0
W = 0
for ci in c:
    if ci == 'R':
        R += 1

ans = max(R,W)
for ci in c:
    if ci == 'R':
        R -= 1
    else:
        W += 1
    tmp = max(R,W)
    ans = min(ans,tmp)

print(ans)

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

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

r = C.count("R")

cnt = 0
for i in range(r):
    if C[i] == "W":
        cnt += 1
        
print(cnt)

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

a = k.count("R")
b = k[:a].count("W")
print(b)

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

WL = [0]
RR = [C.count('R')]

for i in range(0, N):
    if C[i] == 'R':
        WL.append(WL[i])
        RR.append(RR[i] - 1)
    else:
        WL.append(WL[i] + 1)
        RR.append(RR[i])

MM = N
for i in range(0, N + 1):
    MM = min(MM, (max(WL[i], RR[i])))
print(MM)

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

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

W=0
R=0
for i in range(N):
    if s[i]=='R':
        R+=1

count = R

for p in range(N):
    if s[p]=='R':
        R-=1
    elif s[p]=='W':
        W+=1
    if max(R, W) < count:
        count = max(R, W)

print(count)

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

red = s.count('R')

ans = 0
for i in range(red):
  if s[i] == 'W':
    ans += 1
print (ans)

Solution (Python):
N=int(input())
c=str(input())
num_R = c.count("R")
num_W = 0
ans = []
if num_R >= num_W:
    ans.append(num_R)
else:
    ans.append(num_W)

for i in range(len(c)):
    if c[i] == "R":
        num_R -= 1
    else:
        num_W += 1
    if num_R >= num_W:
        ans.append(num_R)
    else:
        ans.append(num_W)
    
print(min(ans))