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 = str(input())
rc = c.count('R')
wc = c.count('W')
if rc ==0 or wc ==0:
  print('0')
else:
  s = c[:wc]
  print(wc-s.count('R'))

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
r=c.count("R")
w=c.count("W")

if w==0 or r==0:
    print(0)
else:
    ans=w
    cnt=0
    for i in range(N-1,N-w,-1):
        cnt+=(c[i]=="W")
        test=N-i-cnt+(w-cnt-(N-i-cnt))
        ans=min(ans,test)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
c = input()
counter = Counter(c)

if counter["R"] == 0 or counter["W"] == 0:
    print(0)
else:
    first_r = 0
    for i in range(N):
        if c[i] == "R":
            first_r = i+1
            break
    if first_r <= counter["R"]:
        print(min(counter["R"]-1,counter["W"]))
    else:
        print(min(counter["R"], counter["W"]))

Submission status: Wrong Answer

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

l = 0
r = -1

ans = 0

while l-r <= n:
    if c[l] == 'W':
        while r > -1 * n:        
            if c[r] == 'R':
                ans += 1
                r -= 1
                break
            else:
                r -= 1

    l += 1

print(ans)

Submission status: Wrong Answer

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

l = 0
r = n-1
ans = 0
while(True):
    while(s[l]=='R' and l<n-1):
        l+=1
    while(s[r]=='W' and r<0):
        r-=1
    if l < r:
        ans += 1
        l += 1
        r -= 1
    else:
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
s = input().strip()
l,r = 0,n-1
ct = 0
if s.count('W') == 0:
    print(ct)
    exit()
while l < r:
    while s[l] == 'R':
        l += 1
        if l >= r:
            break
    while s[r] == 'W':
        r -= 1
        if l >= r:
            break
    ct += 1
    l += 1
    r -= 1
print(ct)

Submission status: Wrong Answer

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

a = 0
rlist = []
wlist = []
for i in range(n):
  if stones[i] == "W":
    wlist.append(i+1)
  elif stones[i] == "R":
    rlist.append(i+1)
rlist.sort(reverse=True)
r_numbers =  len(rlist)
w_numbers =  len(wlist)

if r_numbers == 0 or w_numbers == 0:
  print(0)
elif r_numbers>=w_numbers:
  count = 0
  while rlist[count] > wlist[count] and count < w_numbers-1:
    count += 1
  if rlist[count] > wlist[count]:
    print(count+1)
  else:
    print(count)
elif r_numbers<=w_numbers:
  count = 0
  while rlist[count] < wlist[count] and count < r_numbers-1:
    count += 1
  if rlist[count] < wlist[count]:
    print(count+1)
  else:
    print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right as br

n = int(input())
c = list(input())
cFixed = [x for x in c]
cFixed.sort()
ans = 0
for i in range(n):
	if c[i] != cFixed[i]:
		j = br(c,"R")-1
		c[i] = c[j]
		c[j] = "W"
		ans += 1


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
lw_cnt=0
rr_cnt=0
flg=0
for i in range(n):
  #print(flg,c[i])
  if flg==0:
    if c[i]=='W':
      lw_cnt+=1
    else:
      flg=1
  elif flg==1:
    if c[i]=='W':
      flg=2
  else:
    if c[i]=='R':
      rr_cnt+=1
