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:
#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(min(max(a,cnt), nya))
print(max(a,cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
stone = list(map(str,input()))
ind = [""]*2
ind[0] = list()
ind[1] = list()
R = 0
W = 0
for i in range(N):
    if(stone[i]=="W"):
        ind[0].append(i)
        W += 1
    else:
        ind[1].append(i)
        R += 1
newind =list(reversed(ind[1]))
ans = 0
newR = 0
for i in range(R):
    if(i != ind[1][i]):
        break
    newR+= 1
# print(W,R,newR)
# print(ind[1],newind)
if(W != R):
    if(newR != R):
        print(min(W,R-newR))
    else:
        print(min(W,R))
else:
    for i in range(N//2):
        if(ind[0][i]>newind[i]):
            break
        ans+=1
        # print(ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
"""AtCoder Beginner Contest 174: D - Alter Altar
https://atcoder.jp/contests/abc174/tasks/abc174_d
"""


def exchange(Cs):
    if Cs.count("WR") == 0:
        return 0

    ans = 0
    while(True):
        rr = Cs.rfind("RR")
        if rr == -1:
            break
        wr = Cs.find("W")
        if rr <= wr:
            break
        s = list(Cs)
        s[rr] = 'W'
        s[wr] = 'R'
        Cs = "".join(s)
        ans += 1
    while(True):
        count = Cs.count("WR")
        if count == 0:
            break
        ans += count
        Cs = Cs.replace("WR", "WW")
        break

    return ans


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

    # N = 4
    # Cs = "WWRR"

    # N = 2
    # Cs = "RR"

    # N = 8
    # Cs = "WRWWRWRR"

    print(exchange(Cs))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

c = str(input())

head = 0
tail = -1
count = 0

oikosi_flag = True
while head < N:
    if c[head] == "W":
        while c[tail] == "W":
            tail -= 1
            if head >= N+tail:
                print(count)
                exit()
        tail -= 1
        count += 1
    head += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
ans = 0
c1 = len(c)//2 if len(c)%2 == 0 else len(c)//2 +1
cnt_w = 0
cnt_r = 0
for i in range(c1):
  if c[i]=='W':
    cnt_w += 1
for i in range(c1,len(c)):
  if c[i]=='R':
    cnt_r += 1

ans = cnt_w if cnt_w <= cnt_r else cnt_r

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
white=0
red=0
hu=0
W=list(str(input()))
if "W" not in W or "R" not in W:
  print("0")
  exit()
for i in range(N//2):
  if W[i]=="W":
    white+=1
for i in range(N//2):
  if W[N-1-i]=="R":
    red+=1
for k in range(white):
  if W[N-k-1]=="W":
    hu+=1
if hu==white:
  print(0)
  exit()
elif white>=red:
  print(red)
  exit()
else:
  Z=white*2-red
  if (N/2)%1!=0:
    if W[N//2+1]=="W" and W[N//2+2]=="R":
      Z+=1
  print(Z)

Submission status: Wrong Answer

Solution code:
import math

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

    target = 'WR'
    index = -1
    cnt=0
    
    test=N//2

    if(N%2==0):
        Centor=""
        C1=C[:N//2]
        C2=C[N//2:]
    else:
        Centor=C[N//2:N//2+1]
        C1=C[:N//2]
        C2=C[N//2+1:]


    Rf=C1.count('R')
    Rr=C2.count('R')
    Wf=C1.count('W')
    Wr=C2.count('W')


    cnt+=min(Wf,Rr)   

    if(C.count('R')==0 or C.count('W')==0):
        cnt=0

    print(cnt)
 
resolve()

Submission status: Wrong Answer

Solution code:
from re import match

n  = int(input())
ci = input()

if len(match('R*W*', ci).group(0)) == n:
    print(0)
    exit()

fst = ci.find('R')
rng = len(match('^R+', ci[fst:]).group(0))
Rs  = ci.count('R')
Ws  = n - Rs

'''
first <= Ws
'''

Rs2 = Rs - fst
Ws2 = Ws - fst

if Rs2 == 0:
    print(fst)

elif Ws2 == 0:
    print(Rs)

else:
    print(fst + Rs2 - rng)

Submission status: Wrong Answer

Solution code:
import collections

def solve():
    wr = collections.Counter(c)
    
    w = wr["W"]
    r = wr["R"]
    R = r
    left  = collections.Counter(c[0:r])
    right = collections.Counter(c[r:N])
#    print(left)
#    print(right)
#    print(right["R"])
    cnt = 0
    tmp = 0
    is_change = False
    for i in range(N):
        if not is_change and c[i] == "W":
            cnt += 1
            tmp += 1
            is_change = True
        elif is_change and c[i] == "W":
            cnt += 1
            r += 1
            tmp += 1
            is_change = False
        elif c[i] == "R":
            tmp += 1
        if tmp == r:
            break
#        print(i,cnt,tmp)
    print(cnt)

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

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left
from collections import deque
#======================================================#
def main():
    N = II()
    cc = list(IS())
    cc_rev = cc[::-1]
    cnt = 0
    indexs = []
    for i, c in enumerate(cc):
        if c == 'W':
            indexs.append(i)
    indexs = deque(indexs)
    if cc.count('W') == 0:
        print(0)
        return 0
    for i, c in enumerate(cc_rev):
        if c == 'R':
            if indexs:
                idx = indexs.popleft()
                if i >= idx:
                    cc[idx] = 'R'
                    cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


rcnt = c.count('R')
wcnt = c.count('W')
if n-rcnt == 1 and c[-1] =='W':
    print(0)
    exit()
if n-wcnt == 1 and c[0] == 'R':
    print(0)
    exit()

if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    if rcnt >= wcnt:
        cnt = 0
        left = n//2
        for i in range(left):
            if c[i] == 'R':
                cnt += 1
        
        if cnt == left:
            print(wcnt)
        else:
            print(rcnt - cnt)
    else:
        print(rcnt)

Submission status: Wrong Answer

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

c = c.lstrip('R')
c = c.rstrip('W')
n = len(c)

rn = c.count('R')

if n == 0:
  print(0)
else:
  print(min(c[:rn].count('W'),c[n-rn:].count('R')))

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())
    c = list(input())
    print(c[0:(n//2)].count('W'))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
WWRR"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
RR"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
WRWWRWRR"""
        output = """3"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

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

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':
      rw[i]='R'
      rw[j]='W'
      count+=1
  i+=1
  j-=1

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

Submission status: Wrong Answer

Solution code:
input()
num = input()

print(num.find('WR'))

Submission status: Wrong Answer

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 ==0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 0
    while True:
        count += 1
        n = n % K
        if n == 0:
            print(count)
            exit()
        else:
            n_before = 10 * n_before % K
            n = n + n_before
print(count)

Submission status: Wrong Answer

Solution code:
input()
l =list(input())
cw = l.count('W')
cr = l.count('R')

if cr < cw:
  ans = l[:cr].count('W')
else:
  ans = l[cw:].count('R')
print(ans)

Submission status: Wrong Answer

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

red = [i for i, x in enumerate(c) if x == 'R']
white = [i for i, x in enumerate(c) if x == 'W']

if len(white) == 0:
    print(0)
elif len(red) == 0:
    print(len(white) - 1)
else:
    red.sort(reverse=True)
    count = 0
    while(1):
        if red[0] > white[0]:
            red.pop(0)
            red.append(white[0])
            white.pop(0)
            count += 1
            break
        
    print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import copy
N = int(input())
C = input()
M = ''
Ret = []
w_c = 0
r_c = 0
S = ''
cop = 0
ans = 0
for i in range(N):
    if C[i] == 'W':
        if r_c != 0:
            if 'W' in M:
                M += S
#                Ret.append([cop, r_c])
                ans += min(cop, r_c)
            else: M = copy.copy(S)
            S = ''
            r_c = 0
        w_c += 1
        S += 'W'
    else:
        if w_c != 0:
            M = copy.copy(S)
            S = ''
            cop = copy.copy(w_c)
            w_c = 0
        r_c += 1
        S += 'R'
if 'W' in M:
#    Ret.append([cop, r_c])
    ans += min(cop, r_c)
'''
ret = 0
for r in Ret:
    ret += min(r[0], r[1])
'''

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    C = list(input())

    W = deque()
    R = deque()
    flg = False
    for i in range(n):
        if C[i] == "W":
            W.append(i)
            flg = True
        if flg and C[i] == "R":
            R.appendleft(i)

    res = 0
    i = 0
    cnt = 0
    while R:
        if C[i] == "W":
            cnt += 1
        if cnt:
            r = R.popleft()
            w = W.popleft()
            C[r], C[w] = C[w], C[r]
            cnt -= 1
            res += 1
        else:
            R.pop()
        i += 1
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
str_list = list(input())
flag = 0

if (str_list[0] == 'W' and str_list[1] == 'R') and str_list[n-1] == 'R':
    str_list[0] = 'R'
    str_list[n-1] = 'W'
    flag += 1
elif (str_list[0] == 'W' and str_list[1] == 'W') and str_list[n-1] == 'R':
    str_list[0] = 'R'
    str_list[n-1] = 'W'
    flag += 1

for i in range(n-1):
    if str_list[i] == 'W' and str_list[i+1] == 'R':
        str_list[i+1] = 'W'
        flag += 1

print(flag)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
n=0
while S.find("W")<S.rfind("R"):
  S = S[S.find("W")+1:S.rfind("R")]
  n+=1
print(n)

Submission status: Wrong Answer

Solution code:
from math import *

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

if N==C.count("R") or N==C.count("W"):
    print(0)
    exit()

if N%2==0:
    judge=N//2
    cnt_left_R=C[0:judge].count("R")
    cnt_left_W=C[0:judge].count("W")
    
    cnt_right_W=C[judge:].count("W")
    cnt_right_R=C[judge:].count("R")
else:
    judge=N//2
    cnt_left_R=C[0:judge+1].count("R")
    cnt_left_W=C[0:judge+1].count("W")
    
    cnt_right_W=C[judge:].count("W")
    cnt_right_R=C[judge:].count("R")



#print(cnt_left_R)
#print(cnt_left_W)

#print(cnt_right_R)
#print(cnt_right_W)

ans=min(cnt_left_W,C.count("W"))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
C=list(input())
nR=-1
nW=0
u=0
for i in range(N):
    if C[i]=='W':
        nW=nW+1
    else:
        u=i
        break
if u!=0:
    for i in range(N-u):
        if C[i+u]=='R':
            nR=nR+1
if nW<=nR:
    print(nR)
if nW>nR:
    print(nR+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
if 'W' not in c or 'R' not in c:
    print(0)
else:
    for i in range(n-1, -1, -1):
        if c[i] == 'W':
            l = i
            break
    for i in range(n-1, -1, -1):
        if c[i] == 'R':
            r = i
            break
    if l > r:
        print(0)
    else:
        l = 0
        r = n-1
        cnt = 0
        while l < r:
            for i in range(r+1):
                if c[i] == 'W':
                    l = i
                    break
            for i in range(r, l-1, -1):
                if c[i] == 'R':
                    r = i
                    break
            c[l], c[r] = c[r], c[l]
            cnt += 1
        print(cnt-1)
"""
p = -1
q = -1
cnt = 0

for i in range(n-1, -1, -1):
    if c[i] == 'R' and q == -1:
        p = i
        break
for i in range(p-1, -1, -1):
    if c[i] == 'R' and p != -1 and q == -1:
        q = i
    elif c[i] == 'W':
        break
if p == -1:
    print(0)
elif q == -1:
    for i in range(p):
        if c[i] == 'W':
            cnt += 1
    print(cnt)
else:
    for i in range(n):
        if c[i] == 'W' and i < p:
            cnt += 1
    print(cnt-(q-p+1))
"""

Submission status: Wrong Answer

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

c = [c[i] for i in range(N)]

cR = c.count('R')
cW = c.count('W')

listR = [i for i, x in enumerate(c) if x == 'R']
listW = [i for i, x in enumerate(c) if x == 'W']

if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[:cW]]):
    print(0)
    exit()

cnt = 0

for i in range(N):
        c[listR[-(i+1)]] = 'W'
        c[listW[i]] = 'R'
        cnt += 1
        if all([i == 'R' for i in c[:cR]]):
            print(cnt)
            break

Submission status: Wrong Answer

Solution code:
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    a, b = c[:len(c) // 2], c[len(c) // 2:]
    while len(a) and a.count('W') == 0:
        a, b = b[:len(b) // 2], b[len(b) // 2:]
    # print(f'{c=}')
    # print(f'{a=}')
    # print(f'{b=}')

    wc = a.count('W')
    rc = b.count('R')
    # print(f'{wc=} {rc=}')

    return min(wc, rc)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [c for c in s]
ans = 0
t1 = a.count('W')
t2 = a.count('R')
ans += (t1*t2)//n
if(ans != 0):
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = input()
count = 0
flg = False
r=999999
w=999999
for i in range(n):
        if c[i]=='W':
            w=i
            break
for i in range(n):
    if c[n-i-1]=='R':
        r=n-i-1
        break
if r<w:
    flg=True
    
while((r>=w and count<=n/2)):
    count += 1
    w_=c.find('W')
    c=c[:w_-1] + 'R' + c[w_:]
    r_=c.rfind('R')
    c=c[:r_-1] + 'W' + c[r_:]
    w=c.find('W')
    r=c.rfind('R')
        
if flg==True:
    print(0)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(str, stdin.readline().split()))


def main():
    N = int(input())
    ls = str(input())
    rls = []
    wls = []
    for i,item in enumerate(ls):
        if item == 'W':
            wls.append(i)
        if len(wls)==0:
            continue
        if item == 'R':
            rls.append(i)
    count = 0
    ww = len(wls)
    rr = len(rls)
    wls = deque(wls)
    rls = deque(rls)
    while True:
        if ww== 0:
            print(0)
            return
        if ww > rr:
            print(rr+count)
            return
        count += 1
        r = rls.pop()
        w = wls.popleft()
        while True:
            if w+1 in rls:
                rls.popleft()
                w += 1
            else:
                break
        ww = ww + 1
        rr = len(rls)



main()

Submission status: Wrong Answer

Solution code:
N = int(input())
c= list(input()) 
if c.count('R') == N:
	print(0)
div=0
if N %2 == 1:
	div =1
clist_L = c[:int(N/2)]
clist_R = c[int(N/2)+div:]
Lcnt = clist_L.count('W')
Rcnt = clist_R.count('R')
if Lcnt - Rcnt <=0:
	print(Rcnt)
else:
	print(Lcnt)

Submission status: Wrong Answer

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

left_white = 0
Rcount = c.count("R")
for i in range(0,len(c)):
    if c[i] == "R":
        left_white = i
        break
#print(i,''.join(c[i:]))
if left_white >= Rcount:
    print(c.count("R"))
elif i == 0:
    print(0)
else:
    print(c[i+1:].count("R"))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
t=0
i=0
j=n-1
while c[i]=='R':
    i += 1
    if i>n-1:
        print(0)
        exit()
while c[j]=='W':
    j -= 1
    if j<0:
        print(0)
        exit()
if i<j:
    i += 1
    j -= 1
    t += 1
while i<j:
    while c[i]=='R':
        i += 1
        if i>n-1:
            print(t)
            exit()
    while c[j]=='W':
        j -= 1
        if j<0:
            print(t)
            exit()
    i += 1
    j -= 1
    t += 1
print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
cnt = 0
for i in range(n):
    if c[i] == 'W' and i > c.find('R') and c.find('R') != -1:
        r = c.find('R')
        l = list(c)
        l[i] = 'R'
        l[r] = 'W'
        cnt += 1
        c = ''.join(l)

print(cnt)

Submission status: Wrong Answer

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

c = c.lstrip('R')
c = c.rstrip('W')
n = len(c)

rn = c.count('R')

if n == 0:
  print(0)
elif rn < n/2:
  print(c[:rn].count('W'))
else:
  print(c[n-rn:].count('R'))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(str,input().split()))
c=list("".join(l))
w=c.count('W')
cc=c[-w:]
r=cc.count('R')
print(r)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
c = input()
count = 0
flg = False
r=999999
w=999999
for i in range(n):
        if c[i]=='W':
            w=i
            break
for i in range(n):
    if c[n-i-1]=='R':
        r=n-i-1
        break
if r<w:
    flg=True
    
while((r>=w and count<=n/2)):
    count += 1
    w_=c.find('W')
    c=c[:w_] + 'R' + c[w_+1:]
    r_=c.rfind('R')
    c=c[:r_] + 'W' + c[r_+1:]
    w=c.find('W')
    r=c.rfind('R')
        
if flg==True:
    print(0)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
w=[i for i, x in enumerate(c) if x == 'W']
r=[i for i, x in enumerate(c) if x == 'R']
wc=len(w)
rc=len(r)
if n%2==0:
    wt=list(range(wc,wc+rc))
    tand = set(w) & set(wt)
    print(wc-len(tand))
else:
    if wc>rc:
        wt=list(range(wc-1,wc+rc))
        tand = set(w) & set(wt)
        print(wc-len(tand))
    else:
        wt=list(range(wc+1,wc+rc))
        tand = set(w) & set(wt)
        print(wc-len(tand))

Submission status: Wrong Answer

Solution code:
import collections

def solve():
    wr = collections.Counter(c)
    
    w = wr["W"]
    r = wr["R"]
    left  = collections.Counter(c[0:r])
    right = collections.Counter(c[r:N])
#    print(left)
#    print(right)
#    print(right["R"])
    cnt = 0
    tmp = 0
    is_change = False
    for i in range(N):
        if not is_change and c[i] == "W":
            cnt += 1
            is_change = True
        elif is_change and c[i] == "W":
            cnt += 1
            r += 1
            tmp += 1
            is_change = False
        elif c[i] == "R":
            tmp += 1
        if i == r-1:
            break
#        print(i,cnt,tmp)
    print(cnt)

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

Submission status: Wrong Answer

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

for i in range(100):
    if not "W" in c or not "R" in c :
        print(i)
        exit()
    cr = c[:]
    cr.reverse()
    w =  c.index("W")
    r = cr.index("R")
    
    c[-(r+1)] = "W"
    c.pop(w)
    if w > len(c)-r:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
s1 = input()
s2 = s1[::-1]
i1 = 0
i2 = 0
ans = 0
while i1 < n:
  if s1[i1]=='W':
    while i2 < n:
      if s2[i2]=='R':
        ans += 1
        i2 += 1
        break
      elif i1+i2 >= n-2:
        break
      else:
        i2 += 1
  i1 += 1
  if i1+i2 >= n-2:
    break
    
print(ans)

Submission status: Wrong Answer

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


rcnt = c.count('R')
wcnt = c.count('W')
if n-rcnt == 1 and c[-1] =='W':
    print(0)
    exit()
if n-wcnt == 1 and c[0] == 'R':
    print(0)
    exit()

ans = 0
if set(c) == {'R'} or set(c) == {'W'}:
    print(0)
else:
    if rcnt >= wcnt:
        cnt = 0
        left = n//2
        for i in range(left):
            if c[i] == 'R':
                cnt += 1
        
        if cnt == left:
            print(wcnt)
        else:
            print(rcnt - cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
print(max(s[:n//2].count('W'),s[n//2:].count('W')))

Submission status: Wrong Answer

Solution code:
""" D
    https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, S):
    S = list(S.rstrip())

    if len([c for c in S if "W" == c]) == 0:
        return 0

    return len([c for c in S[(len(S)+1)//2:] if "R" == c])

if __name__ == "__main__":
    _N = readInteger()
    _S = readString()

    print(main(_N, _S))

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input().split())
str_list = []
for s in S:
  str_list.append(list(s))
count = 0
for i in range(1, n+1):
  if str_list[0][-i] == 'R':
    count += 1
  else:
    break
if n % 2 == 0:
  b = n // 2
else:
  b = (n + 1) // 2
c = str_list[0][:b].count('W')
print(max(count, c))

Submission status: Wrong Answer

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

c = c.lstrip('R')
c = c.rstrip('W')
n = len(c)

rn = c.count('R')

if n == 0:
  print(0)
elif rn < n/2:
  print(c[:rn].count('W'))
elif rn >= n/2:
  print(c[n-rn:].count('R'))

Submission status: Wrong Answer

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

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':
      rw[i]='R'
      rw[j]='W'
      count+=1
  i+=1
  j-=1

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

Submission status: Wrong Answer

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

if 'R' not in c or 'W' not in c:
    print(0)
    exit()

left, right = 0, len(c) - 1
cnt = 0

while left < right:

    if c[left+1] == 'R' and c[left] == 'W':
        c[left] = 'R'
        left += 1

    elif  c[right-1] == 'W' and c[right] == 'R':
        c[right] = 'W'
        right -= 1

    elif c[left] is 'W' and c[right] is 'R':
        c[left] = 'R'
        c[right] = 'W'

    elif c[left] is 'W':
        right -= 1
        continue
    
    elif c[right] is 'R':
        left += 1
        continue

    else:
        left += 1
        right -= 1
        continue

    left += 1
    right -= 1

    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
a = [c for c in s]
ans = 0
t1 = a.count('W')
t2 = a.count('R')
ans += (t1*t2)//n + 1
print(ans)

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)
ans = B[N - a - 1]
print(ans)

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())
a = list(input())
if N%2==0:
  x = a[0:int(N/2)]
  y = a[int(N/2):N]
else:
  x = a[0:int(N/2)]
  y = a[int(N/2)+1:N]
  if a[int(N/2)]=='R':
    y.append('R')
  elif a[int(N/2)]=='W':
    x.append('W')
count_ri = x.count('W')
count_le = y.count('R')
if a.count('W') ==0 or a.count('R')==0:
  print(0)
elif x.count('W')==0 and y.count('R')==0:
  print(0)
elif count_ri==count_le:
  print(count_ri)
elif count_ri>count_le:
  print(count_le)
elif count_ri<count_le:
  print(count_ri)

Submission status: Wrong Answer

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

rtow = c.count('R')
wtor = 0

anses = []
for i in range(n):
  if c[i] == 'W':
    wtor += 1
  else:
    rtow -= 1
  anses.append(max(rtow, wtor))

print(min(anses))

Submission status: Wrong Answer

Solution code:
import copy

n=int(input())

c=list(input())

num=0

c1=copy.copy(c)
for i in range(len(c)-1):
    if(c1[i]=="W" and c1[i+1]=="R"):
        c1[i+1]="W"
        num+=1

c2=c
num1=0
for i in range(len(c2)):
    if(c2[i]=="R"):
        break
    else:
        num1+=1

num2=0
c2=c2[::-1]
#print(c2)
for i in range(len(c2)):
    if(c2[i]=="W"):
        break
    else:
        num2+=1

#print(num,num1,num2)
a=num-abs(num1-num2)

if(a>0):
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = str(input())

w_list = [0 for i in range(n)]
r_list = [0 for i in range(n)]

w = 0
r = 0
f = True
for i in range(n):
    if a[i] == "W":
        w += 1
        if w == 1:
            f = True
    else:
        f = False

    w_list[i] = w

for i in range(n-1,-1,-1):
    if a[i] == "R":
        r += 1
    r_list[i] = r

if w==0 or r == 0 or f == True:
    print(0)
    exit()

ans = n
for i in range(n):
    ans = min(ans,max(w_list[i],r_list[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
cl = list(c)
wi = 0
wnum=0
ri = n-1
rnum=0
br=0
bw=0
res1 = n
for i in range(n):
    while(cl[wi] == "R" and bw==0):
        wi+=1
        if(wi >= n-1):
            bw=1
            break
    if(cl[wi] == "W"):
        wnum+=1
    while(cl[ri] == "W" and br==0):
        ri-=1
        if(ri <= 0):
            br=1
            break
    if(cl[ri] == "R"):
        rnum+=1
    if(ri < wi):
        res1 = i
    wi+=1
    if(wi >= n-1):
        wi=0
        bw=1
    ri-=1
    if(ri <= 0):
        ri=n-1
        br=1
    #print(wi, ri)

    if(br*bw==1):
        break
print(min(res1, rnum, wnum))

Submission status: Wrong Answer

Solution code:
N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
print(Wcount)

Submission status: Wrong Answer

Solution code:
N=int(input())
white=0
red=0
W=list(str(input()))
if "W" not in W or "R" not in W:
  print("0")
  exit()
for i in range(N//2):
  if W[i]=="W":
    white+=1
for i in range(N//2):
  if W[N-1-i]=="R":
    red+=1
if white>=red:
  print(red)
else:
  Z=white*2-red
  if (N/2)%1!=0:
    if W[N//2+1]=="W" and W[N//2+2]=="R":
      Z+=1
  print(Z)

Submission status: Wrong Answer

Solution code:
n=int(input())
li = list(input())
i = 0
k = 1
counter = 0
done = 0
while True:
    # print(li)
    # print(counter)
    if done == 1:
        # print("done")
        break
    if i+k == n:
        # print("owari")
        break
    if i + 1  > n/2:
        # print("ridatsu")
        break
    if li[i] == "W":
        # print("yes")
        # print("i=", i, li[i])
        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
                if li[-k] == "R":
                    li[-k] = "W"
                    counter += 1
                break
    i += 1
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
if N%2 == 0:
    S1 = S[0:N//2]
    S2 = S[N//2:N]
    W = S1.count("W")
    R = S2.count("R")
    if R == 0 or W == 0:
        print(0)
    else:
        if R < W:
            print(R)
        elif R == W:
            print(R)
        else:
            #(W < R)
            print(R+len(S2)-R)
else:
    S1 = S[0:N//2]
    S2 = S[N//2+1:N]
    print(S1,S2)
    W = S1.count("W")
    R = S2.count("R")
    if R == 0 or W == 0:
        print(0)
    else:
        if R == W:
            print(W)
        else:
            if W < R:
                print(W+(R-W))
            elif R > W:
                S = len(S2)-R
                print(R+S)