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

ans = 0
l, r = 0, n-1
while True:
  while True:
    if c[l] == "W":
      break
    if l >= r:
      break
    l += 1
    
  while True:
    if c[r] == "R":
      break
    if l >= r:
      break
    r -= 1
  if l >= r:
    break
  ans += 1
  l += 1
  r -= 1
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
from itertools import permutations
input = sys.stdin.readline

n=int(input())
arr=list(input())
if arr[-1]=='\n':
	arr.pop()

countW=0
for i in range(n):
	if arr[i]=='W':
		countW+=1

ans=0
for i in range(n-countW):
	if arr[i]=='W':
		ans+=1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
c = list(map(str, input().split()))

def bin_search(arr, num): # num以上の最小の値を探す
    lb = -1
    ub = len(arr)

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if arr[mid] < num:
            lb = mid
        else:
            ub = mid
        
    return ub

red_list = list()
white_list = list()
for i in range(N):
    if c[0][i] == "R":
        red_list.append(i)
    else:
        white_list.append(i)

red_cnt = len(red_list)
white_cnt = len(white_list)

print(red_cnt - bin_search(red_list, red_cnt))

Submission status: Accepted

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

i = 0
j = N-1
ans = 0
while True:
    while i<N and C[i] != "W":
        i += 1
    while j>=0 and C[j] !="R":
        j -= 1
    if i>=j:
        break
    ans += 1
    i += 1
    j -= 1

print(ans)

Submission status: Accepted

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

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

A1 = [0]*(N+1)
A2 = [0]*(N+1)

t = 0
for i, s in enumerate(S):
    if s == "W":
        t += 1
    A1[i+1] = t

t = 0
for i in reversed(range(N)):
    if S[i] == "R":
        t += 1
    A2[i] = t

ans = 10**18
for a1, a2 in zip(A1, A2):
    score = abs(a1-a2) + min(a1, a2)
    ans = min(ans, score)

print(ans)

Submission status: Accepted

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

r = c.count("R")
ans = r - c[:r].count("R")
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
cc = input().rstrip()

sc = ''.join(sorted(cc))
x = 0
for i in range(n):
    if cc[i] != sc[i]:
        x += 1
