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())
c = list(input())
flag = False
ans = 0
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
if c[0] == "W" and c[-1] == "R":
    ans += 1
    c[0], c[-1] = "R", "W"
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "W":
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "R":
    for i, v in enumerate(c):
        if v == "W":
            c[i] = "R"
            c[-1] = "W"
            break
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
else:
    for i, v in enumerate(reversed(c)):
        if v == "R":
            c[n-1-i] = "W"
            c[0] = "R"
            break
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
Stone_n = int(input())
Stone = input()
# R = Red
# B = Black


def Change(st1, st2):
    return st2, st1


def color(st1):
    if st1 == 'W':
        return 'R'
    elif st1 == 'R':
        return 'W'


Wcount = 0
Rcount = 0
Precolor = ''
coList = []
Start = Stone[0]
for i in Stone:
    if i == 'W':
        if Precolor == 'W':
            coList[-1] += 1
        else:
            Precolor = 'W'
            coList.append(1)
        Wcount += 1
    if i == 'R':
        if Precolor == 'R':
            coList[-1] += 1
        else:
            Precolor = 'R'
            coList.append(1)
        Rcount += 1


ans = -1

if Wcount and Rcount:
    if Wcount < Rcount:
        ans = Wcount
    else:
        ans = Rcount

    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

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

J=0
ans=0
for i in range(N):
    if C[i]=="W":
        for j in range(J,N):
            if i+j>N:break
            if C[N-1-j]=="R":
                ans+=1
                #print(i,N-1-j)
                J=j+1
                break

    if i+J+1>N:break
    
print(ans)

Submission status: Wrong Answer

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

