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
#input = sys.stdin.readline  #文字列では使わない
N = int(input())
c =input().strip()
ans =0
count_w =0
count_r =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_w +=1
        an_w =count_w +1
        for i in range(1,len(r)):
            if r[i] !=r[i-1]+1:
                count_r +=1
        an_r =count_r +1
        ans =min(an_w,an_r,len(w),len(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')
    c = c.rstrip('W')
    if c.count('R') == 0 or c.count('W') == 0:
        return 0
    # print(f'{c=}')

    a, b = c[:len(c) // 2 + 1], c[len(c) // 2 + 1:]
    # 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_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 == range_end-1:
            w_pos = range_end-1 
    for j in reversed(range(range_start, range_end)):
      if c_list[j] == "R":
        r_pos = j
        range_end = j
        break
      if j == range_start-1:
        r_pos = range_start-1 
    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())
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)


R_R = 0
L_R = 0
for i in range(N - 1, -1, -1):

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

    if (c[i] == "W"):
        break
    L_R += 1

Ans1 = R_R - L_R

L_W = 0
R_W = 0
for i in range(N):
    if (c[i] == "W"):
        L_W += 1
for i in range(N - 1, -1, -1):
    if (c[i] == "R"):
        break
    R_W += 1

Ans2 = L_W - R_W


i = 0
j = N - 1

Ans3 = 0

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

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


print(min(Ans1, Ans2, Ans3))

Submission status: Wrong Answer

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

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

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


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

if r == 0:
    W_r = 0

# print(r,w)
print(W_r)

Submission status: Wrong Answer

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

ans = 0

color = [C[0]]
c = [0]
for i in range(len(C)):
    if C[i] == color[-1]:
        c[-1] += 1

    else:
        color.append(C[i])
        c.append(1)

idx_w = 0
idx_r = len(c) - 1
while True:
    if color[idx_w] != 'W':
        idx_w += 1
    if color[idx_r] != 'R':
        idx_r -= 1

    if idx_w == len(c) or idx_r == 0:
        break
    # print(idx_w)

    ans += min(c[idx_r], c[idx_w])
    if c[idx_w] < c[idx_r]:
        c[idx_r] -= c[idx_w]
        c[idx_w] = 0
        idx_w +=1
    else:
        c[idx_w] -= c[idx_r]
        c[idx_r] = 0
        idx_r -=1

    if idx_w + 1 >= idx_r or idx_w == len(c) or idx_r == 0:
        break

print(ans)

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':
    if cnt>=cnt_r-saisyo_r-1:
        print(cnt_r-saisyo_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:
n = int(input())
c = input()

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

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

    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[:rc].count('W'), c[wc-1:].count('R'), n - rc, n-wc))

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)
else:
    cnt = c.count("R", n2, n)
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
d = [0] * N
for i in range(N):
    if c[i] == 'R':
        d[i] = 1
count = 0
v = [0] * N
k = 1
l = -1
for i in range(0, N):
    if d[i] == 0:
        v[i] = k
        k += 1
for j in reversed(range(0, N)):
    if d[j] == 1:
        v[j] = l
        l -= 1
for i in range(0, N):
    if v[i] > 0:
        count += 1
    if v[i] < 0:
        if i == 0:
            for i in range(1,N):
                if d[i] == 1:
                    break
                if i == N-1:
                    print(0)
        elif v[i-1] >= -v[i]:
            print(v)
            break
print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
line = input()

# print(n)
# print(line.count('W'))
# print(line[:math.floor(n/2)])
# print(line[math.ceil(n/2):])

# left_l = line[:math.floor(n/2)]
# right_l = line[math.ceil(n/2):]
# min_WR = min(left_l.count('W'),right_l.count('R'))

# if min_WR > 0:
#     print( min_WR + abs(left_l.count('W')-right_l.count('R')))
# else:
#     print(0)


w_count = 0

for c in line:
    if c == 'W':   
        w_count += 1
    else:
        break

print(line.count("WR") + max(w_count-1,0))

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
 
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
 
    return K * x
