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()
cnt = []
x = ""
for i in range(n):
    if c[i]=="W":
        if x != "" and x != 0: cnt.append(x) 
        x=0
    else:
        if x != "": x += 1
if x!="": cnt.append(x)
if cnt==[]:
    print(0)
    exit()
if len(cnt)==1:
    print(cnt[0])
    exit()

print(len(cnt)-1 + cnt[-1]-1)

Submission status: Wrong Answer

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

if len(set(s)) == 1:
    print(0)
    exit()

left_r = s[:k//2].count('R')
left_w = (k//2) - left_r

right_r = s[k//2:].count('R')
right_w = (k//2) + 1 - right_r

res = min(left_w, right_r)

if right_r and not left_w:
    print(min(right_w, right_r))
else:
    print(res)

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 len(white) == 0:
            break
        elif red[0] < white[0]:
            break
        else:
            red.pop(0)
            red.append(white[0])
            white.pop(0)
            count += 1
            
    print(count)

Submission status: Wrong Answer

Solution code:

n = int(input())
c = input()

# 1文字ずつのListに変換
list_c = ','.join(map(lambda x: '"{}"'.format(x), list(c)))

print(list_c)

all_change = 0

if list_c.count('W') < list_c.count('R') :
    all_change = list_c.count('W')
else :
    all_change = list_c.count('R')

print(all_change)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
count = 0
if (C1.count('W') == 0 and C1.count('R') == 0 and
       C2.count('W') == 0 and C2.count('R') == 0):
    count = 0
elif (C1.count('W') == C2.count('R')):   #左右対象のとき
    count = C1.count('W')
elif(C1.count('R') == C2.count('W')):
    count = C.count('W')
else:
    if(C.count('W') > C.count('R')):
        count = C.count('R')
    else:
        count = C.count('W')
print(count)

Submission status: Wrong Answer

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

count=0
w_count=0
r_count=0
w_count2=0
r_count2=0
flag=False

for i in range(n//2):
	if c[i]=="W":
		w_count+=1
	else:
		r_count+=1
for i in range(n//2,n):
	if c[i]=="W":
		w_count2+=1
	else:
		r_count2+=1
if r_count2>=w_count:
	print(w_count)
else:
	print(r_count+r_count2)

Submission status: Wrong Answer

Solution code:
N = input()
li = input()
#print(li)
red = li.count("R")
white = li.count("W")

if red >= white:
  target = li[-1*white:]
  ans = white - target.count("W")
  print(ans)
  
else:
  print(red)

Submission status: Wrong Answer

Solution code:
import sys

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

count = 0

i = 0
j = len(C) - 1

if not 'R' in C or not 'W' in C:
    print(0)
    sys.exit()

while i <= j:
    while C[i] == 'R':
        i += 1
    while C[j] == 'W':
        j -= 1
    C[i], C[j] = C[j], C[i]
    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] == 'W':
                    pass
                else:
                    cnt = max(cnt-1,0)
            else:
                cnt = max(cnt-1,0)
r = C.count('R')
w = n-r
nya = 0
for i in range(r,n):
    if C[i] == 'R':
        nya += 1
pya = 0
for i in range(r):
    if C[i] == 'W':
        pya += 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, pya))

Submission status: Wrong Answer

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

if len(set(c))==1:
    print(0)
    exit()

ans=0
tmp=-1
for i in range(n//2):
    # print(i,tmp)

    while (c[i]=="W" and not c[tmp]=="R") and tmp<n:
        tmp-=1
    
    if c[tmp]=="R":
        ans+=1
    else:
        break

    if c[i]=="R":
        if len(set(c[i+1::]))==1:
            break
        ans+=c[i+1:tmp].count("R")
        print(c[i+1:tmp])
        break
    tmp-=1

print(ans)

Submission status: Wrong Answer

Solution code:
s = int(input())
n = input()
str_list = list(n)
w_cnt = str_list.count('W')
r_cnt = str_list.count('R')
if w_cnt == 0 or r_cnt == 0:
    print(0)
else:
    w_result = str_list[w_cnt:]
    r_result = str_list[:r_cnt]
    r = w_result.count('R')
    w = r_result.count('W')
    if w <= r:
        print(r)
    else:
        print(w)

Submission status: Wrong Answer

Solution code:
a = int(input())
s = input()
ns = a//2
if ns*2 != a:
    ns+=1

bef = s[:ns]
aft = s[ns:]
tr = 0
tw = 0
for i in range(ns):
    if s[i] == 'W':
        tw += 1 
for j in range(ns,a):
    if s[j] == 'R':
        tr += 1 
if tw == tr:
    ans = tw
elif tw>tr:
    ans = tr + (tw-tr)
else:
    ans = tw
'''print(bef,aft)
print(tw,tr)'''
print(ans)

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) + amari):
  if intdata[i] != sortdata[i]:
    ans += 1

if len(intdata) % 2 == 1:
  print(ans-1)
else:
  print(ans)

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.rfind('WR')
        wnum = a[rightmostW:].count('R')
        print(wnum + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
C_=list(input())
C=[]
for c in C_:
	if c=="W":C.append(0)
	else:C.append(1)

C=np.array(C)
if 1 in C:
	temp_array=np.where(C==1)[0]
	cnt=0
	#print(temp_array)
	for t in temp_array:
		#print(t,cnt)
		if t!=cnt:
			temp=t
			break
		elif t==temp_array[-1]:
			temp=t
			break
		else:
			cnt+=1
			continue
		
	#print(temp,cnt)
	C_w=C[0:temp]
	C_r=C[temp+1:]
	#print(C_w,C_r)
	W_cnt=np.count_nonzero(C_w==0)
	R_cnt=np.count_nonzero(C_r==1)
	if W_cnt==0 and R_cnt==0:
		print(0)
	elif W_cnt==0 and R_cnt>0:
		print(R_cnt)
	elif R_cnt==0 and W_cnt>0:
		print(1)
	elif W_cnt>0 and R_cnt>0:
		print(R_cnt)
		
else:print(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')
w = n-r
nya = 0
for i in range(r,n):
    if C[i] == 'R':
        nya += 1
pya = 0
for i in range(r):
    if C[i] == 'W':
        pya += 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, pya))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


flag = 0
for i in range(n-1): 
    if(s[i] == "R" and s[i+1] == "W"):
        w_left = i
        r_right = i+1
        flag = 1
        break


#print(w_left)
#print(r_right)
if(flag == 1):
    #print(r_right)
    #print(w_left)
    r_len = len([i for i in s[r_right:] if i == "R"])
    w_len = len([i for i in s[:w_left] if i == "W"])
    #print(w_len,r_len)
    if(w_len <= r_len):
        print(w_len)
    else:
        print(r_len+1)
else:
    for i in range(n-1):
        if(s[i] == "W" and s[i+1] == "R"):
            flag = 2
            pnt = i
            ans = min(pnt+1,n-pnt-1)
            print(ans)
            break

if(flag == 0):
    print(0)

Submission status: Wrong Answer

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

if "W" not in C or "R" not in C:
    print(0)
    import sys; sys.exit(0)

cnt = 0

i = 0
j = len(C) - 1
while i < j:
    while C[i] != "W":
        i += 1
    while C[j] != "R":
        j -= 1
    cnt += 1
    C[i] = "R"
    C[j] = "W"
    i += 1
    j -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import collections as c
n = int(input())
s = list(input())
cnt = 0

while c.Counter(s[:cnt+1])["W"]<c.Counter(s[cnt:])["R"]:
    cnt += 1
    
print(cnt)

Submission status: Wrong Answer

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

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


i = 0
j = N - 1

count = 0

while (True):
    while (c[i] != "W"):
        i = i + 1

    while (c[j] != "R"):
        j = j - 1
    count += 1
    i = i + 1
    j = j - 1
    if (i > j or i == j or i >= N or j < 0):
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
c_str = input()
c_list = list(c_str)

cnt = 0
flag = 1
w_pos = 0
r_pos = 0
range_start = 0
range_end = n

while flag:
    for i in range(range_start, range_end):
        if c_list[i] == "W":
            w_pos = i
            range_start = i
            break
        if i == n-1:
            w_pos = n-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
    if w_pos < r_pos:
        c_list[w_pos] = "R"
        c_list[r_pos] = "W"
        cnt += 1
    else:
      flag = 0

print(cnt)

Submission status: Wrong Answer

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

stack = []
w_counting = False
count = 0
output = 0
for c in input_str:
    if c == 'W':
        if not w_counting:
            count = 0
        count += 1
        w_counting = True
    if c == 'R':
        if count > 0:
            count -= 1
            output += 1
        w_counting = False
print(output)

Submission status: Wrong Answer

Solution code:
N = int(input())
stones = [l for l in input()]

cnt = 0
memo = N-1
for i in range(N//2):
    for j in range(memo, i , -1):
        if stones[i] == 'R':
            break
        else :
            if stones[j] == 'R':
                stones[i] = 'R'
                stones[j] = 'W'
                cnt += 1
                break
    
    memo = j
    if memo == i:
        break
            
print(cnt)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=int(a/2)
d=0
e=a-1
i=0
while True:
    if b[i]=='W':
        for j in range(i,e+1)[::-1]:
            if b[j]=='R':
                d=d+1
                e=j-1
                break
    i=i+1
    if i+1>=e: break
print(d)

Submission status: Wrong Answer

Solution code:
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    if n%2==0:
        tmpw=C.count("W")
        #print(tmpw,C)
        C=C[tmpw:]
        #print(tmpw,C)
        print(C.count("R"))
    else:
        tmpw=C.count("W")
        #print(tmpw,C)
        C=C[tmpw-1:]
        #print(tmpw,C)
        print(C.count("R"))

Submission status: Wrong Answer

Solution code:
N = int(input())
stones = list(input())
W_left = 0
W_right = 0
R = 0
count = 0

for i in range(N // 2):
    if stones[i] == 'W':
        W_left += 1

for j in reversed(range(N)):
    if stones[j] == 'R':
        if W_left > 0:
            count += 1
            W_left -= 1
        else:
            R += 1
    elif stones[j] == 'W' and R > 0:
        W_right += 1

if W_right > count:
    print(count + R)
else:
    print(count)

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)
    if w==len(c):
        print(1)
    else:
        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 = input()

a = N // 2

b = 0
for i in range(N-1):
    if C[i] == 'W':
        if C[i+1] == 'R':
            b += 1

if b == 0:
    ans = 0
else:
    if N & 2 == 0:
        right_W = C[:a].count ('W')
    else:
        right_W = C[:a+1].count('W')
    left_R = C[a:].count ('R')

    ans = min(right_W, left_R)

print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
# C = list(map(lambda x: x == 'W', list(input())))
C = list(input())

countR = 0
countI = 0
for n, c in enumerate(C):
    if countI == 0 and c == 'W' :
        countI = n
    if c == 'W' :
        countR += 1

RZ = len(C) - countI +1
RZW = RZ - countR
if countR == 0 :
    RZW = 0
print(RZW)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=str(input())
cnt = 0
flg = False
flg2 = False
for i in range(N):
    if flg == False and c[i] == "W":
        cnt += 1
    elif flg == False and c[i] == "R":
        flg = True
for i in range(N-1):
    if c[i]=="R" and c[i+1] == "W":
        x = i
        break
if cnt == 0:
    print(0)
else:
    y = c[i+1:N].count("R")
    #print(y,cnt,i)
    if cnt >= y:
        print(cnt)
    else:
        print(y)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest


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

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

    def test_入力例_4(self):
        input = """7
WRWRRRR"""
        output = """2"""
        self.assertIO(input, output)


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

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')
w = n-r
nya = 0
for i in range(r,n):
    if C[i] == 'R':
        nya += 1
pya = 0
for i in range(r):
    if C[i] == 'W':
        pya += 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, pya))

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)
    if w==len(c):
        print(0)
    else:
        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())
