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:
import sys
from collections import deque

readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
c = deque(readline().rstrip())
w = 0
r = 0
W = 0
R = 0
C = list()
while c:
    x = c.pop()
    if x == 'R':
        if w == 0:
            r += 1
        else:
            if r == w:
                C.append(r)
            elif r > w:
                W += w
            else:
                R += r
            w = 0
            r = 1
    else:
        w += 1
if r == w:
    C.append(r)
elif r > w:
    W += w
else:
    R += r
C.sort()
X = deque((C))
while X:
    if R >= W:
        W += X.pop()
    else:
        R += X.pop()
print(max(W,R))

Submission status: Wrong Answer

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

prev = S[0]
cur = 'R'
count = 0
wNum = 0
changedPoint = -1
changed = False
for i in range(N-1, -1, -1):
    cur = S[i]
    changed = False
    if cur == 'R':
        for j in range(wNum, i):
            wNum = j + 1
            if S[j] == 'W':
                changedPoint = j
                changed = True
                break
        if changed == True:
            count += 1
        elif changedPoint != -1 and wNum != i:
            count += 1
            break
        else:
            break

    prev = cur
    if wNum == i-1:
        break

print(count)

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
R_flag = True
for i in range(N):
    if (c[i] == "W"):
        R_flag = False
    if (R_flag == False and c[i] == "R"):
        break
    if (i == N - 1):
        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:
import numpy as np

n = int(input())
c = np.array(list(input()))

count = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

if n_red == 0:
    c[0] = 'R'
    count += 1
    n_white -= 1
    n_red += 1

if n_white:
    p_white = np.where(c == 'W')[0].tolist()
    p_red = np.where(c == 'R')[0].tolist()
    num = min(len(p_white), len(p_red))
    i = 0
    while (i < num):
        if p_white[i] < p_red[-1-i]:
            count += 1
        i += 1

print(count)

Submission status: Wrong Answer

