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()
a = [str(c) for c in s]

def sea(a, x, y, n):
  while x < n-1:
    if a[x] == 'W':
      break
    x += 1
    
  while y > 0:
    if a[y] == 'R':
      break
    y -= 1
  
  return[x, y]

z = [0, n-1]

z = sea(a, z[0] ,z[1], n)
c = 0
while z[0] < z[1]:
  a[z[0]], a[z[1]] = a[z[1]], a[z[0]]
  c += 1
  z = sea(a,z[0], z[1],n)
  
print(c)

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

r = C.count("R")
ans = 0
for i in range(N):
    if C[i] == "R" and r <= i:
        ans += 1

print(ans)

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

l = 0
r = n - 1
ans = 0
while r > l:

    while r > l:
        if s[l] == 'W': break
        else: l += 1
    while r > l:
        if s[r] == 'R': break
        else: r -= 1
    if r > l:
        ans += 1
        r -= 1
        l += 1
print(ans)

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

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

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

cnt = 0
i = 0
j = n-1
while i < j:
    if c[i] == 'W':
        while i < j:
            if c[j] == 'R':
                cnt += 1
                j -= 1
                break
            j -= 1
    i += 1

print(cnt)

Solution (Python):

def main():
    N = int(input())
    C = list(input())
    R_cnt = C.count("R")
    
    
    cnt = 0
    for i in range(R_cnt):
        if C[i] == "R":
            cnt+=1
    print(R_cnt - cnt)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
N = int(input())
C = []
for c in list(input()):
  a = 0
  if c == "R":
    a = 1
  C.append(a)
L = -1
R = N
cnt = 0
while L < R:

  L += 1
  if L >= R:
    break
  if C[L] != 0:
    continue
  while L < R:
    R -= 1
    if L >= R:
      break
    if C[R] != 1:
      continue
    cnt += 1
    break     
print(cnt)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    c = input()
    r = c.count("R")
    ans = 0
    for i in range(r, n):
        if c[i] == "R":
            ans += 1
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):
from collections import deque
n = int(input())
c = list(input())
if c.count("W")*c.count("R") == 0:
    print(0)
    exit()
ans = 0
d = deque(c)
while d:
    flag = False
    while d:
        if flag:
            break
        lef = d.popleft()
        if lef == "W":
            while d:
                rig = d.pop()
                if rig == "R":
                    ans += 1
                    flag = True
                    break
print(ans)

Solution (Python):

N = int(input())
a = list(input()) 


allW=0
allR=0
for i in range(N):
    if a[i]=='W':
        allW+=1
    elif a[i]=='R':
        allR+=1


W=0
R=allR
out = max(W,R)
ans = out
for shikiri in range(N):
    if a[shikiri] =='W':
        W+=1
    elif a[shikiri]=='R':
        R-=1
    out = max(W,R)
    ans = min(ans,out)
    

print(ans)

Solution (Python):
N = int(input())
s = input()
num_reds = [0] * N
num_whites = [0] * N
num_reds[0] += 1 if s[0] == 'R' else 0
num_whites[0] += 1 if s[0] == 'W' else 0
for i in range(1, N):
    if s[i] == 'R':
        num_reds[i] += 1
    else:
        num_whites[i] += 1
    num_reds[i] += num_reds[i - 1]
    num_whites[i] += num_whites[i - 1]

ans = N
for n in range(1, N):
    
    a = n - num_reds[n - 1]
    b = (N - n) - (num_whites[N - 1] - num_whites[n - 1])
    x = a + b - min(a, b)
    ans = min(ans, x)
ans = min(ans, num_reds[N - 1])
ans = min(ans, num_whites[N - 1])
print(ans)

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

print(c)

Solution (Python):
n=int(input());s=input();a=b=0
for i in s:
	if i=='R':a+=1
for i in range(a):
	if s[i]=='W':b+=1
print(b)

Solution (Python):
n, X = int(input()), input()
count_w, count = X.count('W'), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)

Solution (Python):
from math import floor, ceil
N = int(input())
WHITE = 0
RED = 1
str = list(map(str, list(input())))
r = []
w = []

for i in range(N):
  w.append(i) if str[i] == "W" else r.append(i)
  str[i] = WHITE if str[i] == "W" else RED
r.reverse()
max_count = min(len(r), len(w))
count = 0
for i in range(max_count):
  if r[i] - w[i] > 0:
    count += 1

