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):
from sys import stdin
N = int(stdin.readline().rstrip())
C = stdin.readline().rstrip()
rc = C.count('R')
ans = 0
for i in range(rc):
    if C[i] == 'W':
        ans += 1
print(ans)

Solution (Python):
from collections import deque
N = int(input())
C = input()
r = deque()
lr = 0
for i in range(N):
  if C[i] == 'R':
    lr += 1
    r.append(i)
ans = 0
for i in range(N):
  if lr == 0:
    break
  if C[i] == 'W':
    if i < r[-1]:
      ans += 1
      r.pop()
      lr -= 1
    else:
      break
print(ans)

Solution (Python):


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

r_total = 0
w_total = 0
for i in c:
  if i == 'R':
    r_total += 1
  elif i == 'W':
    w_total += 1

w_left = 0
r_left = 0

ans = r_total 


for i in range(N):
  cnt = 0
  if c[i] == 'R':
    r_left += 1
    
  elif c[i] == 'W':
    w_left += 1
    
  if w_left <= r_total - r_left:
    cnt += w_left 
    cnt += (r_total - r_left) - w_left 
  else:
    cnt += r_total - r_left  
    cnt += w_left - (r_total - r_left) 
  ans = min(ans, cnt)
print(ans)

Solution (Python):
N = int(input())
C=list(input())
W=(C.count('W'))
R=N-W
WW=0
RR=0
X=[0]*(N-1)
if W>0 and R>0:
  for i in range(N-1):
    if C[i]=='W':
      WW+=1
    RR=(N-i-1)-(W-WW)
    X[i]=max(WW,RR)
print(min(X))

Solution (Python):
ina = input()
inb = input()

l = int(ina)
cw1 = inb.count("W")
cw2 = inb[-cw1:].count("W")
print(cw1-cw2)