print((x + 1) // 2)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int( input())
    C = list(input())
    CC = Counter(C)
    ans = min(CC["R"], CC["W"])
    r = CC["R"]
    count = 0
    for c in C[:r]:
        if c == "W":
            count += 1
    ans = min(ans, count)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

    le = 0
    ri = N - 1
    cnt = 0
    while le < ri:
        if S[le] == 'R':
            le += 1
            continue

        if S[ri] == 'W':
            ri -= 1
            continue

        cnt += 1
        le += 1
        ri -= 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=input()
l=[i for i in raw_input()]
s=0
e=n-1
ct=0
while s<e:
    if(l[s]=='W' and l[e]=='R'):
        l[s],l[e]=l[e],l[s]
        s+=1
        e-=1
        ct+=1
    if(l[s]=='R'):
        s+=1
    if(l[e]=='W'):
        e-=1
print ct

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    C = input()
    l, r = 0, N - 1
    c = 0
    while True:
        while l < r and C[l] == 'R':
            l += 1
        while l < r and C[r] == 'W':
            r -= 1
        if l >= r:
            break
        c += 1
        l += 1
        r -= 1

    return c

print(main())

Submission status: Accepted

Solution code:
N = int(input())
stones = input()
red = stones.count("R")
ans = 0
for i in range(red,N):
    if stones[i] == "R":
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
c=input()
cnt=Counter(c)

ans=0
for i in range(cnt["R"]):
    if c[i]!="R":
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
c_ls = input()
count_R = 0
for i in range(n):
    if c_ls[i] == 'R':
        count_R += 1
ans = 0
for i in range(count_R):
    if c_ls[i] == 'W':
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

R_num = C.count("R")
R_pre_num = C[:R_num].count('R')
print(R_num-R_pre_num)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
lr=0
lw=0
rr=0
rw=0
for i in range(n):
  if s[i]=='R':
    rr+=1
  else:
    rw+=1
minans=rr
for i in range(n):
  if s[i]=='R':
    rr-=1
    lr+=1
  else:
    rw-=1
    lw+=1
  ans=max(lw,rr)
  minans=min(ans,minans)
print(minans)

Submission status: Accepted

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

whites = []
reds = []
for i in range(N):
    if S[i] == 'W':
        whites.append(i)
    else:
        reds.append(i)

whites.reverse()

ans = 0
while reds and whites and whites[-1] < reds[-1]:
    whites.pop()
    reds.pop()
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
c = input()
wcnt = c.count('W')
ans = 0
it = list(reversed(c))[:wcnt]
for x in it:
    if x == 'R':
        ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N = int(input())
S = input()
Rs = S.count('R')
Ws = N - Rs

if Rs == 0 or Ws == 0:
	print(0)
	sys.exit()

C = list(S)

i = 0
j = N-1
ops = 0

while i < j:
	while i < N and C[i] == 'R': i += 1
	while j >= 0 and C[j] == 'W': j -= 1

	if i < j:
		C[i], C[j] = C[j], C[i]
		ops += 1

print(ops)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
tw = s.count("W")
cw = 0
ans = min(tw, n-tw)
for i in range(n):
    if s[i] == "W":
        cw += 1
    ans = min(ans, cw + n-i-1 - (tw-cw) - min(cw, n-i-1 - (tw-cw)))
print(ans)

Submission status: Accepted

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


white = []
for i in range(n):
    if s[i] == "W":
        white.append(i)

white = white[::-1]
if len(white) == 0:
    print(0)
    exit()
ans = 0
for i in range(n)[::-1]:
    if s[i] == "R":
        if not white:
            continue
        if i > white[-1]:
            ans += 1
            del white[-1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
C = input()
sR = [0]*(n+1)
sW = [0]*(n+1)

for i in range(n):
    sR[i+1] = sR[i] + (C[i] == "R")
    sW[i+1] = sW[i] + (C[i] == "W")

ans = 10**10
for i in range(n+1):
    r = sR[n] - sR[i]
    w = sW[i]
    ans = min(ans, max(r,w))
print(ans)

Submission status: Accepted

Solution code:
INF = 1 << 60

N = int(input())
c = [i for i in input()]

left_w = 0
right_r = c.count("R")

ans = INF

for i in range(N + 1):
    now = min(left_w, right_r) + abs(left_w - right_r)
    ans = min(now, ans)
    if i < N:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1

print(ans)

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
n = int(input())
a = input()
i1 = 0
i2 = n-1
t = 0

while i1 < i2:
	if a[i1] == "W" and a[i2] == "R":
		t += 1
		i1 += 1
		i2 -= 1
	elif a[i1] == "R":
		i1 += 1
	elif a[i2] == "W":
		i2 -= 1
print(t)

Submission status: Accepted

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

cnt_r = [0] * (n + 1)
for i in range(n):
    if c[i] == 'R':
        cnt_r[i + 1] = cnt_r[i] + 1
    else:
        cnt_r[i + 1] = cnt_r[i]

ans = n
for i in range(n + 1):
    right_r = cnt_r[n] - cnt_r[i]
    left_w = i - cnt_r[i]
    ans = min(ans, max(right_r, left_w))

print(ans)

Submission status: Accepted

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

r = 0

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

ng = 0

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

print(ng)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    s = input()
    r = s.count('R')
    w = s.count('W')
    cnt = 0
    for i in range(r):
        if s[i] == 'W':
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
rn = [0]
wn = [0]
for i in range(n):
  if s[i] == "R":
    rn.append(rn[-1]+1)
    wn.append(wn[-1])
  else:
    rn.append(rn[-1])
    wn.append(wn[-1]+1)
ans = 10**10
for i in range(n+1):
  ans = min(ans,max(wn[i],rn[-1]-rn[i]))
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
n = input()
a = min(n.count("R"),n.count("W"))
newn = n[(n.count("R")):]
b = newn.count("R")
print(min(a,b))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    c=Counter(s)
    cr=c['R']
    cw=N-cr
    if cr==N:
        print(0)
        return
    cnt=0
    for i in range(cr):
        if s[i]=="W":
            cnt+=1
    print(cnt)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

r_count=0

for i in stones:
	if i=='R':
		r_count+=1

ans=0
for i in stones[:r_count]:
	if i=='W':
		ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
ans1=0
ans2=0
for i in range(r):
    if c[i]=='W':
        ans1+=1
for i in range(r,n):
    if c[i]=='R':
        ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
c = input()
r = c.count("R")
w = c.count("W")
ans = r
cc = 0
for i in range(n):
    cc += c[i] == "W"
    ans = min(ans, abs(i+1-r) + cc)
print(ans)

Submission status: Accepted

Solution code:
num = int(input())
c_i = input()
r_Count = c_i.count("R")
print(c_i[:r_Count].count("W"))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


n = int(input())

s = list(input())

c = 0
for e in s:
    if e == 'R':
        c += 1

res = min(c,n-c)

tmp = 0
for i in range(c):
    if s[i] != 'R':
        tmp += 1

res = min(res,tmp)

print(res)

Submission status: Accepted

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

l = 0
while l < N and C[l] == "R":
    l += 1
r = N-1
while r > 0 and C[r] == "W":
    r -= 1

ans = 0
while l < r:
    if C[l] == "W" and C[r] == "R":
        ans += 1
        l += 1
        r -= 1
    elif C[l] == "W":
        r -= 1
    elif C[r] == "R":
        l += 1
    else:
        l += 1
        r -= 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())[: -1]
r = S.count("R")
res = 0
for i in range(r):
  if S[i] != "R": res += 1
print(res)

Submission status: Accepted

Solution code:
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    c = ns()
    n_r = c.count("R")
    print(c[n_r:].count("R"))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    border = S.count("R")
    ans = 0
    for i in range(N):
        if S[i] == "W" and i < border:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
line = input()
r_count = 0
for i in line:
  if i == 'R':
    r_count += 1
w_count = 0
for i in range(r_count):
  if line[i] == 'W':
    w_count += 1
print(w_count)

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
n=N()
c=input()
ans=0
w=[]
r=[]
for i,j in enumerate(c):
    if j=="W":
        w.append(i)
    else:
        r.append(i)
x=min(len(w),len(r))
for i in range(x):
    if w[i]<r[-1-i]:
        ans+=1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    c = input()
    nm = 0
    rn = 0
    for i in c:
        if i == "R":
            rn += 1

    for i in c[:rn:]:
        if i == "W":
            nm += 1

    print(nm)

    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
s = ns()

# RRRWWW
w2r = 0
r2w = s.count("R")
ans = 999999999
for i in range(n+1):
    ans = min(ans, max(w2r, r2w))
    if i < n:
        if s[i] == "W":
            w2r += 1
        else:
            r2w -= 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

answer = 0
for c in C[:r]:
  if c=='W':
    answer += 1

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
C = sys.stdin.buffer.readline().decode().rstrip()

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

Submission status: Accepted

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

Submission status: Accepted

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

N=int(input())+2
C="R"+input().strip()+"W"

W=[0]*(N+1)
R=[0]*(N+1)

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

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

ANS=1<<30
for i in range(N-1):
    ANS=min(ANS,max(W[i],R[i+1]))

print(ANS)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
c = input()

nR = c.count('R')
#nW = c.count('W')

lnR = c[:nR].count('R')
#lnW = c[:nW].count('W')

print(nR-lnR)

Submission status: Accepted

Solution code:
n = int(input())
c = input()
l, r = 0, n-1
ans = 0
while l < r:
	if c[l] == "W" and c[r] == "R":
		ans += 1
		l, r = l+1, r-1
	else:
		if c[l] == "R":
			l += 1
		if c[r] == "W":
			r -= 1
print(ans)

Submission status: Accepted

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

rcnt = cls.count('R')

wcnt = cls[:rcnt].count('W')

print(wcnt)

Submission status: Accepted

Solution code:
n = int(input())
c = input()
t = c.count('R')
ans = 0
for i in range(n):
    if c[i] == 'R' and t <= i:
        ans += 1
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())
s = input()
i = 0
j = len(s)-1
count = 0
while i<j:
    if s[i] == 'R':
        i+=1
    elif s[j] == 'W':
        j-=1
    else:
        i+=1
        j-=1
        count+=1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