print(count)

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

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

Solution (Python):
def count(l):
    res = {'W':0, 'R':0}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res
n = int(input())
string = input()
cnt = count(string)
swap = 0
for i in range(cnt['R']):
    if string[i] == 'W':
        swap += 1
print(min(swap, cnt['R'], cnt['W']))

Solution (Python):
from enum import Enum

def main():
  initialStones = readProblem()
  minOperationCount = getMinOperationCount(initialStones)
  print(minOperationCount)

def getMinOperationCount(initialStones):
  whiteOnLeft = 0
  redOnRight = 0  
  for stone in initialStones:
    if Color[stone] == Color.R:
      redOnRight += 1
  minOperationCount = len(initialStones)  
  for separator in range(len(initialStones) + 1):
    operationCount = max(whiteOnLeft, redOnRight)
    if minOperationCount > operationCount:
      minOperationCount = operationCount
    
    if separator < len(initialStones):
      if Color[initialStones[separator]] == Color.R:
        redOnRight -= 1
      else:
        whiteOnLeft += 1
    else:
      pass  
  return minOperationCount

def readProblem():
  input()  
  return input()

class Color(Enum):
  R = 'Red'
  W = 'White'
  
if __name__ == '__main__':
  main()

Solution (Python):
n=int(input())
s=input()
li=0
ri=len(s)
cnt=0
while li<ri:
  if s[li] == "W":
    while li<ri:
      ri-=1
      if s[ri] == "R":
        cnt+=1
        break
      
  li+=1
print(cnt)

Solution (Python):

N = int(input())
C = input()
r = 0
w = 0   
b = 0
r = C.count('R')
for i in range(r):
    if (C[i]=='W'):
        b+=1
print(b)

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

c_sort = sorted(c)



r = 0
w = 0

for cc, ss in zip(c,c_sort):
    if cc == 'W' and ss == 'R':
        r += 1
    elif cc == 'R' and ss == 'W':
        w += 1
    else:
        continue

print(max(r,w))

Solution (Python):
N = int(input())
s = input()
l = 0
r = len(s) - 1
ans = 0
while True:
    while l < len(s) - 1 and s[l] == 'R':
        l += 1
    while r >= 0 and s[r] == 'W':
        r -= 1

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

print(ans)

Solution (Python):
n=int(input())
k=list(input())
n1=k.count("R")
ideal_lis=["R"]*n1
ans = 0
for i in range(n1):
    if k[i]!=ideal_lis[i]:
        ans+=1
print(ans)

Solution (Python):
def main():
    n = int(input())
    C = input()
    r_all = C.count('R')
    
    
    
    
    
    
    
    move = [0] * (n+1)
    
    w = 0
    r = r_all
    
    move[0] = max(0, r_all)
    for idx, c in enumerate(C):
        if c == 'W':
            w += 1
        else:
            r = r - 1 
        move[idx+1] = max(w, r)
    ans = min(move)
    print(ans) 

if __name__ == '__main__':
    main()

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

r = 0
for v in c:
    if v == "R":
        r += 1
ans = min(r, n - r)
w = 0
for v in c:
    if v == "W":
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
print(ans)

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

leftw=0
rightr=0

for i in range(n):
    if s[i]=='R':
        rightr+=1

ans=rightr

for i in range(n):
    if s[i]=='W':
        leftw+=1
    else:
        rightr-=1
    ans=min(ans,max(leftw,rightr))

print(ans)

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

N = int(input())

c = input()

a = c.count('R')

b = 0
ans = max(a, b)

for i in range(len(c)):
    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())
w=0
r=C.count('R')
ans=max(w,r)

for i in range(n):
  if C[i]=='W':
    w+=1
  if C[i]=='R':
    r-=1
  if ans>max(w,r):
    ans=max(w,r)
    
print(ans)



"""
n=int(input())
C=list(input()) 
cnt=0
flag1=False
flag2=True

for i in range(n):
  if C[i]=='W':
    for t in range(1,n-i):
      if C[-t]=='R':
        C[i]='R'
        C[-t]='W'
        cnt+=1
        flag2=False
        break
    if flag2:
      flag1=True
  if flag1:
    break

print(cnt)
"""

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

li = list(input())

r_count = li.count('R')

ideal_li = list('W' for _ in range(len(li)))