print(max(lw_cnt,rr_cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
k = input()
k2 = k[::-1]
i1 = 0
i2 = 0
cnt = 0
while i1 < n:
  if k[i1] == 'W':
    while i2 < n:
      if k2[i2] == 'R':
        k2 = k2[:i2] + 'W' + k2[i2+1:]
        cnt += 1
        break
      i2 += 1
  i1 += 1
  if i1 + i2 >= n:
    break
print(cnt)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
c_list = list(c)
ans = 0
flag = False
count = 0
W_count = c_list.count("W")
R_find = False
W_count_before = 0
for i in range(n):
    if not R_find and c[i] == "R":
        R_find = True
        break
    elif not R_find and c[i] == "W":
        W_count_before += 1
res = 0
for i in range(len(c)-1):
    if c[i] == "W" and c[i+1] == "R":
        res += 1
        flag = True
    elif c[i] == "R" and c[i+1] == "W":
        flag = False
    elif c[i] == "R" and c[i+1] == "R" and flag:
        count += 1

if res + count <= W_count_before:
    ans = res+count
else:
    ans = res+count-W_count_before

print(min(ans, W_count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
start = 0
end = n-1
count = [[0, 0] for _ in range(n)]
start_w = 0
end_r = 0
for i in range(n):
    if s[i] == "W":
        start_w += 1
    count[i][0] = start_w
for i in reversed(range(n)):
    count[i][1] = end_r
    if s[i] == "R":
        end_r += 1

print(min(map(max,count)))

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
ans = 0
while c:
    x = c.pop()
    if x == 'R':
        if w == 0:
            r += 1
        else:
            ans += min(r,w)
            w = 0
            r = 1
    else:
        w += 1
ans += min(r,w)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

stones = input()

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

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

Submission status: Wrong Answer

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

l = 0
r = -1

ans = 0

while l-r <= n:
    if c[l] == 'W':
        while r > -1 * n:        
            if c[r] == 'R':
                ans += 1
                break
            else:
                r -= 1
    r -= 1
    l += 1


print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
C=input()
from collections import Counter
count=Counter(C)
#print(count)
countR=count["R"]
countW=count["W"]
missR=0
missW=0
for i in range(N):
    now=C[i]
    if now=="W" and i<countW:
        missW+=1
    if now=="R" and i>countR:
        missR+=1
# print(countR, countW)
ans=min(missW, missR)+abs(missR-missW)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    if li[i] == "W" and li[j] == "R":
      li[i] = "R"
      li[j] = "W"
      ans += 1
    print(li)
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

l = 0
r = len(S)-1
ans = 0
while l < r:
    if S[l] == 'W' and S[r] == 'R':
        ans += 1
    l += 1
    r -= 1
    while l < len(S) and S[l] != 'W':
        l += 1
    while r >= 0 and S[r] != 'R':
        r -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
import heapq ,random
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))
def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def find_le(a, x):
    'Find rightmost value less than or equal to x'
    i = bi.bisect_right(a, x)
    if i:
        return i-1
    else:
        return -1



def main():
    try:
        n=I()
        l=list(input())
        pos=-1
        count=0
        upti=0
        for x in range(n):
            if l[x]=='W':
                count+=1
            if l[x]=='R':
                pos=x
                upti=count
        print(min(pos+1-upti,upti)) 
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()

Submission status: Wrong Answer

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

ans = 0
W = -1
for i in range(N):
    if S[i] == "W":
        W = i
        break
if W == -1:
    print(ans)
    sys.exit()

R = N
for i in range(N-1,-1,-1):
    if S[i] == "R":
        R = i
        break
if R == N:
    print(ans)
    sys.exit()

ans += 1


while W < R:
    for i in range(W+1,R):
        if S[i] == "W":
            W = i
            break
    else:
        print(ans)
        sys.exit()
    
    for j in range(R-1, W, -1):
        if S[j] == "R":
            R =j 
            ans += 1
            break
    else:
        print(ans)
        sys.exit()
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
S = list(input().split())
str_list = []
for s in S:
  str_list.append(list(s))
ans = 0
if n % 2 == 0:
  a = n // 2 
  ans = min(str_list[0][:a].count('W'), str_list[0][a:].count('R'))
else:
  b = (n+1) // 2
  ans = min(str_list[0][:b].count('W'), str_list[0][b:].count('R'))
print(ans)

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
ans = 0
while c:
    x = c.pop()
    if x == 'R':
        if w == 0:
            r += 1
        else:
            ans += min(r,w)
            w = 0
            r = 1
    else:
        w += 1
ans += min(r,w)

Submission status: Wrong Answer

Solution code:
def main():
    input()  # n
    stones = input()
    white_counter = []
    white_stones = 0
    red_stones = 0
    for color in stones:
        if color == 'W':
            white_stones += 1
        else:
            red_stones += 1
        white_counter.append(white_stones)
    print(white_counter[red_stones - 1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
cnt = 0
while 'WR' in s:
    cnt += s.count('WR')
    s = s.replace('WR', '')
print(cnt)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=input()
r_num=0
w_num=0
for i in b :

  if i=='W' :
    w_num+=1
  else :
    r_num+=1

count=0
if r_num<w_num :
  for i in range(r_num) :
    if b[i]=='R' :
      count+=1
else :
  for i in range(w_num) :
    if b[i]=='W' :
      count+=1
print(count)

Submission status: Wrong Answer

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

for i in range(len(c)):
    
    c = c.lstrip("R")
    if c.count("R")==0:
        break
    
    firstW = c.find("W")
    lastR = c.rfind("R")
    
    c=list(c)
    c[firstW] = "R"
    c[lastR] = "W"
    c="".join(c)
    
    print(c)


print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
c = list(input())
#print(c)
myr_cnt = c.count('R')
if myr_cnt == 0:
    print(1)
    sys.exit()
#print(myr_cnt)
myw_cnt = 0
for i in range(myr_cnt):
    if c[i] == 'W':
        myw_cnt += 1
print(myw_cnt)

Submission status: Wrong Answer

Solution code:
import collections

c=input()
c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]-count_r:
            ans+=1
            dis_r+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = input()
w = sum([True for c in C if c == "W"])
r = N - w

count = 0
for i, c in enumerate(C):
  if i < w and c == 'W':
    count += 1
print(count)

Submission status: Wrong Answer

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

n = ii()
s = input()

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

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
S = str(input())
if S == "R"*N or S == "W"*N:
  print("0")
  sys.exit()

S = list(S)

chk = ""
i1 = 0
while chk != "R":
  chk = S[i1]
  i1 += 1

chk = i1
i2 = 0
for i in range(i1, N):
  if S[i] == "R":
    i2 += 1

if i2 < i1 -1:
  print(i2+1)
else:
  print(i2)

Submission status: Wrong Answer

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

le = len(c)
if le % 2 == 0:
    i = le // 2
else:
    i = le // 2 + 1


ans = c[:i].count("W")
print(ans)

Submission status: Wrong Answer

Solution code:


import math

if __name__=="__main__":
    n=int(input())
    s=input()
    s=list(s)
    ##print(n,s)
    mid=n//2
    leftcount=0
    rightcount=0
    for i in range(0,mid):
        if(s[i]=="W"):
            leftcount+=1
            
    for i in range(mid,n):
        if(s[i]=="R"):
            rightcount+=1
    print(min(leftcount,rightcount))

Submission status: Wrong Answer

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

print(min(ans1,aru,dab))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=str(input())
Wh=0
Red=0
for i in range(len(c)):
    if c[i] == 'W':
        Wh+=1
    else:
        Red+=1
print(min(Wh,Red))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N = int(input())
S = list(input())
W = [0]*N
R = [0]*N
ans = N

for i in range(N):
    if S[i] == "W":
        W[i] = 1
    else:
        R[i] = 1
R.reverse()
R = list(accumulate(R))
W = list(accumulate(W))
if R[0] == 0 or W[N-1] == 0:
    ans = 0
else:
    sakai = R[N-1]
    ans = max(W[sakai-1], R[sakai])
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.find('RW')
        wnum = a[rightmostW+1:].count('R')
        leftmostR = a.rfind('R')
        wnum2 = a[:leftmostR+1].count('W')
        r = min(wnum, wnum2)
        print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [s for s in input()]
    ans = 0
    right = N-1
    for left in range(N//2):
        if S[left] == "W" and S[right] == "R":
            S[left], S[right] = S[right], S[left]
            ans += 1
        while N//2 <= right and S[left] == "W" and S[right] != "R":
            right -= 1

        if N//2 > right:
            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__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	C = inputStr()

	aida = []
	ai = 0
	yokei = 0
	flg = False
	for i,val in enumerate(C):
		ai += 1
		if val == "W":
			if flg == False:
				flg = True
		elif val == "R":
			if flg == False:
				pass
			else:
				yokei += 1
				aida.append(ai)

	if yokei == 0:
		print(0)
		sys.exit()

	ans = 0
	for i,val in enumerate(aida):
		if val <= yokei:
			continue
		ans += 1

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
nw = len(s.replace('R',''))
nr = n - nw

tmp_w = 0
ret = n
w_left = 0
for i, c in enumerate(s):
    if c == 'W':
        w_left += 1
    r_right = nr + w_left - i - 1
    ret = min(ret, max(r_right, w_left))
print(ret)

Submission status: Wrong Answer

Solution code:
import collections
def main():
    N = int(input())
    S = list(input())
    if len(set(S))==1:
        print(0)
        return
    for i in range(N):
        if S[i] == 'W':
            break
    S = S[i:]
    # print(S)
    cnt = 0
    left = 0
    right = len(S)-1
    while left<right:
        if S[left] == 'W':
            cnt +=1
            left += 1
            right -=1
        else:
            # S[left] == 'R'
            left += 1
            if S[right] =='W':
                right -=1
    print(cnt)
    return 0
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

c1 = 0
for v in c[: n // 2]:
    if v == "W":
        c1 += 1
c2 = 0
for v in c[n // 2 :]:
    if v == "R":
        c2 += 1
c3, c4 = 0, 0
for v in c:
    if v == "W":
        c3 += 1
    else:
        c4 += 1
print(min(c1, c2, c3, c4))

Submission status: Wrong Answer

Solution code:
# abc174_d.py
import queue
import math
N = int(input())
stone = list(input())
liv = list(reversed(stone))
squeue = []
livqueue = []
cnt = 0

for i in range(N//2):
    if stone[i]=="W":
        squeue.append(stone[i])
    if liv[i]=="R":
        livqueue.append(liv[i])
    if len(livqueue)!=0 and len(squeue)!=0:
        livqueue.pop()
        squeue.pop()
        cnt += 1
if N%2==1:
    if stone[N//2]=="W":
        squeue.append(stone[i])
    if liv[N//2]=="R":
        livqueue.append(liv[i])
    if len(livqueue)!=0 and len(squeue)!=0:
        livqueue.pop()
        squeue.pop()
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n%2==0 or n%5==0:
    print(-1)
    exit()

ans,c = 0,0

while 1:
    c+=1
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            break
    ans = ans//10
    if ans==0:
        break
print(c)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
c = input()
ans = 0
exchange = 0
for i in range(N):
    if c[i] == "W":
        exchange = i
        break
else:
    print(0)
    sys.exit()

for i in range(N):
    if N-1-i >exchange:
        if c[-(i+1)] =="R":
            c = c[:exchange]+"R"+c[exchange+1:]
            c = c[:-(i+1)]+"W"+c[(i+1)+1:]
            ans += 1
            for k in range(exchange+1,N):
                if c[i] == "W":
                    exchange = k
                    break
            else:
                break
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
tmp = 0
ans = 0
if(N % 2 == 0):
    tmp = N - (N//2) + 1
else:
    tmp = N - (N//2)
for i in range (tmp):
    if(c[i] == "W"):
        ans += 1
print(str(ans))

Submission status: Wrong Answer

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

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

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

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

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

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

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
for x in reversed(l):
    if x=="R":
        lastr+=1
    else:
        break
if wn<=lastr:
    print(wn)
else:
    print(lastr+(wn-lastr-1))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
c = input()

#t = c.count("R")
print(c.count("R")-c[:2].count("R"))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
c = input()
counter = Counter(c)

if counter["R"] == 0 or counter["W"] == 0:
    print(0)
else:
    first_r = 0
    for i in range(N):
        if c[i] == "R":
            first_r = i+1
            break
    if first_r <= counter["R"]:
        print(counter["R"]-1)
    else:
        print(counter["R"])

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  li = list(input())
  i = 0
  j = n-1
  ans = 0
  while(i < j):
    while(li[i] == "R" and i < j):
      i += 1
    while(li[j] == "W" and i < j):
      j -= 1
    li[i] = "R"
    li[j] = "W"
    ans += 1
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import  Counter
def resolve():
    N,=pin()
    C=input()
    X=Counter(C)
    a=(min(X["R"],X["W"]))#すべての色を変えにしてしまったらいい時
    c=list(C)


    rightlimit_R=-1
    for i in range(1,N):
        if c[-i]=="R":
            rightlimit_R=N-i
            break
    cnt=0

    for i in range(N):

        if c[i]=="W":

            for j in range(rightlimit_R-1,0,-1):
                if c[j]=="R":

                    
                    rightlimit_R=j
                    break

            cnt+=1
        if rightlimit_R<=i:
            
            break


    print(min(a,cnt))

Submission status: Wrong Answer

Solution code:
import collections

c=input()

tmp=collections.Counter(c)

count_r=0
count_w=0
ans=0
dis_r=0

for i in c:
    if dis_r == tmp["R"]:
        break
        
    elif i == "W":
        if count_r<=tmp["R"]-count_r:
            ans+=1
            dis_r+=1
    else:
        count_r+=1
        dis_r+=1
print(ans)

Submission status: Wrong Answer

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

left = 0
right = N-1
c = 0

for _ in range(int(N/2)+1):
  if left >= N or right < 0:
    break
  if seq[left] == "R":
    left += 1
    continue
  if seq[right] == "W":
    right -= 1
    continue
  left += 1
  right -= 1
  c += 1

print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
r=0
for i in range(n):
     if c[i]=='W':
          r=i
num=0
for i in range(n):
     if c[i]=='W':
          num+=1

if num>=n-r:
     print(num-1)
else:
     print(num)

Submission status: Wrong Answer

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

if N == count_R:
    answer = 0
elif N - count_R > count_R:
    answer = count_R
else:
    if 'R' in list(stones)[:N//2]:
        answer = count_R - 1
    else:
        answer = count_R

print(answer)

Submission status: Wrong Answer

Solution code:
K = int(input())
C = input()
C = list(C)
r = C.count("W")
A = C[:r].count("W")
B = C[-K+r:].count("W")
# print(A)
# print(B)
cnt = 0
for _ in range(200000):
    if A > 0:
        if B > 0:
            A -= 1
            B += 1
            cnt += 1
        else:
            A -= 1
            cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

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

W = N - C.count('W')
R = N - C.count('R')

CH = R - C[:R].count('R')
print(min(W,R, CH))

Submission status: Wrong Answer

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

ans1=c.count("R")
ans2=c.count("W")

ans3=0
for i in range(n//2):
    if c[i]=="W":
        ans3+=1

print(min([ans1,ans2,ans3]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def change(S,index,color):
	lstS = list(S)
	lstS[index] = color
	S = ''.join(lstS)

	return S


if __name__ == '__main__':
	N = int(input())
	S = input()
	L = 0
	R = N-1
	count = 0
	if S.count('W') == 0 or S.count('R') == 0:
		R = -1
	while(L < R):
		while(S[L] == 'R'):
			L += 1
		while(S[R] == 'W'):
			R -= 1
		S = change(S,L,'R')
		S = change(S,R,'W')
		L += 1
		R -= 1
		count += 1

	print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    c = list(input())
    r = 0
    w = 0
    for i in range(n):
        if c[i] == "R":
            r += 1
        else:
            w += 1
    print(r, w)

    count = 0
    for i in range(r):
        if c[i] == "W":
            count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
r=c.count("R")
w=c.count("W")

if w==0 or r==0:
    print(0)
else:
    ans=w
    cnt=0
    for i in range(N-1,N-w,-1):
        cnt+=(c[i]=="W")
        test=i-cnt+w-i
        ans=min(ans,test)
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
s = input()

fw = s.find('R')
fr = s[::-1].find('W')
if fw == -1 or fr == -1:
    print(0)
    exit()
else:
    sw = min(fw,fr)
    ret = sw
    ss = s[sw:n-sw]
    fg = 0
    cnt1 = 0
    cnt2 = 0
    for a in ss:
        if a == 'W' or fg:
            fg = 1
        if fg and a == 'R':
            cnt1 += 1
    fg = 0
    for a in ss[::-1]:
        if a == 'R' or fg:
            fg = 1
        if fg and a == 'W':
            cnt2 += 1
    print(sw + min(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

n = inp()
s = input().strip()
l,r = 0,n-1
ct = 0
if s.count('W') == 0:
    print(ct)
    exit()
while l < r:
    while s[l] == 'R':
        if l >= r:
            break
        l += 1
    while s[r] == 'W':
        if l >= r:
            break
        r -= 1
    ct += 1
    l += 1
    r -= 1
print(ct)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, len(c)//2+1):
    s = "W" * i + "R" * i
    num = c.count(s)
    if num == 0:
        break
    else:
        ans += num

print(ans)

Submission status: Wrong Answer

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

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

print(ans)