s_w = input()
r_cnt = s_cnt = 0

for s in s_w:
  if s == 'R':
    r_cnt += 1
    
for s in s_w[:r_cnt+1]:
  if s != 'R':
    s_cnt += 1
print(min(s_cnt, r_cnt, n-r_cnt))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
con=0
ans=n
for i in range(n):
  if i==ans:
      break
  if a[i]=="W":
    con+=1
    while ans>=0:
      ans-=1
      if i==ans:
        print(con)
        exit()
      if a[ans]=="R":
        break  
print(con)

Submission status: Wrong Answer

Solution code:
N = int(input())
c= list(input()) 
if c.count('R') == N:
	print(0)
	exit()
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-Rcnt)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=int(a/2)
d=0
e=a-1
i=0
while True:
    if b[i]=='W':
        for j in range(0,e+1)[::-1]:
            if b[j]=='R':
                d=d+1
                e=j-1
                break
    i=i+1
    if i+1>=e: break
print(d)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
def do(arr):
  mid = int(len(arr)/2)
  
  if len(arr) == 2:
    if arr[0] == 'W' and arr[1] =='R':
      return 1
    else:
      return 0 # is ok 
  if len(arr) == 1:
      return 0 # is ok 
    
    
  a1 = arr[0:mid]
  a2 = arr[mid:]
  c1 = do(arr[0:mid])
  c2 = do(arr[mid:])
  if c1==0 and c2==0:
    if a1[-1] == 'W' and a2[0] == 'R':
      return 1
    else:
      return 0
      
  else:
    if a1[-1] == 'W' and a2[0] == 'R':
      return c1 + c2 + 1
    else:
      return c1 + c2

    
    
    
    