for i in range(r_count):
    ideal_li[i] = 'R'

unmatch_count = 0
for i in range(len(li)):
    if li[i] != ideal_li[i]:
        unmatch_count += 1

print(unmatch_count // 2)

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

print(ans)

Solution (Python):
N = int(input())
C = list(input())
l = 0
r = N-1
ans = 0
while (r-l) > 0:
    if C[l] == "W" and C[r] == "R":
        C[l], C[r] = C[r], C[l]
        l += 1
        r -= 1
        ans += 1
        continue
    if C[l] == "R":
        l += 1
    if C[r] == "W":
        r -= 1
print(ans)

Solution (Python):
a=map(int,input())

b=input()

c=b.count("R")
d=b.count("W",0,c)
print(d)

Solution (Python):
n=int(input())
s=input()
red=s.count('R')
white=s.count('W')
mn=min(red,white)
ct=0
for i in range (red):
    if s[i]=='W':
        ct+=1
mn=min(mn,ct)
print(mn)

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

a, b = 0, 0

a = c.count('R')
ans = max(a, b)

for i in range(n):
    if c[i] == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a, b))
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):
import sys
input = sys.stdin.readline

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

n = I()
mychr = input().rstrip()

result = float('inf')
red = 0
for i in mychr:
    if i == "R":
        red += 1

R = 0
W = 0

for index, i in enumerate(mychr):
    if i == "R":
        R+=1
    else:
        W+=1
    temp = max(W,red-R)
    result = min(result, temp)

if W != n:
    print(result)
else:
    print(0)

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    C = input()

    r = 0
    cnt = []
    for c in C:
        if c == "R":
            r += 1
        cnt.append(r)
    cnt.append(cnt[-1])

    if not r or r == len(C):
        print(0)
        return

    ans = float("inf")
    for i in range(1, N):
        ans = min(ans, max(i - cnt[i - 1], cnt[-1] - cnt[i]))
    print(ans)


main()

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

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

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

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    c = input()

    return N, c


