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: Wrong Answer

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

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

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

a = S[:r+1].count('W')

print(a)

Submission status: Wrong Answer

Solution code:
n=int(input()) 
s=input()
a=[]
r,w=0,0
ans=float("inf")
for i in range(n):
    if s[i]=="R":
        r+=1
    else:
        w+=1
    a.append([r,w])
for i in range(n):
    r1,w1=a[i][0],a[i][1]
    r2,w2=r-r1,w-w1
    t=min(w1,r2)
    tmp=t+max(w1-t,0)+max(r2-t,0)
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
if len(set(list(s)))==1:
    print(0)
    exit()
w=[0]*(n+2)
r=[0]*(n+2)
for i in range(1,n+1):
    w[i]=w[i-1]
    r[n+1-i]=r[n+2-i]
    if s[i-1]=="W":
        w[i]+=1
    if s[n-i]=="R":
        r[n+1-i]+=1
ans=10**8
for i in range(1,n+1):
    ans=min(ans,max(r[i],w[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
lw_cnt=0
rw_cnt=0
rr_cnt=0
flg=-1
for i in range(n):
  if flg<0 and c[i]=='W':
    lw_cnt+=1
  elif flg<0 and c[i]=='R':
    flg=i
  elif flg>=0 and c[i]=='R':
    rr_cnt+=1
  else:
    rw_cnt=1
print(max(lw_cnt,rw_cnt*rr_cnt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if c.count('W') == 0:
	print(0)
else:
	if len(c)%2 == 0:
		print(max(c[0:len(c)//2].count('W'), c[len(c)//2:].count('R')))
	else:
		print(max(c[0:len(c)//2].count('W'), c[len(c)//2+1:].count('R')))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('W')].count("W"))

Submission status: Wrong Answer

Solution code:
import sys
import heapq

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


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

    Wcount=0
    Rcount =0
    rr =C.count("R")
    ww =C.count("W")


    for j in range(ww):
        if C[j]=="W":
            Rcount+=1

    for i in range(rr):
        if C[-1-i]=="R":
            Wcount+=1

    print(max(Rcount,Wcount))






if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

c = input()

k = -1
for i in range(N):
    if c[i] == 'W' and k == -1:
        k = i 

if k == -1 or k == N-1:
    print(0)
else:
    w = [0] * N
    r = [0] * N

    if c[0] == 'W':
        w[0] = 1
    if c[N-1] == 'R':
        r[N-1] = 1
    for i in range(1,N):
        if c[i] == 'W':
            w[i] = w[i-1] + 1
        else:
            w[i] = w[i-1]

        if c[N-i-1] == 'R':
            r[N-i-1] = r[N-i] + 1
        else:
            r[N-i-1] = r[N-i]

    for i in range(N):
        if w[i] == r[i]:
            print(w[i])
            break

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
w = c.count('W')
w2 = c[:w].count('W')
r2 = c[w:].count('R')
print(min(w2,r2))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

s = readline().rstrip().decode('utf-8')

#全白
res = s.count("R")
ans = min(res,len(s)-res)
count = 0
res = 0
for i in range(n-1,-1,-1):
    if count and s[i] == "W":
        res += count
        count = 0
    elif s[i] == "R":
        count += 1

ans = min(ans,res)

print(ans)

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *                      # ll = deepcopy(l)
from heapq import *                     # heappush(hp,x)
from string import *                    # alpha = ascii_lowercase
from random import *                    # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *                    # bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin                   # bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize                 # minn = -maxsize
from operator import *                  # d = sorted(d.items(), key=itemgetter(1))
from itertools import *                 # pre = [0] + list(accumulate(l))
from decimal import Decimal             # a = Decimal(a)    # use this for math questions
from collections import Counter         # d = dict(Counter(l))
from collections import defaultdict     # d = defaultdict(list)

'''
8
WRWWRWRR
'''

def solve(l):
	l = list(l)
	n = len(l)
	if(len(set(l)) == 1):
		return 0
	m1 = l.count('R')
	m2,m3 = 0,0
	f = 0
	for i in range(n):
		if(f and l[i] == 'R'):
			m2 += 1
		elif(l[i] == 'W'):
			f = 1
	f = 0
	for i in range(n-1,-1,-1):
		if(f and l[i] == 'R'):
			m3 += 1
		elif(l[i] == 'W'):
			f = 1
	return min(m1,m2,m3+1)
	

N = int(stdin.readline())
l = input()
ans = solve(l)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
idx = 0
flag = False
f = False
for i in range(N):
    if C[i] == 'W' and f:
        flag = True
    elif C[i] == 'W':
        f = True
    if C[i] == 'R' and flag:
        idx = i
        break
if flag:
    cnt = C[idx:].count('R')
else:
    cnt = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
if n % 2 == 0:
    print(min(c[:n//2].count("W"), c[n//2:].count("R")))
else:
    print(min(c[:n//2+1].count("W"), c[n//2:].count("R")))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [_ for _ in input()]

l, r = 0, n-1
if not('R' in s):
    print(0)
    exit()

if not('W' in s):
    print('0')
    exit()

ans = 0
while 1:
    while s[l] == 'R':
        l += 1

    while s[r] == 'R' and l < r:
        r -= 1

    ans += 1

    if l >= r:
        break

    l += 1
    r -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
print(s[0:n//2].count('W'))

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
chk = 0
for i in range(n):
    if C[n-1-i] == 'R':
        chk = n-1-i
        break
cnt = 1
for i in range(chk):
    if C[i] == 'R':
        cnt += 1
ans = 0
for i in range(cnt):
    if C[i] == 'W':
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappop,heappush
def main():
    N = int(input())
    S = input()
    W = []
    R = []
    ans = 0
    for i,s in enumerate(S):
        if s == 'W':
            W.append(i+1)
        else:
            R.append(-i-1)
    while (W and R):
        l = heappop(W)#小さい方から
        r = -heappop(R)#大きい方から
        if l < r:
            ans += 1#白が赤より左にあれば入れ替える

        else:
            break#そうでなければ終了
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    c = input()
    w = c.count("W")
    ans = 0
    for i in range(n):
        target = "R" if i < w else "W"
        if c[i] != target:
            ans += 1
    print(ans // 2 if 0 < w < n else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
a=[]
for i in range(n):
    if(c[i]=='R'):
        a.append(0)
    else:
        a.append(1)

zero=0
one=0
for i in range(n):
    if(a[i]==0):
        zero+=1

ans=[zero]
for i in range(n):
    if(a[i]==0):
        zero-=1
    else:
        one+=1
    #print(zero,one)
    #ans.append(max(zero,one))

print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

c = input()

k = -1
for i in range(N):
    if c[i] == 'W' and k == -1:
        k = i 

if k == -1 or k == N-1:
    print(0)
else:
    w = [0] * N
    r = [0] * N

    if c[0] == 'W':
        w[0] = 1
    if c[N-1] == 'R':
        r[N-1] = 1
    for i in range(1,N):
        if c[i] == 'W':
            w[i] = w[i-1] + 1
        else:
            w[i] = w[i-1]

        if c[N-i-1] == 'R':
            r[N-i-1] = r[N-i] + 1
        else:
            r[N-i-1] = r[N-i]

    for i in range(N):
        if w[i] == r[i]:
            print(w[i])

Submission status: Wrong Answer

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

    x = c.count('R')
    if x == n or x == 0: return 0

    w1 = 0
    for i in range(n):
        if c[i] == 'W':
            w1 += 1
        else:
            break
    
    return max(x-1, w1)
print(solve())

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from collections import deque

def solve():
    N = int(readline())
    C = readline().rstrip()

    R, W = 'R', 'W'
    reds = deque(i for i in range(len(C)) if C[i] == 'R')
    whites = deque(i for i in range(len(C)) if C[i] == 'W')

    count = 0
    print(reds, whites)
    while len(whites) > 0 and len(reds) > 0 and whites[0] < reds[-1]:
        reds.pop()
        whites.popleft()
        count += 1
    
    print(count)

solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
print(s[n//2].count('W'))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
num_r = 0
for ci in c:
    if ci == 'R':
        num_r += 1
ans = 0
if num_r != N and num_r != 0:
    for i in range(num_r+1):
        if c[i] == 'W':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
rlen=c.count("R")
wlen=c.count("W")
r=0
w=0
for i in c:
    if i=="R":
        r+=1
    else:
        w+=1
    if w==rlen-r:
        print(w)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
import collections
from heapq import *
#RRR...WWW...にしたい
N=int(input())
stones=list(input())
#print(stones)
l=0
r=N-1
wchange=0
rchange=0
cnt=0
while l<r:
    if (wchange==0)and(stones[l]=="W"):
        wchange=1
    elif stones[l]=="R":
        l=l+1

    if (rchange==0)and(stones[r]=="R"):
        rchange=1
    elif stones[l]=="W":
        r=r-1

    if wchange+rchange==2:
        buf=stones[l]
        stones[l]=stones[r]
        stones[r]=buf
        cnt=cnt+1
        wchange=0
        rchange=0
    #print(l,wchange,r,rchange,stones)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

c = input()

k = -1
for i in range(N):
    if c[i] == 'W' and k == -1:
        k = i 

if k == -1 or k == N-1:
    print(0)
else:
    w = [0] * N
    r = [0] * N

    if c[0] == 'W':
        w[0] = 1
    if c[N-1] == 'R':
        r[N-1] = 1
    for i in range(1,N):
        if c[i] == 'W':
            w[i] = w[i-1] + 1
        else:
            w[i] = w[i-1]

        if c[N-i-1] == 'R':
            r[N-i-1] = r[N-i] + 1
        else:
            r[N-i-1] = r[N-i]

    print(w)
    print(r)
    for i in range(N):
        if w[i] == r[i]:
            print(w[i])

Submission status: Wrong Answer

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

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

cnt = 0
for i in range(N - lr):
  if c[-1 -i] == "W":
    cnt += 1

ans = cnt

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

cnt = 0

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

ans = min(ans, cnt)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
for i in range(1,n):
  if(s[i]=='R'and s[i-1]=='W'):
    c+=1
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
stone = input()
red_stone = stone.count("R")
white_stone = n - red_stone

left_red_stone = stone[:red_stone].count("R")
right_white_stone = stone[:white_stone].count("W")

if left_red_stone == red_stone:
  print(0)
elif left_red_stone <= right_white_stone:
  print(red_stone-left_red_stone)
else:
  print(white_stone-right_white_stone)

Submission status: Wrong Answer

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

d = list(c)

i = 0
j = N - 1
result = 0
while i != j and i <= j and i < N:
    if d[i] == 'W':
        while d[j] != 'R' and i <= j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)

Submission status: Wrong Answer

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


N=int(input())

T=input()

S=[]
Wcount=0
Rcount=0
for i in range(N):
    S.append(T[i])
    if T[i]=="W":
        Wcount+=1
    else:
        Rcount+=1

search_count=min(Wcount,Rcount)
ans=search_count


for i in range(search_count):
    if T[i]=="R":
        ans-=1



print(ans)
    

#print(Wcount,Rcount)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
C = list(input())[:-1]
r = 0
w = 0
for s in C:
    if s == "R":
        r += 1
    elif s == "W":
        w += 1
ans = 0
if w == 0:
    print(0)
else:
    for i in range(r):
        if C[i] == "W":
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
C=[]
for i in range(N):
    C.append(c[i])
num= C.count("W")
CC=C[num:]
numnum=CC.count("W")
print(num-numnum)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
for i in range(1,n):
  if(s[i]=='R'and s[i-1]=='R'):
    c+=1
print(c)

Submission status: Wrong Answer

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

d = list(c)

i = 0
j = N - 1
result = 0
while i != j and i < j:
    if d[i] == 'W':
        while d[j] != 'R' and i < j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

firstR=S.find('R')
Sother=S[firstR+1:]
otherR=Sother.count('R')
print(firstR+otherR-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
num_r = 0
for ci in c:
    if ci == 'R':
        num_r += 1
ans = 0
if num_r != N:
    for i in range(num_r+1):
        if c[i] == 'W':
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import groupby
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n=int(input())
    c=list(input())[::-1]
    ans=0
    red=0
    for key, value in groupby(c):
        if key=='R':
            red=len(list(value))
        else:
            ans+=min(red,len(list(value)))
    print(ans)   


 
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

d = list(c)

i = 0
j = N - 1
result = 0
while i < N and i < j:
    if d[i] == 'W':
        while d[j] != 'R' and i < j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
C=np.array([x for x in input()])

if N%2==0:
  print(np.count_nonzero(C[:N//2]=='W'))
else:
  print(np.count_nonzero(C[:N//2+1]=='W'))

Submission status: Wrong Answer

Solution code:
from heapq import heappop
def main():
    N = int(input())
    S = input()
    W = []
    R = []
    ans = 0
    for i,s in enumerate(S):
        if s == 'W':
            W.append(i)
        else:
            R.append(-i)
    while (W and R):
        l = heappop(W)
        r = -heappop(R)
        if l <= r:
            ans += 1
        else:
            break
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
#from functools import reduce
from __future__ import division, print_function
mod1=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest


# sys.setrecursionlimit(10**6) 
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter
import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25 
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] 
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
    n=inin()
    a=sin()
    print(a.count('R'))















######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
s=c.count("W")
d=c[:n-s+1].count("W")
print(d)

Submission status: Wrong Answer

Solution code:
k = int(input())
cs = input()
print(cs[:len(cs)//2].count("W"))

Submission status: Wrong Answer

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

rall=c.count('R')
wlef=c[:rall+1].count('W')

print(wlef)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
import heapq ,random
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bi.bisect_right(a, x)
    if i:
        return i-1
    else:
        return -1



def main():
    try:
        n=I()
        #print(n)
        l=list(input())
        #print(l)
        t=l.count('W')
        ans=0
        for x in range(t):
            if l[x]=='W':
                ans+=1
        ans=min(ans,t-ans)
        print(ans) 
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()

Submission status: Wrong Answer

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
C=input()
L=[0]*(n+1)
R=[0]*(n+1)
for i in range(n):
  if C[i]=="W":
    L[i+1]=L[i]+1
  else:
    L[i+1]=L[i]
  if C[n-1-i]=="R":
    R[n-i-1]=R[n-i]+1
  else:
    R[n-i-1]=R[n-i]
ans=n
for i in range(n):
  cur=max(L[i],R[i])
  ans=min(ans,cur)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
ans = 0
right = n-1
for i in range(n//2):
    if s[i] == "W":
        while right > i:
            if s[right] == "R":
                s[right] = "W"
                s[i] = "R"
                ans += 1
                right -= 1
                break
            else:
                right -= 1

for i in range(n-1):
    if s[i] == "W" and s[i+1] == "R":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
    A[i+1] += A[i]
ans = float("inf")
for i in range(1, n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
A = [0]*(n+1)
cnt = 0
for i, c in enumerate(C):
    if c == "R":
        cnt += 1
        A[i+1] = 1
        A[i+1] += A[i]
ans = float("inf")
for i in range(1, n+1):
    W_l = i - A[i]
    R_r = cnt - A[i]
    temp = min(W_l, R_r) + abs(W_l-R_r)
    ans = min(ans, temp)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
import heapq ,random
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bi.bisect_right(a, x)
    if i:
        return i-1
    else:
        return -1



def main():
    try:
        n=I()
        #print(n)
        l=list(input())
        #print(l)
        t=l.count('W')
        ans=0
        for x in range(t):
            if l[x]=='W':
                ans+=1
        print(ans) 
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()

Submission status: Wrong Answer

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

N = int(input())
c = input().rstrip()
white = [0] * N
red = [0] * N
if c[0] == 'W':
    white[0] = 1
for i in range(1, N):
    white[i] = white[i-1]
    if c[i] == 'W':
        white[i] += 1
for i in range(1, N)[::-1]:
    red[i-1] = red[i]
    if c[i] == 'R':
        red[i-1] += 1
if white[-1] == 0 or red[0] == 0:
    print(0)
    exit()
for i in range(N):
    if white[i] == red[i]:
        print(i)
        exit()

Submission status: Wrong Answer

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

wa = [0] * (n+2)
for i in range(n):
    if(c[i]=='W'): wa[i+1]+=1
for i in range(n+1):
    wa[i+1] += wa[i]

ans = n;
for i in range(1, n+1):
    w = wa[i]
    r = n-i - (wa[n] - wa[i])
    ans = min(ans, max(w, r))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input().strip())

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

print(min(r, w))

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    s = i = 0
    while True:
        i += 1
        s = (s*10 + 7) % k
        if s % k == 0:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from itertools import groupby
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    G = groupby(S)
    WR = []
    for key, L in G:
        WR.append((key, len(list(L))))
    if WR[-1][0] == "W":
        WR.pop()
    if WR:
        if WR[0][0] == "R":
            WR = WR[1:]
    ans = 0
    tmp = 10**9
    for c, x in WR:
        if c == "W":
            tmp = x
        else:
            ans += min(tmp, x)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
right = n-1
for i in range(n//2):
    if s[i] == "W":
        while right > i:
            if s[right] == "R":
                ans += 1
                right -= 1
                break
            else:
                right -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
l = 0
r = N - 1
ans = 0
while l < r:
    while l < N and S[l] == "R":
        l += 1
    if l >= N: break
    
    while r >= 0 and S[r] == "W":
        r -= 1
    if r < 0: break
    ans += 1
    l += 1
    r -= 1
print(ans)

Submission status: Wrong Answer

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(n-red):
  if a[i] == 'W':
    ans += 1
print(ans)