Solution (Python):
n = int(input())
c = list(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 = list(input())
r = c.count('R')
w = c.count('W')
ans = 0

for i in range(r):
    if c[i] == 'R':
        pass
    elif c[i] == 'W':
        ans += 1
print(ans)

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

Solution (Python):
N = int(input())
C=list(input())
type=set(C)
L=0
R=0
RR=0
X=0
if 'R' in type and 'W' in type:
    for L in range(N):
      R=RR
      if L>=N-1-R:
        break
      if C[L]=='W':
          for ii in range(N-L-R):
            if C[N-1-R-ii]=='R':
              C[L]='R'
              C[N-1-R-ii]='W'
              X+=1
              break
            RR+=1
            if L>=N-1-R:
              break
print(X)

Solution (Python):
N = int(input())
C=list(input())
type=set(C)
L=0
R=0
RR=0
X=0
if 'R' in type and 'W' in type:
    for i in range(N):
      L=i
      R=RR
      if L>=N-1-R:
        break
      if C[i]=='W':
          for ii in range(N-L-R):
            if C[N-1-R-ii]=='R':
              C[L]='R'
              C[N-1-R-ii]='W'
              X+=1
              break
            RR+=1
            if L>=N-1-R:
              break
print(X)

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

ans = s.count("R")
fans = s[0:ans].count("R")
print(ans-fans)

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

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

count = 0
for i in range(r_cnt):
    if moji[i] == "W":
        count += 1
print(count)

Solution (Python):
param_n = int(input())
param_str = str(input())



list_param_str = list(param_str)



param_R_count = list_param_str.count('R')



param_R_count_before_separation = list_param_str[0:param_R_count].count('R')


print(param_R_count - param_R_count_before_separation)

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

R_count = 0
W_count = 0
for i in range(len(stone)):
  if stone[i] == "R":
    R_count = R_count + 1
  else:
    W_count = W_count + 1

W = 0
R = R_count
try_num_prev = -1
for i in range(N):
  if R_count == 0 or W_count == 0:
    try_num = 0
    break
  
  if W <= R:
    try_num = R
  else:
    try_num = W
  
  
  if try_num_prev >= 0 and try_num_prev < try_num:
    try_num = try_num_prev
    break
  else:
    try_num_prev = try_num
    if stone[i] == "R":
      R = R - 1
    else:
      W = W + 1
    
print(try_num)

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

print(cou_r-count)

Solution (Python):
N=int(input())
C=input()
ans=0
while C!="":
  if C[0]=="R":
    C=C[1:]
  elif C[len(C)-1]=="W":
    C=C[0:len(C)-1]
  else:
    C=C[1:len(C)-1]
    ans+=1
print(ans)

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

N = list(map(int, input().split()))[0]
s = list(input())

w = 0
r = s.count('R')
min_op = max(w, r)
dprint('w, r = ', w, r)

p = 0
while(p < N):
    if (s[p] == 'W'):
        w = w + 1
    else: 
        r = r - 1
    min_op = min(min_op, max(w, r))
    dprint('p, w, r = ', p, w, r)
    
    p = p + 1

print(min_op)

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

num_r = 0
for i in range(N) :
  if c[i] == 'R' :
    num_r += 1
    
ans = 0
for i in range(num_r, N) :
  if c[i] == 'R' :
    ans += 1
    
print(ans)

Solution (Python):


def main():
    n = int(input())
    c_array = list(input())
    
    w = 0
    r = c_array.count("R")
    ans = r
    
    for i in range(0, n):
        if c_array[i] == "W":
            w += 1
        else:
            r -= 1
        
        tmp = max(w, r)
        
        if tmp <= ans:
            ans = tmp
    
    print(ans)
    
main()

Solution (Python):
n = int(input())
s = input()
res = 2000000 
aw=s.count('W')
ar=s.count('R')
if (aw == 0 or ar == 0):
	res=0
pw=0
pr=0
for i in range(n-1):
	if (s[i] == 'R'):
		pr=pr+1
	else:
		pw=pw+1
	if (max(pw,ar-pr) < res):
		res = max(pw,ar-pr)

print(str(res))

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

print(ans)

Solution (Python):

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

white = c.count('W')
red = c.count('R')

left = [0, 0]
right = [white, red]
ans = min(white, red)

for i in range(0, N):
	if c[i] == 'W':
		left[0] += 1
		right[0] -= 1
	else:
		left[1] += 1
		right[1] -= 1
	
	count = max(left[0], right[1])
	ans = min(ans, count)

print(ans)

Solution (Python):
N = int(input())
X = list(input())
es = [0,N,0]

def p(X):
    print(X)

def list_change(X):
    for i in range(N):
        if X[i] == 'W':
            es[0] = i
            for j in reversed(range(es[1])):
                if X[j] == 'R':
                    es[1] = j
                    if i<j :
                        X[i] = 'R'
                        X[j] = 'W'
                        es[2] +=1
                        break
                elif j == 0:
                    es[1] = 1
                


list_change(X)
p(es[2])

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

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

Solution (Python):
n = int(input())
c = input()
lst = []
w = 0
r = 0
for i in range(n):
  if c[i] == 'R':
    r += 1
ans = max(w, r)

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

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

def main():

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

    l = len(reds)
    ans = 0
    for i in range(l):
        if reds[i] > l:
            ans += 1

    print(ans)

main()

Solution (Python):
"""
4
WWRR
2
"""
import itertools

n = int(input())
s = list(input())
left_w = [0]
right_r = [0]
for l in s:
    if l == "W":
        left_w.append(1)
    else:
        left_w.append(0)
lacc = list(itertools.accumulate(left_w))
for r in s[::-1]:
    if r == "R":
        right_r.append(1)
    else:
        right_r.append(0)
racc = list(itertools.accumulate(right_r))
racc = racc[::-1]
print(min(map(max, zip(lacc, racc))))

Solution (Python):
def solve(n, c_str):
    cum_sum_w_left = [0] * (n + 1)
    cum_sum_r_right = [0] * (n + 1)
    
    cum_sum_w = 0
    for i in range(n):
        if c_str[i] == "W":
            cum_sum_w += 1
        cum_sum_w_left[i + 1] = cum_sum_w
    
    cum_sum_r = 0
    for i in range(n - 1, -1, -1):
        if c_str[i] == "R":
            cum_sum_r += 1
        cum_sum_r_right[i] = cum_sum_r
    
    
    res = n + 1
    for i in range(n + 1):
        res = min(res, max(cum_sum_w_left[i], cum_sum_r_right[i]))
    
    return res


def main():
    n = int(input())
    c_str = input()
    res = solve(n, c_str)
    print(res)


def test():
    assert solve(4, "WWRR") == 2
    assert solve(2, "RR") == 0
    assert solve(8, "WRWWRWRR") == 3


if __name__ == "__main__":
    test()
    main()

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

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

Solution (Python):
N = int(input())
c = input()
ans = [-1] * (N+1)

for i in range(0, N+1):
  if i == 0:
    l = c[:i]
    r = c[i:]
    W = l.count("W")
    R = r.count("R")
  else:
    if (c[i-1]) == "W":
      W += 1
    elif (c[i-1]) == "R":
      R -= 1

  ans[i] = max(R, W)
      
print(min(ans))

Solution (Python):
N = int(input())
C = input()
a = b = ans = 0
for c in C:
    if c == 'R':
        a += 1
ans = max(a, b)
for c in C:
    if c == 'R':
        a -= 1
    else:
        b += 1
    ans = min(ans, max(a, b))
print(ans)

Solution (Python):



def main():
  n = int(input())
  lc = list(input().strip())
  
  i = 0
  j = n - 1
  cnt = 0
  while i < j:
    while i < n:
      if lc[i] == 'R':
        i += 1
      else:
        break
    while 0 < j:
      if lc[j] == 'W':
        j -= 1
      else:
        break        
    if i < j:
      cnt += 1
    i += 1
    j -= 1
    
  print(cnt)

if __name__=='__main__':
  main()

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

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

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

if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
r = [0] * n
w = [0] * n
for i in range(n):
  if s[i] == 'W':
    w[i] += 1
  else:
    r[i] += 1
for i in range(1, n):
  w[i] += w[i - 1]
  r[i] += r[i - 1]
rn = r[n - 1]
ans = n
if rn == 0:
  ans = 0
for i in range(n):
  c = (i + 1)
  ri = r[i]
  left = rn - ri
  need = c - ri
  ans = min(ans, max(left, need))  

print(ans)

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

Solution (Python):

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

w2r = 0 
r2w = 0 
for i in range(n):
    if c[i] == 'R': r2w += 1 

needed = lambda a,b: a + b - min(a,b)

ans = needed(w2r,r2w)
for i in range(n):
    if c[i] == 'R':
        r2w -= 1
    else:
        w2r += 1
    ans = min(ans, needed(w2r,r2w))

print(ans)

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

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

wcount=0
for i in range(n):
    if s[i]=="R" :
        wcount+=1

wwcount=0
for i in range(wcount):
    if s[i]=="R" :
        wwcount+=1

print(wcount-wwcount)

Solution (Python):
def calc_min_op(n, stone, left_red):
    ans = float('inf')
    for i in range(n+1):
        
        left_excess_w = i - left_red[i]
        right_excess_r = left_red[n] - left_red[i]
        operations = max(left_excess_w, right_excess_r)
        ans = min(ans, operations)
    return ans


def main():
    n = int(input())
    stone = input()
    
    left_red = [0] * (n + 1)
    for i in range(1, n + 1):
        left_red[i] = left_red[i-1] + (1 if stone[i-1] == 'R' else 0)
    print(calc_min_op(n, stone, left_red))


if __name__ == '__main__':
    main()

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

r = []
for i in range(len(c)):
    if c[i] == "R":
        r.append(i+1)

l = len(r)
ans = 0
for i in range(l):
    if r[i] > l:
        ans += 1

print(ans)

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

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

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

print(min(r_num, min(w_num, change_num)))

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

white=[0]*(N+1)
red=[0]*(N+1)

for i in range(N):
    if C[i]=="W":
        white[i+1]=white[i]+1
        red[i+1]=red[i]
    else:
        white[i+1]=white[i]
        red[i+1]=red[i]+1

if white[-1]==N or red[-1]==N:
    print(0)
    exit()

ans=float("inf")
for i in range(1,N):
    wcnt=white[i]
    rcnt=red[-1]-red[i]
    m=max(wcnt,rcnt)
    ans=min(m,ans)

print(ans)

Solution (Python):
import sys

n = int(input())
s = input()
r = s.count('R')

print(r - s.count('R', 0, r))

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

c = b.count("R")
R_count = 0
change_count = 0

while R_count < c:
    if b[R_count] == "W":
        R_count +=1
        change_count +=1
    else : R_count +=1

print(change_count)

Solution (Python):
n = int(input())
color = list(input())
left = 0
right = len(color) - 1
ans = 0
while left<right:
    if(color[left]=='W' and color[right]=='R'):
        ans += 1
        left += 1
        right -=1
    if color[left] == 'R':
        left+=1
    if color[right] == 'W':
        right -=1
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    N = II()
    C = IS()
    r = 0
    w = 0
    for c in C:
        if c=='R': r+=1
        else : w +=1
    ans = 0

    for c in C:
        if(r==0 or w==0):
            break
        else:
            if c == 'W':
                r-=1
                ans+=1
            if c == 'R':
                r-=1
    print(ans)




if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    N = int(input())
    C = input().strip()
    R = C.count('R')
    if R == 0 or R == N:
        print(0)
        return
    leftR = 0
    pos = 0
    ans = N - R
    for i, c in enumerate(C):
        if c == 'R':
            leftR += 1
        leftW = i + 1 - leftR
        rightR = R - leftR
        
        changes = abs(rightR - leftW)
        swaps = min(rightR, leftW)
        ans = min(ans, swaps + changes)
    print(ans)

solve()

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

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

Solution (Python):
N = int(input())
c = input()
R = c.count('R')
W = 0
ans = max(R,W)
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())
s = input()