def main(N: int, c: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 石の個数（2 <= N <= 200000）
        c (str): 石の色
    """
    
    w = 0
    r = c.count("R")
    ans = max(w, r)
    for n in range(N):
        c_n = c[n]
        if c_n == "W":
            w += 1
        else:
            r -= 1
        ans = min(ans, max(w, r))

    
    print(ans)


if __name__ == "__main__":
    
    N, c = get_input()

    
    main(N, c)

Solution (Python):


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


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


print(ans)

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

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

Solution (Python):
n = int(input())
c = ','.join(input()).split(',')

ans = 0

ri = -1

if c.count('W') == 0:
    print(0)
    exit()

if c.count('R') == 0:
    print(0)
    exit()

for i in range(n):
    if c[i] == 'W':
        while c[ri] != 'R':
            ri -= 1
        
        if n < i-ri:
            break
        
        c[i], c[ri] = 'R', 'W'
        ans += 1
    
print(ans)

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

Solution (Python):
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]
rw_count = r_num
wr_count = 0
for i in range(num):
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())

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:
                break
        while c[j]=='W':
            j -= 1
            if j==-1:
                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())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R > W:
    for i in range(0,cnt):
        if list[N-i-1]=="R":
            ans +=1

if R<=W:
    for j in range(0,cnt):
        if list[j] == "W":
            ans +=1


print(ans)

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

Solution (Python):
n = int(input())
s = list(input())
l = 0
r = n-1
c = 0
while l < r:
  for i in range(l, r):
    if s[i] == "W":
      c += 1
      l = i+1
      break
  else:
    l = r
  for i in range(r, l-1, -1):
    if s[i] == "R":
      r = i-1
      c += 1
      break
  else:
    r = l

print(c//2)

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

wc = 0
rc = N - 1

cnt = 0
while True:
    while wc < N and S[wc] == "R":
        wc += 1

    while rc >= 0 and S[rc] == "W":
        rc -= 1

    if wc == N or rc == -1 or wc > rc:
        break

    cnt += 1
    wc += 1
    rc -= 1

print(cnt)

Solution (Python):
n=int(input())
p = input()
w, r = 0,0
for i in range(n):
  if p[i] == "W":
    w += 1
  else:
    r += 1
ans = n
noww , nowr = 0,0
for i in range(n+1):
  ans = min ( ans , max(noww , r - nowr))
  if i < n and p[i] == "W":
    noww += 1
  else:
    nowr += 1
print(ans)

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

r_cnt = C.count('R')
w_cnt = 0
ans = 200000

if w_cnt <= r_cnt:
    ans = min(ans, r_cnt)
else:
    ans = min(ans, w_cnt)

for i in range(N):
    if C[i] == 'R':
        r_cnt -= 1
    else:
        w_cnt += 1

    if w_cnt <= r_cnt:
        ans = min(ans, r_cnt)
    else:
        ans = min(ans, w_cnt)
print(ans)

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

left, right = 0, n - 1
cnt = 0
while True:
    while left < n and c[left] == 'R':
        left += 1
    while right >= 0 and c[right] == 'W':
        right -= 1
    if left >= right:
        break
    cnt += 1
    left, right = left + 1, right - 1
    
print(cnt)

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

Solution (Python):
N = int(input())
C = 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):

import sys
import math

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
c = input()

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

print(ans)

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


RR=[]

for i in range(n):
    if a[i]=='R':
        RR.append(i)


v=a.count('R')
ans=v
for i in range(len(RR)):
    if RR[i]+1<=v:
        ans-=1
print(ans)

Solution (Python):
N = int(input())
c = input()
a, b = c.count('R'), 0
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):
input()
a=input()
if 'W'not in a:print(0);exit()
a=a[a.index('W'):]
b=a.count('R')
print(b-a[:b].count('R'))

Solution (Python):
n=int(input())
c=input()
c=list(c)
a=sorted(c)
countw=0
countr=0

for i in range(n):
  if c[i]=='R' and a[i]=='W':
    countw+=1
  elif c[i]=='W' and a[i]=='R':
    countr+=1
    
ansmin=min(countw,countr)
ansmax=max(countw,countr)

print(ansmin+abs(ansmin-ansmax))

Solution (Python):
n = int(input())
c = input()
towhite = 0
tored = 0

for i in range(n):
    if c[i] == "R":
        towhite += 1
change = max(towhite, tored)

for j in range(n):
    
    if c[j] =="R":
        towhite -= 1
    else:
        tored +=1
    
    now = max(towhite, tored)
    
    change = min(change, now)

print(change)

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

def solve_fixed(p):
    w_cnt = 0
    r_cnt = 0

    for i in range(p):
        if(c[i] == "W"):
            w_cnt += 1
    
    for j in range(p,n):
        if(c[j] == "R"):
            r_cnt += 1
    
    return (w_cnt,r_cnt)

ans = 10**9
w_cnt,r_cnt = solve_fixed(0)

tmp = max(w_cnt,r_cnt)
ans = min(ans,tmp)
for i in range(n):
    
    if(c[i] == "W"):
        w_cnt += 1
    else:
        r_cnt -= 1

    tmp = max(w_cnt,r_cnt)
    ans = min(ans,tmp)
    

print(ans)

Solution (Python):
n = int(input())
cs = input()
b=[]
for i in range(n):
  if cs[i] == "W":
    b.append(0)
  else:
    b.append(1)
a= sum(b)
ans = a- sum(b[:a])
print(ans)

Solution (Python):

N = int(input())
C =[]
C = list(map(str,input()))
red_ko    = len(list(filter(lambda x :x == 'R',C)))
write_ko  = 0
total = max(write_ko,red_ko)
for i in range(N):
    if str(C[i]) == 'R' :
        red_ko -= 1
    else:
        write_ko += 1
    M = max(write_ko,red_ko)
    if total > M : total = M

print(total)

Solution (Python):
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    c = input()
    sushi = c.count("R")
    cnt = 0
    for i in range(sushi):
        if c[i] == "R":
            cnt += 1
    print(sushi - cnt)
    return 0

if __name__ == "__main__":
    solve()

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

cand1 = cs[:cs.count('R')].count('W')
cand2 = cs[cs.count('W'):].count('R')
if cand1 < cand2:
  print(min(cand1, cand2))
else:
  print(max(cand1, cand2))

Solution (Python):
import numpy as np
N=int(input()) 
c=input()



ANS=np.zeros(N+1)
CR=np.zeros(N+1)
CW=np.zeros(N+1)

CR[0]=c.count('R')
CW[N]=c.count('W')

ANS[0]=c.count('R')
ANS[N]=c.count('W')


for i in range(1,N+1):
  if(c[i-1]=='R'):
    CR[i] = CR[i-1] - 1
    CW[i] = CW[i-1]
  else:
    CR[i] = CR[i-1]
    CW[i] = CW[i-1] + 1
  ANS[i]=max(CR[i],CW[i])

print(int(min(ANS)))

Solution (Python):




def main():
    N = input()
    C = input()

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

    print(a - b)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
c = list(input())
print(len([i for i, j in zip(sorted(c), c) if i != j])//2)

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

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

Solution (Python):
N = int(input())
c = list(input())
r, w = 0, 0
r = c.count('R')
a = r
for i in range(N):
    if c[i] == 'R':
        r -= 1
    else:
        w += 1
    ai = max(r, w)
    a = min(a, ai)
print(a)

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

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


def main():
    N = int(input())
    C = input()
    r = C.count("R")
    w = C.count("W")
    cnt = 0
    if w != 0:
        for i in range(r, N):
            if C[i] == "R":
                cnt += 1
        print(cnt)
    else:
        print(0)


if __name__ == "__main__":
    main()

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

r_cnt = 0
for c in C:
    if c == 'R':
        r_cnt += 1

ans = r_cnt
r2w = r_cnt
w2r = 0

for c in C:
    if c == 'W':
        w2r += 1
    elif c == 'R':
        r2w -= 1
    ans = min(ans, max(r2w, w2r))
print(ans)

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

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

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

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

Solution (Python):
n = int(input())
s = input().strip()
l, r = 0, n-1
ans = 0
while l < r:
    if s[l] == 'R':
        l += 1
    elif s[r] == 'W':
        r -= 1
    else:
        ans += 1
        r -= 1
        l += 1
print(ans)

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

str = list(input())

r = str.count('R')
c = N-r

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

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

white_left = [0 for _ in range(N+1)]
red_right = [0 for _ in range(N+1)]

for i in range(N):
  white_left[i+1] = white_left[i]
  if S[i] == 'W':
    white_left[i+1] += 1
    
for i in range(N):
  red_right[i+1] = red_right[i]
  if S[N-1-i] == 'R':
    red_right[i+1] += 1

ans = N
for i in range(N+1):
  ans = min(ans, max(white_left[i], red_right[N-i]))
print(ans)

Solution (Python):
def solve():
	n = int(input())
	s = input().strip()
	left = 0
	right = n-1
	total = 0
	while left < right:
		while left < right and s[left] == 'R':
			left+=1
		while left < right and s[right] == 'W':
			right-=1
		if left == right:
			break
		total+=1
		left+=1
		right-=1
	return total



print(solve())

Solution (Python):
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i-1] == "R":
            cnt += 1

print(cnt)

Solution (Python):

from math import *

n=int(input())
s=input()
c=s.count('R')
p=0
for i in range(c):
    if s[i]=='W':
        p+=1
print(p)

Solution (Python):


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

r_cnt=c.count("R")
ans=c[:r_cnt].count("W")
print(ans)

Solution (Python):
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i-1] == "R":
            cnt += 1

print(cnt)

Solution (Python):
import sys
N = int(input())
word = input()
if word.count('W') == N:
  print(0)
  sys.exit()
num_R = word.count('R')
num_W,min_count= 0,float('inf')
for i in range(N):
  if word[i] == 'W':
    num_W += 1
  else:
    num_R -= 1
  min_count = min(min_count,max(num_W,num_R))
print(min_count)

Solution (Python):
n = int(input())
s = input()
cnt = s.count('R')
s = list(s)
i = 0
res = 0
while(i<cnt):
	if(s[i]=='W'):
		res+=1
	i+=1
print(res)

Solution (Python):


from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


N = int(input())
s = list(input())

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



















def count_w_before_d(num_w_before_d, d):
    if d == 0:
        return 0
    if s[d-1] == 'W':
        num_w_before_d += 1
    return num_w_before_d


def count_r_after_d(num_r_after_d, d):
    if d == 0:
        return num_r
    if s[d-1] == 'R':
        num_r_after_d -= 1
    return num_r_after_d

ans = INF
num_w_before_d = 0
num_r_after_d = num_r
for d in range(N+1):
    num_w_before_d = count_w_before_d(num_w_before_d, d)
    num_r_after_d = count_r_after_d(num_r_after_d, d)
    ans = min(ans, max(num_w_before_d, num_r_after_d))

print(ans)

Solution (Python):



from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

def check(LW, RR):
    
    ct = min(LW, RR)

    if LW >= RR:
        ct += LW - RR
    elif LW < RR:
        ct += RR - LW

    return ct

a = Counter(c)
if not (a["W"] and a["R"]):
    print(0)
    exit()

L = Counter(c[:1])
R = Counter(c[1:])

LW = L["W"]
RR = R["R"]
mi = N
for i in range(1, N):
    mi = min(mi, check(LW, RR))
    
    if c[i] == "W":
        LW += 1
    else:
        RR -= 1
    
print(mi)

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

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

ans = 0
left = 0
right = N - 1

while left < right:
  
  if C[left] == "R":
    left += 1
    continue
  while left < right and C[right] == "W":
    right -= 1
  if left == right:
    break
  ans += 1
  left += 1
  right -= 1
  
print(ans)

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

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

Solution (Python):

length = int(input())
stone = input()
red = [0] * (length + 1)
white = [0] * (length + 1)
[red_num, white_num] = [0, 0]
for i in range(1, length + 1):
	if(stone[i-1] == "W"):
		white_num += 1
	if(stone[length-i] == "R"):
		red_num += 1
	white[i] = white_num
	red[length - i] = red_num


mini = 200000
for i in range(0, length+1):
	trial = max(white[i], red[i])
	mini = min(mini, trial)
print(mini)

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

whites = 0
reds = 0

for stone in stones:
    if stone == "W":
        whites += 1
    else:
        reds += 1

ops = 0
for stone in stones[N - whites :]:
    if stone == "R":
        ops += 1

print(ops)

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

Solution (Python):

def main():
    import sys

    input = sys.stdin.readline

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

    white, red = 0, c.count('R')
    ans = red
    for i in range(N):
        if c[i] == 'W':
            white += 1
        else:
            red -= 1
        res = max(white, red)
        ans = min(ans, res)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
C = [i for i in input()]
w = C.count("W")
r = len(C)-w
B = ["R"]*r + ["W"]*w
ans = 0
for j in range(r):
    if C[j] != B[j]:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
A = str(input())
Wsum = 0
Wright = 0
for i in range(N):
    if A[i] == "W":
        Wsum += 1
for i in range(N - Wsum):
    if A[i] == "W":
        Wright += 1
print(Wright)

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

Solution (Python):
from collections import deque

N = int(input())
line = deque(list(input()))
num = 0
while True:
    if len(line) ==0:
        print(num)
        break
    if line[0] == "R":
        line.popleft()
        continue
    elif line[-1] == "W":
        line.pop()
        continue
    
    
    line.pop()
    line.popleft()
    num += 1

Solution (Python):
def q4():
    n = int(input())
    line = input()
    if 'WR' in line:
        r = line.count('R')
        safe = line[0:r].count('R')
    else:
        r = 0
        safe = 0
    print(r-safe)



if __name__ == "__main__":
    q4()

Solution (Python):
N = int(input())
s = input()
r = s.count("R")
w = s.count("W")
c = s[:r].count("W")

print(min(r,w,c))

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

R = c.count("R")
W = len(c) - R

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

L_W = 0
ans = R+W
for i in range(N+1):
  maxWR = max(L_W,R)
  if ans > maxWR:
    ans = maxWR
  if L_W == W:
    break
  if c[i] == "R":
    R -= 1
  else:
    L_W += 1

print(ans)

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

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

cnt = 0
i = 0
j = n-1
while i < j:
    while c[i] == 'R' and i < j:
        i += 1
    while c[j] == 'W' and i < j:
        j -= 1
    if c[i] != 'W' or c[j] != 'R':
        break
    i += 1
    j -= 1
    cnt += 1

print(cnt)

Solution (Python):
n=int(input())
c=input()
from collections import Counter
w=Counter(c)["W"]
r=0
ans=w
for i in range(n-1,-1,-1):
    if c[i]=="W":
        w-=1
    else:
        r+=1
    ans=min(ans,max(r,w))
print(ans)

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

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

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

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

left = 0
right = n - 1
cnt = 0

while left < right:
  while left < right:
    if c[left] == "W":
      break;
    left += 1
  while left < right:
    if c[right] == "R":
      break;
    right -= 1
  if left < right:
    cnt += 1
  left += 1
  right -= 1


print(cnt)