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



Sample input:
4
WWRR


Sample output:
2

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
C=list(input())

# RRRRWWWW ok
count=Counter(C)
ws=count["W"]
rs=count["R"]

outws=0
outrs=0
for i in range(N):
    c=C[i]
    if c=="R":
        if not 0<=i<rs:
            outrs+=1
    else:
        if 0<=i<rs:
            outws+=1

ans=max(outrs, outws)
print(ans)

Submission status: Accepted

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

a, b = 0, 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
    tmp = max(a, b)
    ans = min(ans, tmp)

print(ans)

Submission status: Accepted

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

if "R" not in C:
    print(0)
    exit()

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

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

Submission status: Accepted

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

r = s.count('R')

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x = input().strip()
cnt = 0
for i in range(N):
    if x[i]=="R":
        cnt += 1
if cnt==0 or cnt==N:
    print(0)
else:
    ans = 0
    for i in range(cnt):
        if x[i]=="W":
            ans += 1
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline
N = int(input())
C = list(input().strip())

counter = Counter(C)
if len(counter) == 1:
    print(0)
else:
    red_n = counter["R"]
    ans = 0
    for i in range(N):
        if red_n <= i:
            break
        if C[i] == "W":
            ans += 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
check = s.count("R")
q = s[:check]
print(q.count("W"))

Submission status: Accepted

Solution code:
from collections import Counter


N = int(input())
c = input()
cntr = Counter(c)

ans = 0
for c, r in zip(c, "R" * cntr["R"]):
    if c != r:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
# Nとcの定義
N = int(input())
C = input()

# 赤色の個数
red_num = str.count(C, "R")

# 左からred_num個までに含まれる白色の個数
white_num_left = str.count(C[:red_num], "W")

# 最小の操作回数
min_ope = white_num_left

# 最小の操作回数の出力
print(min_ope)

Submission status: Accepted

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

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

Submission status: Accepted

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

n=0
c=0
for i in range(N)[::-1]:
    if C[i]=="R":
        while n<i:
            if C[n]=="W":
                c+=1
                n+=1
                break
            n+=1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
Stones = list(input())

count_red = 0
count_white = 0

for i in range(N):
  if Stones[i] == "R":
    count_red += 1
    
for i in range(count_red):
  if Stones[i] == "W":
    count_white += 1
    
print(count_white)

Submission status: Accepted

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

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

Submission status: Accepted

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

f = 0
b = N - 1
ans = 0

while True:
    while  f <= N -1 and C[f] == "R":
        f += 1
    while b >= 0 and C[b] == "W":
        b -= 1
    if f > b:
        print(ans)
        break
    ans += 1
    f += 1
    b -= 1

Submission status: Accepted

Solution code:
n = int(input())
c = list(input())
rcnt = 0
allrcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        allrcnt += 1
for i in range(len(c)):
    if i+1<=allrcnt and c[i]=='R':
        rcnt += 1

ans = allrcnt-rcnt

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
for i in range(len(c)):
    if i+1<=rcnt and c[i]=='R':
        hrcnt += 1

wcnt = len(c)-rcnt
if rcnt==len(c) or rcnt==0:
    ans = 0
else:
    ans = rcnt-hrcnt

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

c = list(input())
cnt = 0
l = 0
r = n-1
while l < r:
    while c[l] == "R" and l < r:
        l += 1

    while c[r] == "W" and l < r:
        r -= 1

    if c[l] == c[r]:
        break

    c[l], c[r] = c[r], c[l]

    l += 1
    r -= 1
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n = int(input())
    C = input()
    C_cunt = Counter(C)
    cunt_r = C_cunt['R']
    ans = 0
    for i in range(cunt_r):
        if C[i] == 'W':
            ans += 1
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import math
n = int(input())
ar = input()
w = 0
r = 0
ans = 0
for i in ar:
  if i == 'W':
    w += 1
  else:
    r += 1
if w == 0 or r == 0:
  print(ans)
else:
  for j in range(-1,-len(ar)-1,-1):
    if w == 0:
      break
    if ar[j] == 'R':
      ans += 1
    w -= 1
  print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
c=list(input().rstrip("\n"))
import collections
cc=collections.Counter(c)
ans=0
for i in range(cc["R"]):
    if c[i]=="W":
        ans+=1
print(ans)

Submission status: Accepted

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

#仕切りの右側の赤石の数rr
#仕切りの左側の赤石の数rl
rr, rl = c.count("R"), 0

#全ての石の色が同じ場合
if rr == 0 or rr == N:
  print(0)
  exit()

#仕切りの右側の白石の数wr
#仕切りの左側の白石の数wl
wr, wl = N - rr, 0

for i in range(N + 1):
  if i == 0:
    ans = min(rr, wr)
    continue

  if c[i-1] == "R":
    rr -= 1
    rl += 1
  else:
    wr -= 1
    wl += 1

  if rr >= wl:
    ans = min(ans, rr)
  else: ans = min(ans, wl)

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#cを[R,R,R,.....,R,W,W,W,.....,W]の形にする。

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
#実質 ans = max(c_for.count('W'), c_lat.count('R')) やんけ！

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#import re

N = input()
stones = input()
#pattern = 'W.*R'
#stoneslist =list(stones)
#result = re.search(pattern,stones)
#if result:
 # print (result.start())
  #print (result.end())
#print(stones[result.start()])
#stoneslist[result.start()]='R'
#stoneslist[result.end()-1]='W'

count =0
#while 'WR' in stones:
 # if stones.count('WR')>1:
  #  stoneslist =list(stones)
   # result = re.search(pattern,stones)
    #stoneslist[result.start()]='R'
    #stoneslist[result.end()-1]='W'
    #stones =str(stoneslist)
    #stones = "".join(stoneslist)
  #else:
   # stones = stones.replace('WR','RR',1)
  #count+=1
  #print(stones)

#print (stones)

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)
#print (count)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
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()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

Solution code:
N = int(input())
#stones = list(input())
stones = input()
#print(stones)
a = stones.count('W')
b = stones.count('R')
 
left_side =stones.count('W', 0, b)
 
print(left_side)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# 全て赤にする
# 全て白にする
# 垢を左に集める

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
    #print(s[:i], s[i:], s[i], left_w, right_r)
    count.append(max(left_w,right_r))
print(min(count))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())

R=S.count("R")

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

print(W)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D - Alter Altar
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)

Submission status: Accepted

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

num_R = c.count('R')

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def main(s):
  a = 0 #r-w 
  b = 0 #w-r 
  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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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(Rc)
    # print(Wc)
    print(c)
    pass

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
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
#  if r==N or w==N:
#    print(0)
#    return 
  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()
#解説AC

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ciが R のとき赤、W のとき白です。
#入力
#N
#c1...cN

N = int(input())
C = input()
Rednum = C.count('R')
#print(Rednum)
#Rの数 - 左にある赤の数が答
NewC = C[:Rednum]
#print(NewC)
Whinum = NewC.count('R')

print(Rednum - Whinum)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


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:
            # S[l] == 'W' S[r] == 'R' l < r
            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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

cntR = c.count('R')

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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