ans = n
w2r = 0
r2w = s.count("R")
ans = min(ans, max(w2r, r2w))

for i in range(n):
    if s[i]=="W":
        w2r += 1
    else:
        r2w -= 1
    ans = min(ans, max(w2r, r2w))
    
print(ans)

Solution (Python):
N = int(input())
S = input()
red_count = 0
for s in S:
    if s == 'R':
        red_count += 1
ans = 0
for i in range(red_count):
    if S[i] == 'W':
        ans += 1

print(ans)

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

n_w  = c.count("R")

goal = []
for i in range(n_w):
    goal.append("R")
for j in range(n-n_w):
    goal.append("W")

W2R = 0
R2W = 0

for i in range(n):
    if c[i]=="W" and goal[i]=="R":
        W2R += 1
    elif c[i]=="R" and goal[i]=="W":
        R2W += 1
        
ans = max(W2R, R2W)
print(ans)

Solution (Python):
def solve(n, c):
    num = len(list(filter(lambda _: _=="R", c)))
    if num in [0,n]:
        return 0
    w = [0] * n
    w[0] = int(c[0] == "W")
    for i in range(1, n):
        w[i] = w[i-1] + int(c[i] == "W")
    return min(max(w[i], num+w[i]-i-1) for i in range(n))

n = int(input())
c = input()
print(solve(n, c))

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