def main():  #startline-------------------------------------------
    n = int(input())
    s = input()
    print(s[:n//2+1].count("W"))
        
                
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

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

if C[0]=="W":
  w = C.find("R")
  r = C[w:].find("W")
  t = C.count("R")
  
  if w<=t-r:
    print(t-w)
  else:
    print(t)
    
else:
  r1 = C.find("W")
  w  = C[r1:].find("R")
  r2 = C[r1+w:].find("W")
  t = C.count("R")
  
  if w<=t-r1-r2:
    print(t-r1-r2)
  else:
    print(t)

Submission status: Wrong Answer

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

left=0
right=N
ans=0
while left<right:
    
    print(left,right, list(range(left,N)), list(range(right-1,-1,-1)))
    for il in range(left,N):
        if c[il]=="W":
            break
    else:
        il=N
        
    for ir in range(right-1,-1,-1):
        if c[ir]=="R":
            break
    else:
        ir=-1
    
    
    if il<ir:
        c[il]="R"
        c[ir]="W"
        left=il+1
        right=ir
        ans+=1
    else:
        break
        
print(ans)

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 == 'W':
		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-addcnt)
else:
	print(Lcnt-Rcnt+addcnt)

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
                if len(rls) == 0:
                    print(count)
            else:
                break
        ww = ww + 1
        rr = len(rls)

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
if n==2:
    if c=="WR":
        print(1)
    else:
        print(0)
else:
    counter=0
    for k in range(c.count("W")):
        for i in range(n-1):
            if c[i]=="W" and c[i+1]=="R":
                res=False
                for j in range(n-1,i,-1):
                    if c[j]=="R":
                        counter+=1
                        c[i]="R"
                        c[j]="W"
                        res=True
                        break
                if res==False:
                    c[i]="R"
                    counter+=1

    print(counter)

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=temp_array[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:
n = int(input())
c = input()
count = 0
for i in range(n//2 + 1):
  if 'W' == c[i]:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np

k = int(input())

s = 0
cnt = 0
flg = False

while (cnt < 1e7):
    cnt += 1
    print(cnt)
    s = s * 10 + 7 
    # print(s)

    if s % k == 0:
        flg = True
        break

    if k < 7:
        flg = False
        break

    if k % 2 == 0:
        flg = False
        break


if flg == True:
    print(cnt)
else:
    print(-1)

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

Submission status: Wrong Answer

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

N, = map(int, input().split())
c = list(input())

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

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')
    c = c.rstrip('W')
    if c.count('R') == 0 or c.count('W') == 0:
        return 0
    # print(f'{c=}')

    a, b = c[:len(c) // 2 - 1], c[len(c) // 2 - 1:]
    # 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())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
count = 0
if ((C1.count('W') == 0 and C2.count('R') == 0) or
       (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')
elif(C1.count('W') == C2.count('W') and
       C2.count('R') == C1.count('R')):
    count = min(C1.count('W'),C2.count('R'))
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:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):
 
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
 
    return K * x
def main():  #startline-------------------------------------------
    n = int(input())
    s = input()
    print(s[:n//2].count("W"))
        
                
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input()
wn=0
rn=0
for i in l:
    if i=="R":
        rn+=1
    if i=="W":
        wn+=1
lastr=0
lastww=0
for x in reversed(l):
    if x=="R":
        lastr+=1
        l=l.strip("R")
    else:
        break
    for x in reversed(l):
        if x=="W":
            lastww+=1
        else:
            break
if lastr>=1:
    if wn<=lastr:
        print(wn)
    else:
        print(lastr+(wn-lastww-1))
lastrr=0
lastw=0
if lastr==0:
    for x in reversed(l):
        if x=="W":
            lastw+=1
            l=l.rstrip("W")
        else:
            break
    for x in reversed(l):
        if x=="R":
            lastrr+=1
        else:
            break
    wnoko=wn-lastw
    if wnoko<=lastrr:
        print(wnoko)
    elif wnoko==lastrr+1:
        print(wnoko-1)
    else:
        print(wnoko-lastrr+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
count = 0
left_f = 0
right_f = N-1
while 1:
    if c[left_f] == 'R' and c[right_f] == 'W':
        left_f += 1
        right_f -= 1
    elif c[left_f] == 'W' and c[right_f] == 'W':
        right_f -= 1
    elif c[left_f] == 'R' and c[right_f] == 'R':
        left_f += 1
    else:
        count += 1
        left_f += 1
        right_f -= 1
    if left_f == right_f:
        break
    if c[left_f:right_f].count('W') == len(c[left_f:right_f]):
        count += len(c[left_f:right_f])
        break
print(count)

Submission status: Wrong Answer

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


rcnt = c.count('R')
wcnt = c.count('W')

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
if c.count('R') ==n or c.count('W') == n:
    print(0)
else:
    if c[0]=='W':
        if c[-1] =='W':
            x = c.count('W')-1
            y = c.count('R')
        else:
            x = c.count('W')
            y = c.count('R')
    else:
        if c[-1] =='W':
            x = c.count('W')-1
            y = c.count('R')-1
        else:
            x = c.count('W')
            y = c.count('R')-1
    arr = c
    r_num = c.count('R')
    num = arr.index('R')
    z = 0
    while r_num > 0:
        if num > r_num-1:
            z += r_num
            break
        elif num == r_num-1:
            z += r_num-1
            break
        else:
            arr = arr[num+1:]
            r_num = r_num-num
            z += num

    print(min(x,y,z))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
count = 0
for i in range(n//2):
  if 'W' == c[i]:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
f=False
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
  else:
    rc-=1
 
  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 = input()
c = list(input())
for i in range(len(c)):
    if c[0] == "R":
        del c[0]
    else:
        break
W_left = 0
R_center = 0
for i in range(len(c)):
    if c[0] == "W":
        W_left += 1
        del c[0]
    else:
        break
for i in range(len(c)):
    if c[0] == "R":
        R_center += 1
        del c[0]
    else:
        break
W = c.count("W")
R = c.count("R")
Ans = 0
if W_left > R_center:
    Ans = R_center
elif W_left > R:
    Ans = Ans + W_left
else:
    Ans = Ans + R
print(Ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
c = list(input())
C = collections.Counter(c)
C_2 = collections.Counter(c[:n//2])
tmp_1 = min(C['W'],C['R'])
tmp_2 = min(C_2['W'],C['R']-C_2['R'])
ans = min(tmp_1,tmp_2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[:rc].count('W'), c[wc:].count('R'), n - wc, n - rc))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0 or s['R'] == 0 or c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
  sys.exit()
r = s['R']
las_pos=0
count = 0
for i, v in enumerate(c):
  if v == 'R':
    if i - las_pos < r:
      r = r - (i - las_pos + 1)
      count += (i - las_pos)
      las_pos = i
    else:
      count += r
      break
print(count)

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
if len(set(list(c)))==1:
    ans=0
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')
    c = c.rstrip('W')
    if c.count('R') == 0 or c.count('W') == 0:
        return 0
    # print(f'{c=}')

    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) + 100


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


if __name__ == '__main__':
    main()

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 == 'R':
		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:
N = int(input())
S = input()
Cnt = 0
if S == "W"*N:
    print(0)
else:
    for i in range(N//2):
        if S[i] == "W":
            Cnt += 1
    print(Cnt)

Submission status: Wrong Answer

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

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

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

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

    # print(a, L, R, n//2, L["W"], R["R"])
    cnt = 0
    b = list(a)
    
    # 入れ替え
    for i in range(n):
        if b[i] == "W":
            b[i] = "R"
            cnt += 1
        if cnt == ct:
            break
    a = "".join(b)
    
    # 探索する側の決定
    if n // 2 != 1:
        if L["W"] > R["R"]:
            ct = check(a[:n//2], n // 2, ct)
            print(a, a[:n//2])
        elif L["W"] < R["R"]:
            ct = check(a[n//2:], n // 2, ct)
            print(a, a[n//2:])

    return ct

print(check(c, N, 0))

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:
        left_W = C[:a].count ('W')
        left_R = C[:a].count('R')
    else:
        left_W = C[:a+1].count('W')
        left_R = C[:a+1].count('R')
    right_R = C[a:].count('R')
    right_W = C[a:].count('W')

    if left_W <= right_R:
        ans = left_W
        if left_R == 0:
            ans += 1
    else:
        ans = right_R
        if right_W == 0:
            ans += 1


print(ans)

Submission status: Wrong Answer

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

r = c.count('R')
w = c.count('W')
l = c[w:].count('R')
ans = min(r, w, l)
print(ans)

Submission status: Wrong Answer

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

if N % 2 == 0:
    k = N // 2
    B = A[0:k]
    #print(B)
    print(B.count("W"))

else:
    kk = N // 2
    B = A[0:kk+1]
    #print(B)
    print(B.count("W"))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
wc = c.count('W')
rc = c.count('R')
print(min(c[:rc].count('W'), c[wc:].count('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)].count('W'),
                c[(n // 2):].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:
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,-1,-1):
            if S[j]=='R':
                r=j
                break
        print(i,j)
        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:
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+1):
    if S[i] == "W":
      l += 1

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

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
if N%2 == 0:
    P = c.count("R")
    if P == 0 or P == N:
        print(0)
    else:
        c1 = c[0:N//2]
        c2 = c[N//2:N]
        W = c1.count("W")
        R = c2.count("R")
        if W == R:
            print(W)
        elif W < R:
            print(R-W)
        elif R < W:
            print(W-R)
else:
    P = c.count("R")
    if P == 0 or P == N:
        print(0)
    else:
        c1 = c[0:N//2]
        c2 = c[N//2+1:N]
        W = c1.count("W")
        R = c2.count("R")
        if W == R:
            print(W)
        elif W < R:
            print(R-W)
        elif R < W:
            print(W-R)