string = input()
r_cnt = string.count("R")
w_cnt = string.count("W")
j = 0
cnt = 0
for i in range(r_cnt):
    if string[i] == "W":
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
c=0
for i in range(n):
  if S[i]=="R":
    c=c+1
d=0
for i in range(c):
  if S[i]=="R":
    d=d+1
print(c-d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
i=0
j=n-1
c=0
while True:
  while j>=0 and s[j]!="R":
    j-=1
  while i<n and s[i]!="W":
    i+=1
  if i>j:
    break
  c+=1
  j-=1
  i+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    S = input().strip()

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    for c in B:
        if c == 'R':
            red_cnt += 1

    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    cnt = 0
    red_cnt = 0
    B = sorted(C)
    for c in B:
        if c == 'R':
            red_cnt += 1
        else:
            break
    for i in range(red_cnt+1):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Submission status: Runtime Error

Solution code:
#参考：https://marco-note.net/abc-174-work-log/
n = int(input())
c = input()

R.count('R')
cnt = 0

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

Submission status: Runtime Error

Solution code:
n=(int)(input())
a=input().split()
sum_red=0
for i in a:
  if i=="R":
    sum_red+=1
    
sum=0
for i in range(sum_white):
  if a[i]=="W":
    sum+=1
    
print(sum)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7)