R = [0]
W = [0]
r = 0
w = 0

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

Solution (Python):
n = int(input())
s = input()
w = s.count('W')
print(0 if w == 0 else s[-w:].count('R'))

Solution (Python):
N = int(input())
c = input()
ans = cnt = c.count('R')
for x in c[:cnt]:
    if x == 'R':
        ans -= 1
print(ans)

Solution (Python):
N = int(input().rstrip())
c = list(input().rstrip())
nr = c.count('R')
result = c[nr:].count('R')
print(result)

Solution (Python):
n = int(input())
s = input()
w = s.count('W')
if w == 0:
  print(0)
else:
  print(s[-w:].count('R'))

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

count = 0
if not(c.find('R') == -1 or c.find('W') == -1):
    idx_W = -1
    idx_R = -1
    while True:
        idx_W = c.find('W')
        idx_R = c.rfind('R')
        if idx_W >= idx_R:
            break
        c = c[:idx_W] + 'R' + c[idx_W+1:idx_R] + 'W' + c[idx_R+1:]
        count += 1
print(count)

Solution (Python):
N = int(input())
c = input()
red_to_white = c.count("R")
ans = red_to_white
while_to_red = 0

for i in c:
    if i == "W":
        while_to_red += 1 
    else:
        red_to_white -= 1
    ans = min(ans,max(while_to_red,red_to_white))