'''
Author: andyli
Time: 2020-08-02 19:55:50
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    s = input()

    def calc(s):
        p = 0
        while p < len(s) and s[p] == 'R': p += 1
        ans = s.count('R')-p
        p = len(s)-1
        while p >= 0 and s[p] == 'W': p -= 1
        ans = min(ans, s.count('W')-(len(s)-p-1))
        return ans

    ans = calc(s)
    # print(ans)
    p1 = 0
    while p1 < n and s[p1] == 'W':
        p1 += 1
    p2 = n-1
    while p2 >= 0 and s[p2] == 'R': p2 -= 1

    cnt = min(p1, n-p2-1)
    # print(p1,p2,cnt)
    s2 = 'R'*cnt + 'W' * max(0, p1-cnt) + s[p1:p2+1] + 'R' * max(0,n-p2-1-cnt) + 'W'*cnt

    # calc(s2) + min()
    ans = min(ans, calc(s2) + cnt)
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        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)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w):]; list_w1 = mozi2[:(a-num_w)]
list_r2 = mozi2[(a-num_r):]; list_r1 = mozi2[:(a-num_r)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)

Submission status: Wrong Answer

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

wi = c.find('W')
ri = c.rfind('R')

if wi == -1 or ri == -1:
    print(0)
else:
    ans = 0
    while wi < ri:
        wi += 1
        wi = c[wi:].find('W')
        ri = c[:ri].rfind('R')
        ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input()
ans=0
lindex=0
rindex=N-1
flag=0#0:左進行,1:右進行,2:両どまり
while(1):
    if lindex>=rindex:
        break
    if flag==0:
        if A[lindex]=="W":
            flag=1
        else:
            lindex+=1

    elif flag==1:
        if A[rindex]=="R":
            flag=2
        else:
            rindex-=1
    
    else:
        ans+=1
        flag=0
        lindex+=1
        rindex-=1
if flag==1:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

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

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

def check(a, n, ct):
    L = Counter(a[:n//2])
    R = Counter(a[n//2:])
    
    ct += min(L["W"], R["R"])

    # print(a, L, R, n//2, L["W"], R["R"])
    if n // 2 != 1 and L["W"] > R["R"]:
        ct = check(a[:n//2], n // 2, ct)

    return ct

A = Counter(c)
print(min(A["W"], A["R"], check(c, N, 0)))

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
C = input()
flag = False
cnt = 0
for i in range(n):
    if not flag and C[i] == 'W':
        flag = True
    if flag:
        if C[i] == 'R':
            cnt += 1
        elif C[i] == 'W':
            if i + 1 < n:
                if C[i+1] == 'R':
                    pass
                else:
                    cnt = max(cnt-1,0)
            else:
                cnt = max(cnt-1,0)
r = C.count('R')
nya = 0
for i in range(r,n):
    if C[i] == 'R':
        nya += 1
a = 0
for i in range(n-1):
    if C[i] == 'W' and C[i+1] == 'R':
        a += 1
print(max(min(nya,cnt), a))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
cnt=0
lst=list(str(input()))
y=collections.Counter(lst[:(n//2)])
Ry=y["R"]
Wy=y["W"]
z=collections.Counter(lst[(n//2):])
Rz=z["R"]
Wz=z["W"]
cnt+=Rz
print(cnt)

Submission status: Wrong Answer

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

wi = c.find('W')
ri = c.rfind('R')

if wi == -1 or ri == -1:
    print(0)
else:
    ans = 0
    while wi < ri:
        wi += 1
        wi = c[wi:].find('W')
        ri = c[:ri].rfind('R')
        ans += 1

    print(ans, c)

Submission status: Wrong Answer

Solution code:
#D - Alter Altar
N = int(input())
c = input()
W_r = 0
r = 0
w = 0

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

if c[0]=="W" and c[1]=="W" and r >= 2:
    W_r += 1
else:
    pass



for i in range(1,N):
    if c[i-1]=="W" and c[i]=="R" :
        W_r += 1
    else:
        pass

if r == 0:
    W_r = 0

# print(r,w)
print(W_r)

Submission status: Wrong Answer

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

qw=deque(list())
qr=deque(list())

ans=0
for i in range(N//2):
    if C[i]=='W':
        qw.append(i)
    if C[-(i+1)]=='R':
        qr.append(-(i+1))
    if len(qw)>0 and len(qr)>0:
        ans+=1
        l=qw.popleft()
        r=qr.popleft()
        C[l],C[r]=C[r],C[l]

if len(qw)>0:
    l=qw.popleft()
    if C[l+1]=='R':
        C[l+1]='W'
        ans+=1
elif len(qr)>0:
    r=qr.popleft()
    if C[r-1]=='W':
        C[r-1]='R'
        ans+=1


print(ans)

Submission status: Wrong Answer

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

count = 0
while(True):
    #print(S)
    HeadW = S.find('W')
    TailR = len(S) - S[::-1].find('R')
    
    if(HeadW == -1 or TailR == -1):
        break

    elif(HeadW == TailR):
        break

    elif(HeadW != -1 and TailR != -1):
        S = S[:HeadW] + 'R' + S[HeadW+2:]
        S = S[:TailR] + 'W' + S[TailR+2:]
        count += 1
    
    elif(HeadW == -1):
        count += S[HeadW:].count('R')
        break

    elif(TailR == -1):
        count += S[:TailR].count('W')
        break


print(count)

Submission status: Wrong Answer

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

w_num = c_array.count('W')
r_num = n-w_num
def get_ans(half):
    wl_num = c_array[:half].count('W')
    rr_num = c_array[half:].count('R')

    if w_num == 0 or r_num == 0:
        ans = 0
    else:
        ans = min(wl_num, rr_num) + abs(wl_num-rr_num)
    return ans

ans = min(get_ans(w_num), w_num, r_num)
print(ans)

Submission status: Wrong Answer

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

# 色を変えるのは、１つの石のみで、遅い
# 入れ替える場合はは、赤と白が左と右にある場合２つの石に効果を上げられるのでよい
# まずは入れ替えを考え、これ以上入れ替えれない（効果が少ない時）色を変える
# 理想は、wwww,,,RRRRと並ぶこと

def is_ok(c):
  s = True
  # どこかにW->Rの変化がある場合、false
  for i, p in enumerate(c[:-1]):
    if p == 'W':
      if c[i+1] == 'R':
        s = False
        break
  return s

if is_ok(c):
  print(0)
  exit()


# 下では最小となっていない
# 最小になるためには、Wだけ、Rだけにする方が早い場合もある

# WとRの数で、並べると最後の正解の並び方がわかり、それと最初との差分を取ることができるはず
Wn = len([x for x in c if x == 'W'])
Rn = len([x for x in c if x == 'R'])
# print(Wn, Rn)
c_r = 'R'*Wn+'W'*Rn
# print(c_r)
# print(c)

w_cnt = 0
for i in range(len(c)):
  if c_r[i] != c[i]:
    w_cnt += 1
# print(w_cnt)

# 入れ替えで最小にする場合の最小数
# 間違いが偶数だとそのまま割り算で答え、奇数だと1を足した操作数
if w_cnt % 2 == 0:
  a_c = int(w_cnt/2)
else:
  a_c = int((w_cnt+1)/2)
# print('a_c', a_c)

# WRRの場合は、WをRに変える方が早い
c_rr = 'R' * len(c)
r_cnt = 0
for i in range(len(c)):
  if c_rr[i] != c[i]:
    r_cnt += 1
a_r = r_cnt
# print('a_r', a_r)

print(min([a_c, a_r]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(input())
a = 0
B = []
for i in range(N):
    if A[i] == 'W':
        a += 1
    B.append(a)
if a >= N - a:
    ans = B[N - a]
else:
    ans = B[a]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
li = list(input())
i = 0
k = 1
counter = 0
done = 0
while True:
    if done == 1:
        break
    if i + 1  > n/2:
        break
    if li[i] == "W":
        while True:
            if li[-k] == "R":
                li[i] = "R"
                li[-k] = "W"
                counter += 1
                k += 1
                break
            k += 1
            if k+i == n:
                done = 1
                counter += 1
                break
    i += 1
    if i+k == n:
        break
print(counter)

Submission status: Wrong Answer

Solution code:
N=int(input())
rw=input()
count=0
s=len(rw)
i=0
j=s-1

while i<=j:
  while (rw[i]=='R' and i<s-1):
        i+=1
  while (rw[j]=='W' and j>0):
        j-=1
  if rw[i]=='W' and rw[j]=='R':
      count+=1
  i+=1
  j-=1


print(count)

Submission status: Wrong Answer

Solution code:
#n = int(input(''))
#clist = input('')
n=2
clist="RR"

wcnt=clist.count("W")
rcnt=clist.count("R")

clist1 = clist[0:rcnt]

wcnt2 = clist1.count("W")

print(wcnt2)

Submission status: Wrong Answer

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

count = 0
for i in range(1, N):
    if c[i] == 'W':
        count += 1
print(count)

Submission status: Wrong Answer

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

l_tmp = 1
r_tmp = -1
# カウント
count = 0
# デバック
# print("    ", s)
# RRRRWW みたいにRを左におしやりたい
for i in range(n):
    if l_tmp - r_tmp - 1 >= n:
        break

    if s[l_tmp - 1] == "R":
        l_tmp += 1
        # print("cont", s)
        continue

    if s[l_tmp - 1] == "W":
        if s[r_tmp] == "R":
            # 交換処理
            s[l_tmp - 1] = "R"
            s[r_tmp] = "W"
            #
            l_tmp += 1
            r_tmp -= 1
            # カウント
            count += 1
            # デバック
            # print("chan", s)
            continue

        if s[r_tmp] == "W":
            # 更新処理
            s[l_tmp - 1] = "R"
            #
            l_tmp += 1
            # カウント
            count += 1
            # デバック
            # print("chan", s)
            continue

addon_count = 0
tmp = sorted(s)
for i in range(n):
    if tmp[i] != s[i]:
        addon_count += 1

print(count + addon_count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
N = int(input())
c = list(input())
n = 0
OK = False
while not OK:
    ni = 0
    OK = True
    for i in range(N - 1):
        if c[i] == 'W' and c[i + 1] == 'R':
            c[i] = 'R'
            ni += 1
            OK = False
    ni = (ni + 1) // 2
    n += ni
print(n)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import numpy as np

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

    W_list = np.zeros(N)
    R_list = np.zeros(N)
    for i in range(N):
        if i == 0:
            if c[i] == 'W':
                W_list[i] = 1
            else:
                W_list[i] = 0
        else:
            if c[i] == 'W':
                W_list[i] = W_list[i-1] + 1
            else:
                W_list[i] = W_list[i-1]

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

    ans = 0
    for i in range(N):
        if W_list[i] == R_list[i]:
            ans = W_list[i]
            break
    print(int(ans))
    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
def main():
    N = int(input())
    S = list(input())
    if len(set(S))==1:
        print(0)
        return
    cnt = 0
    left = 0
    right = len(S)-1
    while left<right:
        if S[left] == 'W':
            cnt +=1
            left += 1
            right -=1
        while left<len(S) and S[left]=='R':
            left += 1
    print(cnt)
    return 0
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a = int(input())
s = input()
ns = a//2
new = s[0:ns]
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

N = int(input())
C = input()
M = ['']

w_c = 0
r_c = 0
S = ''
for i in range(N):
    if C[i] == 'W':
        if r_c != 0:
            if 'W' in M[-1]:
                M[-1] += S
            else: M.append(S)
            S = ''
            r_c = 0
        w_c += 1
        S += 'W'
    else:
        if w_c != 0:
            M.append(S)
            S = ''
            w_c = 0
        r_c += 1
        S += 'R'
if 'W' in M[-1]:
    M[-1] += S
else: M.append(S)

ret = 0
for m in M[1:]:
    w_c = m.count('W')
    r_c = m.count('R')
    ret += min(w_c, r_c)

print(ret)

Submission status: Wrong Answer

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

count=0
for i in range(int(k/2)):
    if s[i]=="W":
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
C = input()
flag = False
cnt = 0
for i in range(n):
    if not flag and C[i] == 'W':
        flag = True
    if flag:
        if C[i] == 'R':
            cnt += 1
        elif C[i] == 'W':
            if i + 1 < n:
                if C[i+1] == 'R':
                    pass
                else:
                    cnt = max(cnt-1,0)
            else:
                cnt = max(cnt-1,0)
r = C.count('R')
nya = 0
for i in range(r,n):
    if C[i] == 'R':
        nya += 1

print(min(nya,cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())

c = list(input())

cnt = 0
headcnt = 0
tailcnt = -1

Noflag = 0

while True:
    if c[tailcnt] == 'R':
        while True:
            if c[headcnt] == 'W':
                c[headcnt], c[tailcnt] = c[tailcnt], c[headcnt]
                cnt += 1
                headcnt += 1
                tailcnt -= 1
                break
            else:
                headcnt += 1
                if headcnt >= len(c):
                    print(0)
                    Noflag += 1
                    break
    else:
        tailcnt -= 1
    
    if headcnt + abs(tailcnt) >= len(c) and Noflag == 0:
        print(cnt)
        break
    elif Noflag>=1:
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
data = input()
intdata = []
ans = 0
for d in data:
  if d == "R":
    intdata.append(0)
  else:
    intdata.append(1)

sortdata = sorted(intdata)

if len(intdata) % 2 == 0:
  amari = 0
else:
  amari = 1

for i in range(int(len(intdata)/2)):
  if intdata[i] != sortdata[i]:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    R_l=c.find('R')
    R_n=c.count('R')

    ans=0

    if c.find('WR')==-1:
        print(0)
    else:
        R_info=[]
        p=0
        for i in range(N):
            if c[i]=='R':
                R_info.append(p)
                p=0
            else:
                p+=1

        # print(R_info)
        for i,n in enumerate(R_info):
            # print(i)
            if n==0:
                R_n-=1
            elif n>=1 and R_n-i-1>=n:
                R_n-=n+1
                ans+=1
                # print(ans)
            else:
                ans+=R_n
                # print(ans)
                break
        print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

isiall = min(saidan.count('W'), saidan.count('R'))

tesuu = 0
for i in range(len(saidan)//2):
    r_iti = saidan.rfind('R')
    w_iti = saidan.find('W')
    
    if r_iti == -1 or w_iti == -1:
        break
    
    saidan = saidan[w_iti+1 : r_iti]
    tesuu += 1
    
print(min(tesuu, isiall))

Submission status: Wrong Answer

Solution code:
def function(N, c):
    num_R = c.count('R')
    num_W = c.count('W')
    if (num_R == 0) or (num_W == 0):
        return 0
    else:
        num = 0
        for i in range(int(N/2)):
            if c[i] == 'R':
                num += 1
        if num_R == 1:
            if c[0] == 'R':
                return 0
            else:
                return 1
        else:
            return num_R-num


if __name__ == '__main__':
    N = int(input())
    c = input()
    print(function(N, c))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
d = [0] * N
for i in range(N):
    if c[i] == 'R':
        d[i] = 1
count = 0
for i in range(0, N//2 + 1):
    if d[i] == 0:
        for j in reversed(range(0, N)):
            if d[j] == 1:
                d[i] == 1
                d[j] == 0
                count += 1
                break
            if j == i:
                d[j] = 1
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

'''
Author: andyli
Time: 2020-08-02 19:55:50
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    s = input()

    def calc(s):
        p = 0
        while p < len(s) and s[p] == 'R': p += 1
        ans = s.count('R')-p
        p = len(s)-1
        while p >= 0 and s[p] == 'W': p -= 1
        ans = min(ans, s.count('W')-(len(s)-p-1))
        return ans

    ans = calc(s)
    # print(ans)
    p1 = 0
    while p1 < n and s[p1] == 'W':
        p1 += 1
    p2 = n-1
    while p2 >= 0 and s[p2] == 'R': p2 -= 1

    cnt = min(p1, n-p2-1)
    # print(p1,p2,cnt)
    s2 = 'W' * max(0, p1-cnt) + s[p1:p2+1] + 'R' * max(0,n-p2-1-cnt)

    # calc(s2) + min()
    ans = min(ans, calc(s2) + cnt)
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        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)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            for x in reversed(range(i,chk+1)):
                if C[x] == 'R':
                    chk = x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1

    print(cnt)

