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=input()
if N%2==0:
    print(min(c[:N//2].count('W'),c[N//2:].count('R')))
else:
    print((min(c[:(N+1)//2].count('W'),c[(N+1)//2:].count('R'))))

Submission status: Wrong Answer

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

n=int(input())
c=input().rstrip()

l=0
r=n-1
ans=0
while True:
    while c[l]=='R':
        l+=1
        if l==n:
            break
    while c[r]=='W':
        r-=1
        if r==-1:
            break
    if l>r:
        break
    ans+=1
    l+=1
    r-=1

temp=0
for i in c:
    if i=='R':
        temp+=1
temp=min(temp,n-temp)
ans=min(ans,temp)

Submission status: Wrong Answer

Solution code:
n=int(input())

c=input()

wnum=0

for i in range(n):
    if c[i]=="W":
        wnum+=1

cnt=0
for ci in c[:wnum]:
    if ci=="W":
        cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    c=input()
    
    #x...WR
    #o...RR, RW, WW
    #Wが来たらそれ以降はW
    #R(0個以上)+W(0個以上)
    
    i=0
    while 'WR' in c:
        x=c.index('WR')  
        y=N-c[::-1].index('R')-1
        #print(x,y)
        c=c[:x]+'R'+c[x+1:y]+'W'+c[y+1:]
        #print(c)
        i+=1
        
    print(min(c.count('R'),c.count('W'),i))
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

stones = input()

Rn = 0
W = -1
for i, stone in enumerate(stones[::-1]):
    if stone == 'R':
        Rn += 1
    else:
        W = N - i - 1
        break
Wn = 0
if W < 0:
    print(0)
else:
    for i, stone in enumerate(stones):
        if i < W:
            if stone == 'W':
                Wn += 1
        else:
            break

    if Wn >= Rn:
        print(Wn)
    else:
        print(Wn+1)

Submission status: Wrong Answer

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

ans = 0
if C[0] == 'W':
    ans += 1

c = C[1::]

for i in range(len(c) - 1):
    if c[i] == 'W' and c[i + 1] == 'R':
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = input()
    #rn = s.count("R")
    #wn = s.count("W")
    #red = 0
    #white = 0
    l = 0
    r = n-1
    ans = 0
    while(True):
        if(l >= n or r < 0):
            break
        if(s[l] == "R"):
            l += 1
            continue
        else:
            while(s[r] == "W"):
                if(r < 0):
                    print(0)
                    return
                r -= 1
            l += 1
            r -= 1
            ans += 1
            if(l >= r):
                break
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
ls=list(input())
r_ls = [i for i,v in enumerate(ls) if v=='R']
w_ls = [i for i,v in enumerate(ls) if v=='W']
end_flag = False
if len(r_ls) == 0 or len(w_ls) == 0:
    end_flag = True
else:
    r_mx, w_min = max(r_ls), min(w_ls)
    max_try = min(len(r_ls), len(w_ls))

r_i, w_i = -1, 0

if end_flag:
    print(0)
elif r_mx < w_min:
    print(0)
else:
    c = 0
    for i in range(max_try):
        c += 1
        r_ls[r_i], w_ls[w_i] =  w_ls[w_i], r_ls[r_i]
        if i == max_try -1 or w_ls[w_i] < w_ls[w_i + 1]:
            print(c)
            break
        else:
            r_i -= 1
            w_i += 1

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
r = 0
w = 0
l = 0
ans = 0
for i in range(n):
    if c[i] == "W":
        w += 1
    else:
        r += 1
        if i < n / 2:
            l += 1
res = 0
if r == 0 or w == 0:
    print(0)
    exit()
elif w < r:
    ans += r - w
    r = w

ans += r - l
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
w_count = c[:len(c)//2].count("W")
r_count = c[len(c)//2:].count("R")

if (w_count == 0)|(r_count==0):
    print(0)
else:
    print(w_count) if w_count < r_count else print(r_count)

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import Counter

n = ii()
s = input()

d = Counter(s)
num = d['R']
ans = num
wcnt = 0
rcnt = 0
for i in s:
    if i == 'W':
        wcnt += 1
    else:
        if num - 1 > wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt
            wcnt = 0
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = input()
a = A.count('W')
b = A.count('R')
c = A[:n//2]
d = A[n//2:]
e = c.count('W')
f = d.count('R')
g = max(e,f)
print(min(a,b,g))

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

print(count)

Submission status: Wrong Answer

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

j = N-1
count = 0
for i in range(N):
    if RW[i]=='W':
        while i<j:
            if RW[j]=='R':
                count += 1
                break
            j -= 1

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=list(input())
k=0
for i in range(N):
    if c[i]!='R':
        k=i
        break
R=c[k:].count('R')
W=c[k:k+R+1].count('W')
print(W)

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] == 'W' and l < r:
        r -= 1

    ans += 1
    l += 1
    r -= 1

    if l >= r:
        break
    # print(l, r)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
if c.count("R")==0 or c.count("W")==0:
    print(0)
else:
    W_count=0
    R_count=0
    for i in range(N//2):
        if c[i]=="W":
            W_count+=1
        else:
            R_count+=1
    print(min(c.count("R"),c.count("W"),max(W_count,R_count)))

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    c = list(SS())
    c_r = c[::-1]

    # 一番左のRより右にあるWの数か一番右のWより左にあるRの数
    if 'R' not in c or 'W' not in c:
        print(0)
    else:
        idx_R = c.index('R')
        ans0 = c[idx_R:].count('W')
        idx_W = c_r.index('W')
        ans1 = c_r[idx_W:].count('R')
        print(min(ans0, ans1))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
# C = [c for c in input().strip()]
C = input().strip()

cnt = 0

def is_ok(c):
    r = c.rfind("R")
    w = c.find("W")
    return r < w


def rep(i, c, r, w):
    if i == r:
        return "W"
    elif i == w:
        return "R"
    else:
        return c

while not is_ok(C):
    cnt += 1
    r = C.rfind("R")
    w = C.find("W")
    C = "".join([
        rep(i, c, r, w)
        for i, c in enumerate(C)
    ])
    # break

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
lc=len(c)
if "W" not in c or "R" not in c:
    print(0)
else:
    ctr = c.count("R")
    if c[0] == "W":
        print(min(ctr-1, lc-ctr))
    else:
        c.pop(0)
        print(min(ctr, lc-ctr))

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
c = input()
d = deque()
a = 0; b = 0
for i in range(n):
    d.append(c[i])
for _ in range(len(d)):
    if d[0] == "R":
        d.popleft()
    else:
        break
for _ in range(len(d)):
    if d[-1] == "W":
        d.pop()
    else:
        break
for _ in range(len(d)//2):
    if d[-1] == "R": a += 1
    d.pop()
for _ in range(len(d)):
    if d[0] == "W": b += 1
    d.popleft()
print(min(a, b))

Submission status: Wrong Answer

Solution code:
def _run(N, colors):
    double_c = 0
    single_c = 0
    right_exists_red = False
    for i in range(0, N - 1)[::-1]:
        if i == 0:
            current = colors[i:i + 2]
            if current == "WR":
                double_c += 1
            elif right_exists_red and current == "WW":
                single_c += 1
        else:
            current = colors[i - 1:i + 2]
            if current == "RWR":
                double_c += 1
                right_exists_red = False
            elif current == "WWR":
                single_c += 1
                right_exists_red = True
            elif right_exists_red and current[1:] == "WW":
                single_c += 1
            elif right_exists_red and current[0:2] == "RW":
                double_c += 1
            else:
                right_exists_red = False

    print(double_c // 2 + double_c % 2 + single_c)


def _main():
    N = int(input())
    colors = str(input())
    _run(N, colors)


if __name__ == "__main__":
    _main()

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import Counter

n = ii()
s = input()

d = Counter(s)
num = d['R']
ans = num
wcnt = 0
rcnt = 0
for i in s:
    print(i)
    if i == 'W':
        wcnt += 1
    else:
        if num - 1 > wcnt or wcnt == 0:
            ans -= 1
            num -= wcnt
            wcnt = 0
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(input())
cr = al.count('R')
cr2 = cr//2
ans = 0
flag = False
flag2 = False
for a in al[::-1]:
    if not flag and a == 'R':
        cr2 -= 1
        if cr2 == 0:
            flag = True
            continue

    if flag and not flag2 and a == 'R':
        flag2 = True
        continue

    if flag2 and a == 'W':
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
# C = [c for c in input().strip()]
C = input().strip()

cnt = 0

def is_ok(c):
    r = C.rfind("R")
    w = C.find("W")
    return r < w


def rep(i, c, r, w):
    if i == r:
        return "W"
    elif i == w:
        return "R"
    else:
        return c

while not is_ok(C):
    cnt += 1
    r = C.rfind("R")
    w = C.find("W")
    C = "".join([
        rep(i, c, r, w)
        for i, c in enumerate(C)
    ])
    # break

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(input())
r=0
for i in l:
    if i=="R":
        r+=1
cr=0
cw=0
for i in range(len(l)):
    if l[i]=="R":
        cr+=1
    else:
        cw+=1
    if cw==r-cr:
        break
print(cw)

Submission status: Wrong Answer

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

l = 0
r = N-1
ans = 0
while(l < r):
    while(l < N and c[l] == 'R'):
        l += 1
    while(r >= 0 and c[r] == 'W'):
        r -= 1
    if l >= N or r < 0:
        break
    else:
        if l-1 == r:
            ans += 1
            break
        else:
            l += 1
            r -= 1
            ans += 1

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)
        t1=l.count('W')
        t=min(t1,n-t1)
        ans=0
        for x in range(t):
            if l[x]=='W':
                ans+=1
        ans=min(ans,n-t1)
        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:
n=int(input())
c=input()
r=c.count('R')
w=c.count('W')
rch=c[:r].count('W')
wch=c[r:].count('R')
print(min(rch,wch))
print(r,w,rch,wch)

Submission status: Wrong Answer

Solution code:

import collections


def main():
    n = int(input())
    c = list(input())
    wcnt = c.count("W")
    rcnt = c.count("R")
    if wcnt == 0 or rcnt == 0:
        print(0)
        return
    ans = c[0:wcnt].count("W")
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
st = input()
from collections import deque
st = deque(st)

cnt = 0
while len(st) > 1:
    if st[0] == 'W' and st[-1] == 'R':
        cnt += 1
        st.popleft()
        st.pop()
    elif st[0] =='R' and st[-1] == 'R':
        st.popleft()
    elif st[0] == 'R' and st[-1] == 'W':
        st.popleft()
    else:
        if 'R' in st:
            cnt += 1
            st.popleft()
        else:
            break
print(cnt)

Submission status: Wrong Answer

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

cnt1 = 0
for v in c[: n // 2]:
    if v == "W":
        cnt1 += 1
cnt2 = 0
for v in c[n // 2 :]:
    if v == "R":
        cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
N=int(input())
S= list(input())
W_count=S.count('W')
R_count=S.count('R')
if((W_count==0) or (R_count==0)):
    print(0)
else:
    print(R_count-S[:len(S)//2].count('R'))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
w_count = c[:len(c)//2].count("W")
r_count = c[len(c)//2:].count("R")

if (w_count == 0)|(r_count==0):
    print(0)
else:
    print(w_count) if w_count > r_count else print(r_count)

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
        ans=min(ans,n-t)
        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:
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] == 'W':
        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 collections

def solve():
    l = len(c)
    if l%2==0:
        left  = collections.Counter(c[0:l//2])
        right = collections.Counter(c[l//2:N])
    else:
        left  = collections.Counter(c[0:l//2+1])
        right = collections.Counter(c[l//2+1:N])


    if left["W"] > right["R"]:
        print(right["R"])
    else:
        print(left["W"])

if __name__ == "__main__":
    N = int(input())
    C = input()
    c = [str(l) for l in C]
#    print(c)
    solve()

Submission status: Wrong Answer

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

def solve():
    N = int(input())
    Cs = input()

    ans = 0
    left, right = 0, N-1
    while left <= right:
        if Cs[left] == "W" and Cs[right] == "R":
            ans += 1  # 石を入れ替える
            left, right = left+1, right-1
            continue
        elif Cs[left]=="W" and Cs[right]!="R":
            right -= 1
            if left == right: ans += 1  # 石の色を変える
            continue
        elif Cs[left]!="W" and Cs[right]=="R":
            left += 1
            continue
        else:
            left, right = left+1, right-1
            continue

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

j = N-1
count = 0
for i in range(N//2):
    if RW[i]=='W':
        while i<j:
            if RW[j]=='R':
                count += 1
                break
            j -= 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(input())
cr = al.count('R')
cr2 = cr//2
ans = 0
flag = False
flag2 = False
for a in al[::-1]:
    if a == 'R':
        cr2 -= 1
    if cr2 == 0:
        flag = True
        continue

    if flag and not flag2 and a == 'R':
        flag2 = True
        continue

    if flag2 and a == 'W':
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
stones = input()
count_R = stones.count('R')

if N == count_R:
    answer = 0
elif N - count_R >= count_R:
    answer = count_R
else:
    answer = count_R - 1

print(answer)

Submission status: Wrong Answer

Solution code:
#n,d=map(int,input().split())
#xy = [list(map(int,input().split())) for i in range(n)]
n=int(input())
c=list(input())
left=0
right=0
for i in range(0,n//2+1):
  if c[i]=="W":
    left+=1
  
for i in range(n//2+1,n):
  if c[i]=="R":
    right+=1
ans1=left+right-min(left,right)
aru=0
for i in range(n):
  if c[i]=="R":
    aru+=1
dab=n-aru

print(min(ans1,aru,dab))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.find('WR')
        wnum = a[rightmostW+2:].count('R')
        leftmostR = a.rfind('R')
        wnum2 = a[:leftmostR].count('W')
        r = min(wnum, wnum2)
        print(r)

if __name__ == '__main__':
    main()

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)

flag = 0
Rcount = 0
for i in range(n):
    if not flag:
        if s[i] == "W":
            flag = 1
    else:
        if s[i] =="R":
            Rcount += 1

flag = 0
Wcount = 0
for i in range(n-1,-1,-1):
    if not flag:
        if s[i] == "R":
            flag = 1
    else:
        if s[i] == "W":
            Wcount += 1
lst = [Rcount,Wcount]
lst.sort()
res = lst[0] + abs(lst[1]-lst[0])
ans = min(ans,res)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
  N = int(input())
  S = input()
  red = [S.count('R')]*(N+2)
  white = [0]*(N+2)
  ans = float('inf')
  for i in range(N):
    red[i+2] = red[i+1]
    white[i+1] = white[i]
    if S[i]=='W':
      white[i+1] += 1
    if S[i]=='R':
      red[i+2] -= 1
  for i in range(N+2):
    if red[i]==white[i]:
      return red[i]
  return ans
print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
stones = input()
count_R = stones.count('R')

if N == count_R:
    answer = 0
elif N - count_R > count_R:
    answer = count_R
else:
    answer = count_R - 1

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
_trigger = False
ans = 0
_count = c.count('R')
for i in range(n):
  if c[i] == 'W':
    _trigger = True
  else:
    if _trigger and i + 1 >= _count:
      ans += 1
print (ans)

Submission status: Wrong Answer

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

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

    elif l == N:
        if r >= 0:
            ans += 1
            r -= 1
        else:
            break
    else:
        if r < 0:
            ans += 1
            l += 1
        else:
            ans += 1
            l += 1
            r -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    c = S()
    dp1 = [0] * (n + 1)
    dp2 = [0] * (n + 1)
    W = c.count("W")
    R = c.count("R")
    for i in range(1, n + 1):
        dp1[i] = (c[i - 1] == "W") + dp1[i - 1]
        dp2[i] = (c[i - 1] == "R") + dp2[i - 1]
    ans = inf
    for i in range(n + 1):
        w = max(dp1[i], R - dp2[i])
        r = max(i - dp2[i], W - dp1[i])
        ans = min(ans, max(w , r))
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

l = 0
r = n-1
w_n = 0
r_n = 0

while l < r:
    if c_l[l] == 'W':
        w_n += 1
    if c_l[r] == 'R':
        r_n += 1
    l += 1
    r -= 1

if w_n == 0:
    print(0)
else:
    print(max(w_n, r_n))

Submission status: Wrong Answer

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

wr = 0
wflag = 0

wsum = 0
wtemp = 0
for c in C:
    if c == "W":
        wtemp += 1
        wflag = 1
    elif wflag:
        wr += 1
        wsum += wtemp
        wtemp = 0
        wflag = 0        

print(wsum-wr//2)

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(min(c[0:len(c)//2].count('W'), c[len(c)//2:].count('R')))
	else:
		print(min(c[0:len(c)//2+1].count('W'), c[len(c)//2:].count('R')))

Submission status: Wrong Answer

Solution code:
# for #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


# region fastio

BUFSIZE = 8192


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)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
class union_find:
    def __init__(self, n):
        self.n = n
        self.rank = [0]*n
        self.parent = [int(j) for j in range(n)]
    
    def union(self,i,j):
        i = self.find(i)
        j = self.find(j)
        if self.rank[i] == self.rank[j]:
            self.parent[i] = j
            self.rank[j] += 1

        elif self.rank[i] > self.rank[j]:
            self.parent[j] = i
        else:
            self.parent[i] = j

    def find(self, i):
        temp = i
        if self.parent[temp] != temp:
            self.parent[temp] = self.find(self.parent[temp])
        return self.parent[temp]
from math import log2, ceil
from collections import deque
def main():
# Enter your code here. Read input from STDIN. Print output to STDOUT
    # for t in range(int(input())):
        
        n = int(input())
        # n,k  =[int(j) for j in input().split()]
        s = input()
        ans=0
        a = 0
        b = 0
        tmp=1
        st = []
        ls = [s[0]]
        for i in range(1,n):
            if(s[i]!=s[i-1]):
                ls.append(s[i])
                st.append(tmp)
                tmp=1
            else:
                tmp+=1
        st.append(tmp)
        for i in range(len(ls)-1):
            if(ls[i]=='W' and ls[i+1]=='R'):
                ans+=min(st[i], st[i+1])
        print(ans)
        # print(m)
        


        # n,k,z  =[int(j) for j in input().split()]
        



if __name__ == "__main__":
    main()

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

L = Counter(c[:N//2])
R = Counter(c[N//2:])

if "W" not in c:
    print(0)
    exit()

ct = min(L["W"], R["R"])
if L["W"] < R["R"]:
    ct += R["R"] - L["W"]

print(ct)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
w = []
r = []
for i, ci in enumerate(c):
    if ci == 'W':
        w.append(i)
    if ci == 'R':
        r.append(i)
# print(w, r)
answer = 0
lenw = len(w)
lenr = len(r)
while answer < min(lenr, lenw) and w[answer] < r[-answer]:
    answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
cnt_w = c.count("W")
cnt_r = 0
for i in range(n-1, -1, -1):
    if c[i] == "R":
        cnt_r += 1
    else:
        break
c = list(c)
res = -1
ans = 0
for i in range(n):
    if c[i] == "W":
        cnt_w -= 1
        if cnt_r:
            cnt_r -= 1
            c[res] = "W"
            res -= 1
            ans +=1
            cnt_w += 1
        else:
            ans += 1
    if cnt_w == n-i-1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = input()
a = A.count('W')
b = A.count('R')
c = A[:n//2]
d = c.count('W')
print(min(a,b,d))