print(ans)

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

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

n = int(input())
s = input()
i, j = 0, n - 1
ans = 0
while i < j:
	while i < j and s[i] == 'R':
		i += 1
	while i < j and s[j] == 'W':
		j -= 1
	if i < j:
		ans += 1
	i += 1
	j -= 1
print(ans)

Solution (Python):
N=int(input())
c=input()
dp=[0]
bp=[0]
for i in range(N):
  if c[i]=='W':
    dp.append(dp[-1]+1)
    bp.append(bp[-1])
  else:
    dp.append(dp[-1])
    bp.append(bp[-1]+1)
ans=10**9
for i in range(N+1):
  ans=min(max(dp[i],bp[-1]-bp[i]),ans)
print(ans)

Solution (Python):

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

c = S.count("R")
res = S[c:].count("R")
print(res)

Solution (Python):
def main():
    N = int(input())
    S = [s for s in input()]
    ans = 10**9
    w = 0
    r = S.count("R")
    for i in range(N+1):
        ans = min(ans, max(w, r))
        if i == N:
            break
        if S[i] == "W":
            w += 1
        else:
            r -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
cs = input()
r = cs.count("R")
print(cs[r:].count("R"))

Solution (Python):
n = int(input())
c = input()
cnt = 0
ans = 0

for i in range(n):
    if c[i] == 'R':
        cnt += 1
    
for j in range(cnt):
    if c[j] == 'W':
        ans += 1
        
print(ans)

Solution (Python):
n = int(input())
c = list(input())
sw = [0]*(n+2)
sr = [0]*(n+2)
for i in range(1,n+1):
    sw[i] = sw[i-1] + 1*(c[i-1]=="W")
    sr[n+1-i] = sr[n+2-i] + 1*(c[n-i]=="R")
ans = 10**6
for i in range(n+1):
    ans = min(ans, max(sw[i],sr[i+1]))
print(ans)

Solution (Python):
N = int(input())
C = input()
a = C.count('R')
b = C.count('R', 0, a)
print(a - b)

Solution (Python):
n=int(input())
hoge=input()
r=hoge.count("R")
print(min(hoge[:r].count("W"),hoge[r:].count("R")))

Solution (Python):
N = int(input())
cn = input()
sto = list(cn)
count = 0

r = sto.count("R")
for i in range(r):
    if sto[i] == "W":
      count += 1
print(count)

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


def calculate(n, s):
    arr = list(s)
    result = []


    leftW = 0
    rightR = arr.count('R')


    if rightR == 0:
        print(0)
        return

    for i in range(n):
        val = arr[i]

        if val == 'R':
            rightR -= 1

        if val == 'W':
            leftW += 1

        result.append(max(leftW,rightR))

    if len(result) == 0:
        print(0)
    else:
        print(min(result))

calculate(N, S)

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

C = list(input())

res = 0
j = N - 1
for i in range(N):
    if C[i] == "W":
        while i < j:
            if C[j] == "R":
                res += 1
                C[i] = "R"
                C[j] = "W"
                break
            j -= 1
    if i >= j:
        break

print(res)

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

white_to_red = 0
red_to_white = s.count('R')

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

print(ans)

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