def input(): return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def readInt():return int(input())
def readIntList():return list(map(int,input().split()))
def readStringList():return list(input())
def readStringListWithSpace():return list(input().split())
def readString():return input()

n = readInt()
text = readStringList()
import collections
c  = collections.Counter(text)
if c['W'] == 0:
    print("0")
    exit()
i,j,count = 0,len(text)-1,0

while i <= j :
    if text[i] == 'W':
        while text[j] != 'R':
            j -= 1
        if i <= j:
            text[i],text[j] = text[j],text[i]
            count += 1
    i += 1
print(count)

Submission status: Runtime Error

Solution code:
# ABC174 D

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

def search(s):
    if s=='':
        return 0
    if s[0]=='R':
        return search(s[1:])
    if s[-1]=='W':
        return search(s[:-1])
    return search(s[1:-1])+1
print(search(S))

Submission status: Runtime Error

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

a = 0
b = 0

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

Submission status: Runtime Error

Solution code:
import math, sys

N=int(input())
S=input()
R_count=0
for i in range(N):
    if S[i]=="R":
        R_count+=1

ans=R_count
ind=S.index("R")
if ind>R_count:
    print(R_count)
    sys.exit()

#ans-=ind
S=S[ind:]
while S[0]=="R":
    S=S[1:]
    ans-=1
print(ans)

Submission status: Runtime Error

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 s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
    
print(num)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k == n:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
    
print(num)

Submission status: Runtime Error

Solution code:
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

if C[-1]=="R":
    for i in range(1,N):
        if C[-i]=="W":
            C=C[:-i+1]
            break    
    

print(min(C.count("R"),C.count("W")))

Submission status: Runtime Error

Solution code:
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break

for i in range(1,N):
    if C[-i]=="W":
        C=C[:-i+1]
        break    
    

print(min(C.count("R"),C.count("W")))

Submission status: Runtime Error

Solution code:
N=int(input())
C=input()
C=[str(c) for c in C]

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

print(min(C.count("R"),C.count("W")))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
x,y=0,10**9
while y>x+1:
    m = (x+y)//2
    c=0
    for i in l:
        c+=(i-1)//m
    if c<=k:
        y=m
    else:
        x=m
print(y)

Submission status: Runtime Error

Solution code:
N = int(input())
c = list(map(str, input().split()))

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: Runtime Error

Solution code:
N = int(input())
c = list(map(str, input().split()))

a=0
b=0

a = 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: Runtime Error

Solution code:
N = int(input())
c = list(map(str, input().split()))

a=0
b=0

a = c.count("R")

for i in range(N):
    if S[i] == 'R':
        a -= 1
    else:
        b += 1

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

print(ans)

Submission status: Runtime Error

Solution code:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n=int(input())
list=[]
ant=[]
str=input()
wnum=0
rnum=0
for i in range(n):
  list.append(str[i])
  if str[i]=="W":
    wnum+=1
  else:
    rnum+=1
n1=-5
n2=-5
k=0
if wnum!=0 and rnum!=0:
  for i in range(8000):
    n1=list.index("W")
    n2=n-1-ant.index("R")
    if n1<n2:
      list[n2],list[n1]=list[n1],list[n2]
#      ant[n-1-n2],ant[n-1-n1]=ant[n-1-n1],ant[n-1-n2]
      ant=list.copy()
      ant.reverse()
    else:
      print(i)
      break
else:
  print(0)

Submission status: Runtime Error

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

first_R = c.index('R')
num_R = c.count('R')

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

Submission status: Runtime Error

Solution code:
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)/2):
    if c[i] == "R":
        cou += 1
print(cou)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    int now = 0;
    rep(i,n) if(s[i]=='R') r++;
    rep(i,r) if(s[i]=='R') now++;
    cout << r-now << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
def checkFunction(c):
    count = 0

    while c[-1] == 'W':
        c = c[:-1]
    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

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

print(checkFunction(c))