main_chk()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
cnt=0
lst=list(str(input()))
y=collections.Counter(lst[:(n//2)])
Ry=y["R"]
Wy=y["W"]
z=collections.Counter(lst[(n//2):])
Rz=z["R"]
Wz=z["W"]
if Rz>Ry:
  cnt+=min(Rz, Wy)
else:
  cnt+=min(Ry, Wz)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w+1):]; list_w1 = mozi2[:(a-num_w+1)]
list_r2 = mozi2[(a-num_r+1):]; list_r1 = mozi2[:(a-num_r+1)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    # print(i+1,"回目")
    # print("exchange=",exchange)
    # print("c=",c)
    if N-i < exchange:
        if c[-(i+1)] =="R":
            # c = list(c)
            # c[exchange] = "R"
            # c[-(i+1)] = "W"
            # c = "".join(c)
            c = c[:exchange]+"R"+c[exchange+1:]
            print("newc=",c)
            c = c[:-(i+1)]+"W"+c[N-i:]
            # print("newc=",c)
            ans += 1
            for k in range(exchange+1,N):
                if c[k] == "W":
                    exchange = k
                    break
            else:
                break
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
C = input()
print(C.count('WR'))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
    s = c[:wc]
    wwc = wc-s.count('R')
    if wwc <= rc:
      print(wwc)
    else:
      print(rc)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
if s.count('R')==0 or s.count('W')==0:
    print(0)
else:
    a= s.count('W')
    w=s.index('W')
    b= s[w:].count('R')
    if b==0:
        print(0)
    else:
        c = s[(w+1):].count('W')
        t=min(b,c)
        print(min(t,a))

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)
        t1=l.count('W')
        t=min(t1,n-t1)
        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 collections

N = int(input())
cs = list(input())


count_R = cs.count("R")
count_W = cs.count("W")

W_check = cs[: count_W]
R_check = cs[count_R:]

print(min(W_check.count("W"), R_check.count("R")))

Submission status: Wrong Answer

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

if "WR" not in C:
  print(0)
elif C[:2]=="WR":
  print(C.count("R")-1)
else:
  print(C.count("R"))

Submission status: Wrong Answer

Solution code:
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

def main_chk():
    N=int(input())
    C=input()

    chk = N - 1
    cnt = 0

    for i in range(N):
        if C[i] == 'W':
            for x in reversed(range(i+1,chk+1)):
                if C[x] == 'R':
                    chk = x
                    break
            if chk <= i:
                break
            else:
                cnt = cnt + 1
                chk = chk - 1

    print(cnt)

main_chk()

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
ans = 0
cnt = c.count("W")
ans = c[N-4:].count("R")
if cnt != 0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
l,r=0,n-1
ans=0
while l<r:
    while c[l]!='W':
        l+=1
        if l>n-1:
            break
    while c[r]!='R' or r>=0:
        r-=1
        if r<0:
            break
    if l<r:
        ans+=1
        l+=1
        r-=1
print(ans)

Submission status: Wrong Answer

Solution code:
# D Alter Altar

n = int(input())
C = input()

num_R = C.count("R")

if len(C) == num_R or num_R == 0:
  print(0)
  exit()

space = 0
for c in C:
  if c == "W":
    space += 1
  elif c == "R":
    break

if num_R <= space:
  print(num_R)
else:
  print(num_R - 1)