Solution (Python):
N = int(input())
stn = input()
m = stn.count('R')
r = m
w = 0
for i in range(N):
    if stn[i]=='R':
        r -= 1
    else:
        w += 1

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

print(m)

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

l = 0
r = N-1
count = 0

while l < r:
    if L[l] == 'W' and L[r] == 'R':
        count += 1
        l += 1
        r -= 1
        continue

    if L[l] != 'W':
        l += 1
    
    if L[r] != 'R':
        r -= 1

print(count)

Solution (Python):
n=int(input())
a=list(input())
R=a.count("R")
W=0

count=R
for i in range(n):
    if a[i]=="R":
        R-=1
    else:
        W=W+1
    count=min(count,max(R,W))
print(count)

Solution (Python):
N = int(input())
c = list(input())
num_R = c.count("R")
num_R_2 = c[:num_R].count("R")
ans = num_R - num_R_2
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()))

def main():
    mod=10**9+7
    N=I()
    c=list(input())
    w=[0]*(N+1)
    r=[0]*(N+1)
    
    for i in range(N):
        if c[i]=="W":
            w[i+1]+=1
        else:
            r[i]+=1
            
    for i in range(N):
        w[i+1]+=w[i]
        
    for i in range(N,0,-1):
        r[i-1]+=r[i]
        
    ans=N
    for i in range(N+1):
        temp=max(w[i],r[i])
        ans=min(ans,temp)
        
    print(ans)

        
            

    

main()

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

R, W = [], []
R_ = []
nR, nW = 0, 0
for c in C:
    if c == 'R':
        nR += 1
    else:
        nW += 1
    R.append(nR)
    W.append(nW)

if nR == 0 or nW == 0:
    print(0)
    exit()

for r in R:
    R_.append(nR - r)

ans = N

for i in range(N):
    r, w, r_ = R[i], W[i], R_[i]
    if r_ > w:
        ans = min(r_, ans)
    else:
        ans = min(w, ans)
print(ans)

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())
s = input()
red = 0
white = 0
for x in s:
    if x=='R':
        red += 1
    else:
        white += 1
reqr = 0
for i in range(red):
    if s[i]=='W':
        reqr += 1
print(reqr)

Solution (Python):
n = int(input())
c = input()
wc = c.count("W")
rc = c.count("R")

ans = min(c[rc:].count("R"), c[:-wc].count("W"))
print(ans)

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

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

l = n - 1
r = 0

ans = 0

while r <= l:
    if c[r] == "W" and c[l] == "R":
        ans += 1
        r += 1
        l -= 1

    else:
        if c[r] == "R":
            r += 1
        if c[l] == "W":
            l -= 1
print(ans)

Solution (Python):
n = int(input())
C = [c for c in input()]

ans = 0
l,r = 0, n-1
while(l < r):
    while(C[l] == 'R'): 
        l += 1
        if (n == l): break
    
    while(C[r] == 'W' or -1 == r):
        r -= 1
        if (-1 == r): break

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

print(ans)

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

i = 0
j = len(WR) - 1

num = 0

while(i < j):
  if(WR[j] == "R"):
    if(WR[i] == "W"):
      num += 1
      i += 1
      j -= 1
    else:
      i += 1
  else:
    j -= 1

print(num)

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

r = S.count('R')
w = 0
ans = [max(r,w)]

for i in range(N):
    if S[i] == 'W':
        w += 1
    else:
        r -= 1
    ans.append(max(w,r))

print(min(ans))

Solution (Python):
N = int(input())
C = input()
r, w = 0, 0

for c in C:
    if c == "R":
        r += 1
    else:
        w += 1
ans = 0
if r <= w:
    for c in C[:r]:
        if c == "W":
            ans += 1
    print(ans)
else:
    for c in C[r:]:
        if c == "R":
            ans += 1
    print(ans)

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

ans = 0

rgt = 0
lft = N-1

while(rgt < lft):
    if C[rgt] == "W" and C[lft] == "R":
        ans += 1
        rgt += 1
        lft -= 1


    
    else:
        if C[rgt] == "R":
            rgt += 1
        if C[lft] == "W":
            lft -= 1