print(do(s))

Submission status: Wrong Answer

Solution code:
# D Alter Altar

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

# Rの数
num_R = C.count("R")

# 元々全部R or Wの場合
if len(C) == num_R or num_R == 0:
  print(0)
  exit()

# 一色に染めるときの回数で少ない方
num_all = min(len(C) - num_R, num_R)

# 動かす必要のないWの数
_C = C[::-1]
safe_W = 0
for _c in _C:
  if _c == "W":
    safe_W += 1
  else:
    break

#左端にRを固める作戦の回数
space = 0
for c in C:
  if c == "W":
    space += 1
  elif c == "R":
    break
if num_R <= space:
  num_left = min(len(C) - num_R - safe_W, num_R)
else:
  num_left = min(len(C) - num_R - safe_W, num_R - 1)
  
print(min(num_left, num_all))

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(Rf==0 and Rr==0 and Centor=='R'):
        cnt=1
    if(Wf==0 and Wr==0 and Centor=='W'):
        cnt=1

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

    print(cnt)
 
resolve()

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)

    if c.count('R')==N or c.count('W')==N:
        print(0)
        return
    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-1, -1, -1):
        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 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 len(b) and  a.count('W') == 0:
        # print(f'{a=}')
        # print(f'{b=}')
        a, b = b[:len(b) // 2 + 1], b[len(b) // 2 + 1:]
    # print(f'{c=}')
    # print(f'{a=}')
    # print(f'{b=}')

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

    return max(wc, rc)


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N= int(input())
c=list(str(input()))
#N=4
#c=['W', 'W', 'R', 'R']
c.reverse()
#print(c)


num=0
for i in range(N):
    if c[i]=='R' :
        for u in reversed(range(math.ceil(N/2),N)):
            if c[u]=='W':
                c[u]='y'
                c[i]='W'
                num+=1
                break
            
#print(c)
print(num)

Submission status: Wrong Answer

Solution code:
s = int(input()) 
n = input()
str_list = list(n)
w_cnt = str_list.count('W')
r_cnt = str_list.count('R')
w_result = str_list[w_cnt:]
r_result = str_list[:r_cnt]
r = w_result.count('R')
w = r_result.count('W')
if w <= r:
    print(r)
else:
    print(w)

Submission status: Wrong Answer

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

# 最も右にあるR < 最も左にあるW

if len(set(c)) == 1:
    print(0)
    exit()

# 右からみて初めてRの位置
idx_R = n - 1
i = n - 1
while c[i] != 'R':
    if c[i] == 'R':
        idx_R = i
    i -= 1

# 左から見て初めてのWの位置
idx_W = 0
i = 0
while c[i] != 'W':
    if c[i] == 'W':
        idx_W = i
    i += 1

# しゃくとり
left = 0
right = n - 1
cnt = 0
while left < right:
    while c[left] == 'R': # W まで進める
        left += 1
    while c[right] == 'W': # R まで進める
        right -= 1
    cnt += 1
    left += 1
    right -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
flag = False
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
print(len([i for i in c[n//2:] if i == "R"]))

Submission status: Wrong Answer

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

if c == 'W' * n or c == 'R' * n:
   print(0)
   exit()
c = list(c)

ans = 0
x, y = c.index('W'), c.index('R')
while x < y:
   z = n-c[::-1].index('R')-1
   c[x], c[z] = c[z], c[x]
   ans += 1
   x, y = c.index('W'), c.index('R')
   #print(''.join(c))
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:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
N = int(input())
c =input().strip()
ans =0
count =0
w =[i for i, x in enumerate(c) if x == 'W']
r =[i for i, x in enumerate(c) if x == 'R']
if len(w)==0 or len(r)==0:
    ans =0
else:
    if max(w) <min(r):
        ans =min(len(w),len(r))
        #print("1111")
    else:
        for i in range(1,len(w)):
            if w[i] !=w[i-1]+1:
                count +=1
        an =count +1
        ans =min(an,len(w),len(r))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    word = list(input())
    l, r = 0, n - 1
    cnt = 0
    while l < r:
        while l < r and word[l] == 'R':
            l += 1
        while l < r and word[r] == 'L':
            r -= 1
        if l < r:
            word[l], word[r] = word[r], word[l]
            cnt += 1
            l += 1
            r -= 1
    print(cnt)
  
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    if n%2==0:
        tmpw=C.count("W")
        print(tmpw,C)
        C=C[tmpw:]
        print(tmpw,C)
        print(C.count("R"))
    else:
        tmpw=C.count("W")
        print(tmpw,C)
        C=C[tmpw-1:]
        print(tmpw,C)
        print(C.count("R"))

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":
            # TODO: ここが更新処理で決めつけられない
            while l_tmp - r_tmp + 1 >= n and s[r_tmp] == "W":
                r_tmp -= 1
                # print(s)

            # もしなければ更新処理
            if l_tmp - r_tmp + 1 == n and 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())
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(rc,wc+rc))
    tand = set(w) & set(wt)
    print(wc-len(tand))
else:
    if wc>rc:
        wt=list(range(rc-1,wc+rc))
        tand = set(w) & set(wt)
        print(wc-len(tand))
    else:
        wt=list(range(rc+1,wc+rc))
        tand = set(w) & set(wt)
        print(wc-len(tand))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
pre = c[0:N//2]
suf = c[(N+1)//2:N]
mid = c[N//2] if N % 2 != 0 else 'F'
ans = 0

pre_cnt = pre.count('W')
suf_cnt = suf.count('R')

ans = min(pre_cnt,suf_cnt)

if mid == 'W' and suf_cnt-pre_cnt > 0:
    ans+=1
elif mid == 'R' and pre_cnt-suf_cnt > 0:
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
r=0
w=0
p=0
count = 0
for i in range(len(c)):
    if c[i]=="R":
        r+=1
    else:
        w+=1
white = []

for i in range(len(c)):
    if c[i]=="R":
        r-=1
        
    else:
        white.append(r)
    if r==0:
        break
if len(white)==0:
    print(0)
else:
    for i in range(len(white)):
        if white[-i-1]>=len(white)-i:
            print(len(white)-i)
            break

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
c = input()
cnt = []
flag = False
x = ""
for i in range(n):
    if c[i]=="W":
        if x != "" and x != 0: cnt.append(x) 
        x=0
    else:
        if x != "": x += 1
if x!="": cnt.append(x)
if cnt==[]:
    print(0)
    exit()
if len(cnt)==1:
    print(cnt[0])
    exit()
ans = 0
cnt = deque(cnt)
x = cnt.popleft()
while cnt:
    y = cnt.popleft() 
    if x == 0 and not cnt: ans += y
    else:
        ans += 1
        y -= 1
        x = y
print(ans)