Solution code:
K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(1000000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
S = str(input())
print(S[:math.floor(N/2)].count('W'))

Submission status: Wrong Answer

Solution code:
i=int(input())
s=list(input())
fw,fr=0,0
count=0
cw=0
cr=0
if s[0]=="W" and s[i-1]=="R":
    count+=1
    s[0]="R"
    s[i-1]="W"
if s[i-1]=="R":
    count+=1
    s[i-1]="W"
for j in range (i):
    if s[j]=="W" :
        fw=j
        cw+=1  
        break
print (s)
for j in range (fw+1,i):
    if s[j]=="R":
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
#s = s[::-1]
from itertools import groupby
li = []
for k,v in groupby(s):
    li.append(list(v))
#print(li)
cnt = 0

for i in range(len(li)//2):
    cnt += min(len(li[i]),len(li[i+1]))
print(cnt)

Submission status: Wrong Answer

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

wl = 0
for i in range(N):
  if S[i] == "W":
    wl += 1

rl = N - wl
    
l = 0
if N % 2 == 0:
  for i in range(N//2):
    if S[i] == "W":
      l += 1
else:
  for i in range(N//2):
    if S[i] == "W":
      l += 1

print(min([wl, rl, l]))

Submission status: Wrong Answer

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
c = input()
w = []
r = []
for i in range(n):
    if c[i] == "W":
        w.append(i)
    else:
        r.append(i)
l_w = len(w)
l_r = len(r)
if l_r == 0 or l_w == 0:
    print(0)
else:
    for i in range(min(l_w,l_r)):
        if w[i] > r[-i]:
            print(i)
            break
        if i == min(l_w,l_r) -1:
          print(i+1)
          break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(map(str,input()))

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W > count_R:
    print(count_W)
else:
    print(count_R)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input() #s_1 s_2を分割して取得し、sに値を入れる
count_white = 0
white_flag = 0
white_renzoku = 0

count_red = 0
red_flag = 0
red_renzoku = 0
for i in range(N):
  if s[i]=='W':
    count_white = count_white+1
    red_flag = 1
  elif s[i]=='R':
    count_red = count_red+1
  if red_flag == 0:
      red_renzoku = red_renzoku+1
  if s[N-1-i]=='R':
    white_flag = 1
  elif s[N-1-i]=='W':
    if white_flag==0:
      white_renzoku = white_renzoku+1
white_irekae = count_white-white_renzoku
red_irekae = count_red-red_renzoku

if white_irekae==red_irekae:
  print(white_irekae-1)
elif white_irekae >= red_irekae:
  print(white_irekae)
else:
  print(red_irekae)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
ans=0
#WRがなくなるまでの最小繰り返し数
#Rの左はR.右はなんでもOK（RR?）
#Wの右はW.左はなんでもOK(?WW)
"""
RRRRRR
WWWWWW
RWWWWWW
RRRRRRRW
の大よそ4パターンが存在する
全部やって小さいのでいい？
２か所の色が変わっていいことなんてあるのか？？？

WRWWRWRR
を３回操作で変更する方法
左にRを集め、右にWを集めきればいい
前から順にみていき処置をするか、全部見たうえで計算式を立てるか（多分公社）
Wが連続、Rが連続、RWならOK（カウントを戻す）
WとRの個数をカウントする
#半分より右側にあるWの個数、半分より左側にあるRの個数で、少ないほうがまず＋
#残りは塗り替える
#一番真ん中はWならOK、Rなら＋１
"""
if N%2==0:
    W=c[:N//2].count("W")#変更すべきWの数
    R=c[N//2:].count("R")
    ans=max(R,W)
else:
    W=c[:N//2].count("W")#変更すべきWの数
    R=c[N//2:].count("R")
    ans=max(R,W)
    if c[N//2]=="R":
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
ans = 0
fs = 0
ls = N - 1
for _ in range(N):
    for i, ci in enumerate(c[fs:ls]):
        if ci == 'W':
            break
        fs += 1
    for i , ci in enumerate(c[fs:ls:-1]):
        if ci == 'R':
            break
        ls -= 1
    if fs == ls:
        break
    ans += 1
    fs += 1
    ls -= 1
    #print(c[fs:ls] + 1)
    if len(c[fs:ls + 1]) <= 1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys

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

count_r = 0
for i in c:
    if i == 'R':
        count_r += 1
count_w = n - count_r
ans = min(count_r, count_w)
if ans == 0:
    print(0)
    sys.exit()

# pattern = r"^R*W*$"
# print(re.fullmatch(pattern, "WWWW"))
l = 0
r = n-1
count = 0
# while re.search(pattern, c):
while l < r:
    while c[l] == 'R':
        l += 1
    while c[r] =='W':
        r -= 1
    c[l] = 'R'
    c[r] = 'W'
    count += 1
    # print(c, l, r)
    if l == r-1:
        break

ans = min(count, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
f=False
ans=0
a1=0
wb=wc=0
rb=rc=0
 
for i in range(n):
  if c[i]=="R":
    rc += 1
  else:
    wc += 1
 
for i in range(n):
  if c[i]=="W":
    f=True
 
  if f:
    if c[i]=="R":
      rb+=1
      rc-=1
    else:
      wb+=1
      wc-=1
 
    if wb==rc:
      print(wb)
      exit()
 
print(rb)

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':
      try:
        if a1[-2] == 'W' and a2[1] == 'R':
          return 2
        else:
          return 1
      except:
        return 1
    else:
      return 0
      
  else:
    if a1[-1] == 'W' and a2[0] == 'R':
      try:
        if a1[-2] == 'W' and a2[1] == 'R':
          return c1 + c2 + 2
        else:
          return c1 + c2 + 1
      except:
        return 1

    else:
      return c1 + c2

    
    
    
    

print(do(s))

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:
		if W_cnt>R_cnt:
			print(R_cnt+1)
		else:
			print(R_cnt)
		
else:print(0)

Submission status: Wrong Answer

Solution code:
import re

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

def set_c(a):
    a = re.sub('^[R]*W', 'W', a)
    a = re.sub('R[W]*$', 'R', a)
    return a

c = set_c(c)
l1 = len(c)//2
l2 = (len(c)+1)//2

print(min(c[:l1].count('W'),c[l2:].count('R')))

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 True:
    if c[i] == 'R':
        idx_R = i
        break
    i -= 1

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

if idx_R < idx_W:
    print(0)
    exit()

# しゃくとり
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()) 
if c.count('R') == N:
	print(0)
	exit()
div=0
addcnt = 0
if N %2 == 1:
	div =1
	Q = c[int(N/2)]
	# print(Q)
	if Q == 'Q':
		addcnt +=1
		# print('QQQ!')
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+addcnt)

Submission status: Wrong Answer

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

n = int(input())
n2 = n//2
c = input()

if c.count("R") == n:
    print(0)
elif n%2 == 0:
    cnt = c.count("R", n2, n)
    print(cnt)
else:
    cnt = c.count("R", n2+1, n)
    print(cnt)

Submission status: Wrong Answer

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

N, = map(int, input().split())
c = list(input())
c = ['R', 'R', 'R', 'W', 'W', 'W', 'W', 'R', 'R', 'R']

while True:
    if c[0]=='R':
        c = c[1:]
    else:
        break
    if c==[]:
        break

ans = 0
if 'R' not in c:
    ans = 0
else:
    first_R = N
    con_flag = False
    for i, cc in enumerate(c):
        if cc=='R':
            con_flag = True
            num_left_W = i - 2
        if cc=='W' and con_flag:
            first_R = i
            con_flag = False
            break

    num_right_R = sum([1 for cc in c[first_R:] if cc=='R'])

    num_W = len(c) - (num_right_R+1)
    ans = num_W

    if num_right_R>=num_left_W:
        ans = min(ans, num_right_R)
    else:
        ans = min(ans, num_left_W)

Submission status: Wrong Answer

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

left = 0
right = len(c)-1

count=0
if (right+1)%2==0:
    while (left-1)!=right:
        print(right,left)
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=1
            count+=1
else :
    while left!=right:
        if c[left]=='R':
            left+=1 
        elif c[right]=='W':
            right-=1
        elif c[left]=='W' and c[right]=='R':
            left+=1
            right-=1
            count+=1

ans = count
print(ans)

Submission status: Wrong Answer

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

k = int(input())
s = ''

rs = []

start = time.time()
cnt = 0 
while True:
    cnt += 1
    s += '7' 
    n = int(s)
    r = n%k 
    if r==0:
        print(cnt)
        exit()

    if r in rs: 
        print(-1)
        end = time.time()
        exit()

    rs.append(r)
    end = time.time()
    t = end-start 
    if t >= 1.8:
        print(k-1)
        exit()

Submission status: Wrong Answer

Solution code:
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
 
 
def main():
    N = int(input())
    S = input()
    l=0
    r=len(S)-1
    ans=0
    while(1):
        for i in range(l,len(S)):
            if S[i]=='W':
                l=i
                break
        for j in range(r,0,-1):
            if S[j]=='R':
                r=j
                break
        
        if i<j:
            ans+=1
            l=i+1
            r=j-1
        else:
            break
    print(ans)

 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

most_left_r = 0
r_cnt_r = 0
r_cnt_w = 0
l_cnt_w = 0
res = 0
for i in range(len(s)):
    if s[i] == "R":
        most_left_r = i
        break
for j in range(most_left_r+1, len(s)):
    if s[j] == "R": r_cnt_r+=1
    else: r_cnt_w+=1

for k in range(0, most_left_r):
    if s[k] == "W": l_cnt_w += 1

res = max((min(r_cnt_r, r_cnt_w)), l_cnt_w)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(map(str,input()))

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i <= N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W < count_R:
    print(count_W)
else:
    print(count_R)

Submission status: Wrong Answer

Solution code:
def main(N, S):
    ans = 0
    cw = S.count("W")
    cr = S.count("R")
    cht = min(cw, cr)
    right = N-1
    for left in range(N):
        if S[left] == "W" and S[right] == "R":
            S[left], S[right] = S[right], S[left]
            ans += 1
        while left < right and S[left] == "W" and S[right] != "R":
            right -= 1

        if left >= right or S[left] == "W":
            break
    add = 0
    T = S[:]
    for i in range(N-1):
        if S[i] == "W" and S[i+1] == "R":
            S[i+1] = "W"
            add += 1
    add2 = 0
    for i in range(N-1)[::-1]:
        if T[i] == "W" and T[i+1] == "R":
            T[i] = "R"
            add2 += 1
    print(ans + min(add, add2))


if __name__ == '__main__':
    N = int(input())
    S = [s for s in input()]
    main(N, S)

Submission status: Wrong Answer

Solution code:
# !/usr/bin/python3


def solve(a, n):
    count = 0

    end = n-1
    for i in range(n):
        if a[i] == 'W':
            for j in range(end, i-1, -1):
                if i == j: return count
                if a[j] == 'R':
                    count += 1
                    end -= 1
                    break

    return count


if __name__ == "__main__":
    n = int(input())
    a = input()

    print(solve(a, n))

Submission status: Wrong Answer

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

if 'R' not in S or 'W' not in S:
    print(0)
else:
    w = S.count('W')
    L = S[0:w]
    R = S[w:]
    r = R.count('R')
    print(r)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    c = list(input())
    dp = [0]*n
    left = c[0]
    for i in range(1, n):
        if c[i] == "W":
            dp[i] = dp[i-1]
            left = "W"
        else:
            if left == "R":
                dp[i] = dp[i-1]
            else:
                dp[i] = dp[i-1] + 1
                left = "W"
    dpr = [0]*n
    left = c[0]
    for i in range(1, n):
        if c[i] == "R":
            dpr[i] = dpr[i-1]
            left = "R"
        else:
            if left == "W":
                dpr[i] = dpr[i-1]
            else:
                dpr[i] = dpr[i-1] + 1
                left = "R"
    
    print(min(dp[n-1], dpr[n-1]))
            
        

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0
w = C.count("W")
r = C.count("R")

print(C[0:w].count("W"))

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
text=input()
#wRwのindexを配列
wrw=0
flag_r=False
if text[0]=='R':
    flag_r=True
i=0
cnt=0
ch=True
ans=0
cnt_r=0
wkita = False
saisyo_r=0
for i in range(len(text)):
    if text[i]=='R':
        cnt_r+=1
    if ch:
        if  text[i]=='W':
            cnt+=1
            wkita=True
        elif wkita:
            ch=False
        else:
            saisyo_r+=1


if cnt_r==len(text):
    print(0)
    sys.exit()
if saisyo_r==cnt_r:
    print(0)
    sys.exit()
if text[0]=='R':
    print(cnt_r-1)
    sys.exit()
if cnt>=cnt_r:
    print(cnt_r)
    sys.exit()
ans+=cnt
cnt_r-=cnt+saisyo_r+1
if cnt_r>=0:
    ans+=cnt_r
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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

    c = c.lstrip('R')
    if c.count('R') == 0:
        return 0

    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'{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:
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:
    cnt = 0
    for i in range(n):
        if c[i] == 'W':
            cnt += 1
        else:
            rcnt -= 1
            if rcnt == 0:
                break
    print(cnt)

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(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:
import sys
import os
import itertools
import numpy as np
from collections import deque

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

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

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

    ans=0

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

        # print(R_info)
        for i,n in enumerate(R_info):
            # print(i)
            # print("ans="+str(ans))
            # print("R_n="+str(R_n))
            # if R_n==0:
            #     break
            if n==0:    #連続しているばあい
                R_n-=1  #残りのＲの数ー１
            elif n>=1 and R_n-1>=n: #間が埋められる場合
                R_n-=n+1    #自分＋ｎ子分移動
                ans+=n  #ｎこ移動ぶん＋
                # print(ans)
                # print(R_n)
            else:   #もう間が埋められない場合
                ans+=R_n    #残りのＲは消すしかない
                # print(ans)
                break
        print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
mid=len(c)//2
rl=c[mid:].count('R')
wf=c[:mid].count('W')
print(min(rl,wf))

Submission status: Wrong Answer

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

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

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

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))
    elif max(r) <min(w):
        ans =0
        #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:
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 C2.count('R') == 0 and
       C2.count('W') == 0 and C1.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:
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(w)
    else:
        print(r)

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

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:
n = int(input())
c = input()

ans = 0

l = 0
r = n-1

lsl = 0
lsr = 0

while l < n:
  lc = c[l]
  if lc == 'W':
    while 0 <= r:
      rc = c[r]
      if rc == 'R' and l < r:
        ans += 1
        lsl = l
        lsr = r
        r -= 1
        break
      r -= 1
  l += 1
#print('mid : ', ans, lsl, lsr)
if (lsr - lsl) > 1:
  s = c[lsl+1:lsr]
  for i in range(1, len(s)):
    if c[i-1] == 'W' and c[i] == 'R':
      ans += 1
print(ans)

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 reversed(range(math.ceil(N/2),N)):
    if c[i]=='R' :
        for u in (range(N)):
            if c[u]=='W':
                c[u]='y'
                c[i]='W'
                num+=1
                break
            
#print(c)
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(map(str,input()))

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W < count_R:
    print(count_W)
else:
    print(count_R)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = input() #s_1 s_2を分割して取得し、sに値を入れる
count_white = 0
white_flag = 0
white_renzoku = 0

count_red = 0
red_flag = 0
red_renzoku = 0
for i in range(N):
  if s[i]=='W':
    count_white = count_white+1
    red_flag = 1
  elif s[i]=='R':
    count_red = count_red+1
  if red_flag == 0:
      red_renzoku = red_renzoku+1
  if s[N-1-i]=='R':
    white_flag = 1
  elif s[N-1-i]=='W':
    if white_flag==0:
      white_renzoku = white_renzoku+1
white_irekae = count_white-white_renzoku
red_irekae = count_red-red_renzoku

if white_irekae>=red_irekae:
  print(white_irekae)
else:
  print(red_irekae)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
l = 0
j = 0
a = [0]*n
b = [0]*n
for i in range(n):
  if(c[i]=='W'):
    a[l] =i+1
    l +=1
l = 0
for i in range(n-1,0,-1):
  if(c[i]=='R'):
    b[j] = i+1
    j +=1
j = 0
while(a[l] < b[l]):
      a[l]=0
      b[l]=0
      l+=1
      j+=1
print(j)

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 + 1 <= j - 1:
    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:

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:
import sys


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

    c = c.lstrip('R')
    if len(c) < 2:
        return 0

    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'{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:
def line_check(line, count):
    # print(line)
    try:
        first_w = line.index("W")
    except:
        return count
    try:
        next_r_from_last = len(v_a) - list(reversed(v_a)).index("R") - 1
    except:
        return count
    if next_r_from_last > first_w:
        line[first_w], line[next_r_from_last] = line[next_r_from_last], line[first_w]
        count += 1
        return line_check(line, count)
    else :
        return count



_ = input()
v = input()
v_a = [str(i) for i in v]
# v_a = ["W","R","W","R","W"]
a = line_check(v_a, 0)
print(a)

Submission status: Wrong Answer

Solution code:
score = int(input())
word = input()
kaisu = 0

scint = [0]*score
for i in range(score):
    if word[i] == 'R':
        scint[i] = 0
    else:
        scint[i] = 1

i = 0
j = 0
while i + j + 2 <= score:
    if scint[i] > scint[score-j-1]:
        kaisu += 1
        i += 1
    elif scint[i] == 0:
        i += 1
    j += 1

i = 0
j = 0
while i + j + 2 <= score:
    if scint[j] > scint[score-i-1]:
        kaisu += 1
        i += 1
    elif scint[j] == 0:
        i += 1
    j += 1
        
print(kaisu)

Submission status: Wrong Answer

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

if (s.count("R") == 0 or s.count("W") == 0):
    print(0)
    sys.exit()

middle = int(len(s) // 2)

rr = s[middle:].count("R")
rw = len(s) - rr
lr = s[0:middle].count("R")
lw = len(s) - lr

if (rr == lw):
    print(rr)
    sys.exit()

if (rr > lw):
    print(lw)
    sys.exit()

if (rr < lw):
    print(rr)
    sys.exit()

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:
import numpy as np

n = int(input())
c = np.array(list(input()))

count = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

if n_red:
    if n_white:
        p_white = np.where(c == 'W')[0].tolist()
        p_red = np.where(c == 'R')[0].tolist()
        num = min(len(p_white), len(p_red))
        i = 0
        while (i < num):
            if p_white[i] < p_red[-1-i]:
                count += 1
            i += 1
else:
    count = n_white

print(count)

Submission status: Wrong Answer

Solution code:
c = list(input())
# print(c)
R_c = c.count('R')
ans = 0
# W_c = c.count('W')
# print(R_c,W_c)
for i in range(R_c):
    if c[i]=='W':
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
c=int(a/2)
d=0
e=a-1
i=0
while i+1<e:
    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
print(d)