print(ans)

Solution (Python):
n = int(input())
c = input()
count = 0
i, j = 0, n - 1

while i < j:
  if c[i] == 'W' and c[j] == 'R':
    count += 1
    i += 1
    j -= 1
  elif c[i] == 'W':
    j -= 1
  elif c[j] == 'R':
    i += 1
  else:
    i += 1
    j -= 1

print(count)

Solution (Python):

n = int(input())
cs = input()
r_num = 0
w_num = 0

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

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1
        R = r_num - rl_num
        ans.append(max(W, R))

    print(min(ans))

Solution (Python):

n = int(input())
cs = input()
r_num = 0
w_num = 0

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

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1
        R = r_num - rl_num
        ans.append(max(W, R))

    print(min(ans))

Solution (Python):
n = int(input())
c = input()
ans_c = "".join(sorted(c))

total = 0
miss_dct = {"R": 0, "W": 0}
for i in range(n):
    if c[i] != ans_c[i]:
        total += 1
        miss_dct[c[i]] += 1

swap = min(miss_dct["R"], miss_dct["W"])
cnt = swap
total -= swap*2
print(cnt+total)

Solution (Python):
n=int(input())
s=input()
cnt=0
ri=len(s)-1
for li,ss in enumerate(s):
  if ss=="W":
    while ri>li and s[ri]=="W":
      ri-=1
    if ri<=li:
      break
    ri-=1
    cnt+=1
print(cnt)

Solution (Python):
n=int(input())
s=input()
rcnt=s.count("R")

r_expected_arr=s[:rcnt]


w_exchange_needed=r_expected_arr.count("W")
print(w_exchange_needed)

Solution (Python):
n = int(input())
s = input()
cr = s.count("R")
cw = len(s) - cr

s_out = s[cr:]
cr_out = s_out.count("R")

print(min(cw, cr_out))

Solution (Python):
n=int(input())
s=list(input())
r=n-1
ans=0
for i in range(n):
    if s[i]=='W':
        while i<r:
            if s[r]=='R':
                s[i]='R'
                s[r]='W'
                ans+=1
                break
            r-=1
print(ans)

Solution (Python):
n = int(input())
s = list(input())
s2 = sorted(s)
A = 0
for i in range(n):
  if s[i]!= s2[i]:
    A+=1
    
print(A//2)

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):
n = int(input())
c = list(input())

r = c.count("R")
w=0
ans=r

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

Solution (Python):
n = int(input())
S = input()
c_w = 0
c_r = 0
for i in range(len(S)):
    if S[i] == 'W':
        c_w += 1
    else:
        c_r += 1
p_1 = c_w
p_2 = c_r
p_3 = 0
for i in range(c_r):
    if S[i] == 'W':
        p_3 += 1
print(min(p_1,p_2,p_3))

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

count = c.count('R')
ans = 0

for i in range(n):
    if c[i] == 'R' and i >= count:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
inp=input()
num=[0]*(n+1)

k=0
for i in range(n):
  if inp[i]=='R':k+=1
  num[i+1]=k
R=num[-1]
W=n-R

ans=float('inf')
for i in range(n+1):
  rl=num[i]
  wl=i-rl
  rr=R-rl
  wr=W-wl
  swap=min(wl,rr)
  change=max(wl,rr)-swap
  ans=min(ans,swap+change)
print(ans)

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

lft = 0
rht = 0

ans = 0

flag = False

for i in range(n):
    
    if flag == True:
        break
    if n-1-rht <= i:
        break
    if c[i] == 'W':
        for j in range(n-i):
            if n-1-j-rht == i:
                flag = True
                break
            if c[n-1-j-rht] == 'R':
                ans += 1
                rht += j+1
                break

print(ans)

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

w=A.count("W")
r=A.count("R")

W=0 ; R=r
ans=R
for i in range(n):
    if A[i]=="W": W+=1
    else: R-=1
    ans=min(ans, max(W,R))

print(ans)