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())
A = list(input())

if A.count('R')==n:
    print(0)
elif A.count('W')==n:
    print(0)
else:
    cnt = max(A[:0].count('W'),A[0:].count('R'))
    mini = cnt
    for i in range(1,n-1):
        if A[i] == 'W':
            cnt += 1
        else:
            cnt -= 1
            mini = min(cnt,mini)
    print(mini)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 2000000 
#aw=s.count('W')
ar=s.count('R')
pw=0
pr=0
for i in range(n-1):
	if (s[i] == 'R'):
		pr=pr+1
	else:
		pw=pw+1
	if (max(pw,ar-pr) < res):
		res = max(pw,ar-pr)

print(str(res))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def change(c_array):
    if len(c_array) % 2 == 0: n2 = len(c_array) // 2
    else: n2 = len(c_array) // 2 + 1
    count = 0
    w_idx, r_idx = [], []
    for i in range(n2):
        if c_array[i] == "W":
            w_idx.append(i)
        if c_array[len(c_array) - 1 - i] == "R":
            r_idx.append(len(c_array) - 1 - i)
        
    count = min(len(w_idx), len(r_idx))
    for i in range(count):
        c_array[w_idx[i]] = "R"
        c_array[r_idx[len(r_idx) - 1 - i]] = "W"
        
    if len(w_idx) < len(r_idx): c_array = c_array[:n2+1]
    else: c_array = c_array[n2:]
    
    if len(w_idx) == len(r_idx): flag = True
    else: flag = False
            
    return c_array, count, flag
    
def main():
    n = int(input())
    c_array = list(input())
    # print(c_array)
    count = 0
    flag = False
    
    if not flag:
        c_array, tmp_count, flag = change(c_array)
        count += tmp_count
    
    print(count)
        
main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def main():
    n = int(input())
    c_array = input()
    if n % 2 == 0: n2 = n // 2
    else: n2 = n // 2 + 1
    count = 0
    w_idx, r_idx = [], []
    for i in range(n2):
        if c_array[i] == "W":
            w_idx.append(i)
        if c_array[len(c_array) - 1 - i] == "R":
            r_idx.append(len(c_array) - i)
    print(min(len(w_idx), len(r_idx)))
        
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
w = 0
r = c.count('R')
ans = float('inf')

for k in range(n):
  if c[k] == 'W':
    w += 1
  elif c[k] == 'R':
    r -= 1
  cnt = max(w, r)
  if ans > cnt:
    ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
lst = []
w = 0
r = 0
for i in range(n):
  if c[i] == 'W':
    w += 1
  elif c[i] == 'R':
    r += 1
ans = max(w, r)

for k in range(n):
  if c[k] == 'W':
    w += 1
  elif c[k] == 'R':
    r -= 1
  cnt = max(w, r)
  if ans > cnt:
    ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C=list(input())
X=0
Y=0
for i in range(N):
  if C[i]=='W':
    for ii in range(Y, N-i-Y):
      if C[N-1-ii]=='R':
        C[i]='R'
        C[N-1-ii]='W'
        X=X+1
        Y=ii
        break
  if i+Y==N-1:
    break
print(X)

Submission status: Wrong Answer

Solution code:
N = int(input())
C=list(input())
X=0
Y=0
for i in range(N):
  if C[i]=='W':
    for ii in range(Y, N-i-Y):
      if C[N-1-ii]=='R':
        C[i]='R'
        C[N-1-ii]='W'
        X=X+1
        Y=ii
        break
  if i+Y==N-2:
    break
print(X)

Submission status: Wrong Answer

Solution code:
N = int(input())
C=list(input())
X=0
Y=0
print(C)
for i in range(N):
  if C[i]=='W':
    for ii in range(Y, N-i-Y):
      if C[N-1-ii]=='R':
        C[i]='R'
        C[N-1-ii]='W'
        X=X+1
        print(C)
        Y=ii
        break
  if i+Y==N-2:
    break
print(X)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
s = list(input())
left_w = []
right_r = []
for l in s:
    if l == "W":
        left_w.append(1)
    else:
        left_w.append(0)
lacc = list(itertools.accumulate(left_w))
for r in s[::-1]:
    if r == "R":
        right_r.append(1)
    else:
        right_r.append(0)
racc = list(itertools.accumulate(right_r))
racc = racc[::-1]
print(min(map(max, zip(lacc, racc))))

Submission status: Wrong Answer

Solution code:
N = int(input())
C=list(input())
X=0
for i in range(N):
  if C[i]=='W':
    for ii in range(N-1-i):
      if C[ii]=='R':
        C[i]='R'
        C[ii]='w'
        X=X+1
        break
print(X)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 2000000 
for i in range(1,n):
	w = s.count('W',0,i)
	r = s.count('R',i)
	if (max(r,w) < res):
		res = max(r,w)

print(str(res))

Submission status: Wrong Answer

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

cnt = 0
lst = list(s)

for i in range(N-2):
    if s[i:i+2] == 'WR':
        for j in range(i+2,N-1):
            if s[j:j+2] == 'RW':
                lst[i], lst[j] = lst[j], lst[i]
                s = ''.join(lst)
                cnt += 1
                continue

if 'WR' in s:
    for i in range(1, N):
        if s[-i] == 'W':
            cnt += i-1
            break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
r = [0] * n
w = [0] * n
for i in range(n):
  if s[i] == 'W':
    w[i] += 1
  else:
    r[i] += 1
for i in range(1, n):
  w[i] += w[i - 1]
  r[i] += r[i - 1]
rn = r[n - 1]
ans = n
for i in range(n):
  c = (i + 1)
  ri = r[i]
  left = rn - ri
  need = c - ri
  ans = min(ans, max(left, need))  

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
ans = 0
for i in range(n - 1):
  idx = n - 2 - i
  if s[idx] == 'W' and s[idx + 1] == 'R':
    ans += 1
    s[idx] = 'R'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
ans = 0
for i in range(n - 1):
  idx = n - 1 - i
  if s[idx] == 'W' and s[idx + 1] == 'R':
    ans += 1
    s[idx] = 'R'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = 0
for i in range(n - 1):
  if s[i] == 'W' and s[i + 1] == 'R':
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# c = list(input().split())
c = input()
whiteCount = 0

for i in range(math.ceil(n/2)):
    if c[i] == "W":
        whiteCount += 1
print(whiteCount)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
# c = list(input().split())
c = input()
whiteCount = 0
print(c)
for i in range(math.ceil(n/2)):
    if c[i] == "W":
        whiteCount += 1
print(whiteCount)

Submission status: Wrong Answer

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

for i in range(n):
    if c[i]=='W':
        for j in range(n-1,i+1,-1):
            if c[j]=='R':
                c[j]='W'
                count+=1
print(count)

Submission status: Wrong Answer

Solution code:
def solve(n, c):
    num = len(list(filter(lambda _: _=="R", c)))
    w = [0] * n
    w[0] = int(c[0] == "W")
    for i in range(1, n):
        w[i] = w[i-1] + int(c[i] == "W")
    return min(max(w[i], num+w[i]-i-1) for i in range(n))

n = int(input())
c = input()
print(solve(n, c))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('w')
print( s[-w:].count('R') if w != 0 else 0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('W')
print(s[-w:].count('R'))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('W')
an1 = s[-w:].count('R')
an2 = s[:w].count('R')

print(min(an1, an2))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
w = s.count('w')
print(s[-w:].count('R'))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
red_to_white = c.count("R")
ans = red_to_white
while_to_red = 0

for i in c:
    if i == "W":
        while_to_red += 1 
    else:
        red_to_white -= 1
    ans = min(ans,max(while_to_red,red_to_white))
    print(while_to_red)
    print(red_to_white)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
c=c[::-1]
a,b=0,0
ans=0
c=c+'R'
for i in range(N):
  if c[i]=='W':
    a+=1
    if c[i+1]=='R':
      ans+=min(a,b)
      a=0
      b=0
  else:
    b+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    S = [s for s in input()]
    T = S[:]
    # W -> R に書き換え
    mri_r = 0
    for s in S[::-1]:
        if s == "R":
            mri_r += 1
        else:
            break
    ans1 = 0
    for i in range(N):
        if mri_r > 0 and S[i] == "W":
            S[i] = "R"
            S[-mri_r] = "W"
            ans1 += 1
            mri_r -= 1
    r_appear = False
    for s in S[::-1]:
        if r_appear and s == "W":
            # s = "R"
            ans1 += 1
        elif s == "R":
            r_appear = True
    # R -> Wに 書き換え
    mle_w = 0
    for s in T:
        if s == "W":
            mle_w += 1
        else:
            break
    ans2 = 0
    for i in range(N-1, -1, -1):
        if mle_w > 0 and T[i] == "R":
            T[i] = "W"
            T[mle_w-1] = "R"
            ans2 += 1
            mle_w -= 1
    w_appear = False
    for s in T:
        if w_appear and s == "R":
            # s = "W"
            ans2 += 1
        elif s == "W":
            w_appear = True
    print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
cs = input()
r = cs.count("R")
print(cs[:r].count("R"))

Submission status: Wrong Answer

Solution code:
from collections import deque
N= int(input())
state = input()

newlist = sorted(state)
goalstate = "".join(newlist)
# print("goal is " + goalstate)

# action1 is flippingg R(W) 
# action2 is changing position of two ones
# and goal is no left W to all R
# Distinguish if W is left of R
uni = 0
for l in range(len(goalstate)):
    if goalstate[l] == "W":
        uni = l
        break
def bfs(state,goalstate):
    cur_state = deque([state])
    cou = 0
    while cou < 4:
        cur = cur_state.popleft()
        if cur == goalstate:
            return cou
            break
        new= list(cur)
        temp = 0
        for i in range(len(goalstate)):
            if new[i] == "W":
                temp = i
                break
        neow= 0
        for j in range(uni-1,len(goalstate)):
            if new[j] == "R":
                neow = j
                break
        tempstr = new.pop(temp)
        temp1str = new.pop(neow-1)
        new.insert(neow,tempstr)
        new.insert(temp,temp1str)
        nowstr = "".join(new)
        cur_state.append(nowstr)
        cou += 1


goal = bfs(state, goalstate)
print(goal)

Submission status: Wrong Answer

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


def calculate(n, s):
    arr = list(s)
    result = []

    leftW = 0
    rightR = arr.count('R')

    for i in range(n):
        val = arr[i]

        if val == 'R':
            rightR -= 1

        if val == 'W':
            leftW += 1

        result.append(max(leftW,rightR))

    if len(result) == 0:
        print(0)
    else:
        print(min(result))

calculate(N, S)

Submission status: Wrong Answer

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


def calculate(n, s):
    arr = list(s)
    result = []

    leftW = 0
    rightR = arr.count('R')



    for i in range(n):
        val = arr[i]

        if val == 'R':
            rightR -= 1

        if val == 'W':
            leftW += 1

        result.append(max(leftW,rightR))

    if len(result) == 0:
        print(-1)
    else:
        print(min(result))

calculate(N, S)

Submission status: Wrong Answer

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

ans = n
white_to_red = 0
red_to_white = s.count('R')

for i in range(n):
    if s[i] == 'W':
        white_to_red += 1
    else:
        red_to_white -= 1
    ans = min(ans, max(white_to_red, red_to_white))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input())
ans=0
if a[-1]=="R":
    flag=1
else:
    flag=0

prev=""
for i in range(n):
    if a[i]=="W" and flag==1:
        ans+=1
        flag=0
        prev="R"
        a[-1]="W"
    elif a[i]=="R" and prev=="W":
        ans+=1
        prev="W"
    else:
        prev=a[i]
        
print(ans)

Submission status: Wrong Answer

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

R, W = [], []
R_ = []
nR, nW = 0, 0
for c in C:
    if c == 'R':
        nR += 1
    else:
        nW += 1
    R.append(nR)
    W.append(nW)

for r in R:
    R_.append(nR - r)

#print(R)
#print(W)
#print(R_)

ans = N

for i in range(N):
    r, w, r_ = R[i], W[i], R_[i]
    if r_ > w:
        ans = min(r_, ans)
    else:
        ans = min(w, ans)
print(ans)

Submission status: Wrong Answer

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


flag, flag2 = True, False
nW, nR = 0, 0
m = 0
p = 0

for i, c in enumerate(C):
    if flag:
        if c == 'W':
            m += 1
        else:
            flag = False
            flag2 = True
    if flag2:
        if c == 'R':
            p += 1
        else:
            flag2 = False
    
    if c == 'W':
        nW += 1
    else:
        nR += 1

if m == nW:
    print(min(nW, nR))
    exit()

if m >= nR:
    print(nR)
    exit()

print(m + min(nR - m - p, nW))

Submission status: Wrong Answer

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


flag, flag2 = True, False
nW, nR = 0, 0
m = 0
p = 0

for i, c in enumerate(C):
    if flag:
        if c == 'W':
            m += 1
        else:
            flag = False
            flag2 = True
    if flag2:
        if c == 'R':
            p += 1
        else:
            flag2 = False
    
    if c == 'W':
        nW += 1
    else:
        nR += 1

if m >= nR:
    print(nR)
    exit()

print(m + min(nR - m - p, nW))

Submission status: Wrong Answer

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

fixed = True
fixed_count = 0
red_count = 0
white_count = 0

for i in range(N):
    if fixed and stones[i] == 'R':
        fixed_count += 1
    else:
        fixed = False
        if stones[i] == 'R':
            red_count += 1
        else:
            white_count += 1 

target_min = min(red_count, white_count)

print(target_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
wc = c.count("W")
rc = c.count("R")

ans = min(c[rc:].count("R"), c[:wc].count("W"))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
cs = input()
r_num = 0
w_num = 0
# RRRR|WWWW にする 左にR，みぎにWだけの状態にする．
r_num = cs.count('R')

if r_num == 0 or w_num == 0:
    print(0)
else:
    ans = []
    W = 0
    rl_num = 0
    for c in cs:
        if c == 'R':
            rl_num += 1
        elif c == 'W':
            W += 1  # 左にあるWの個数を計数
        R = r_num - rl_num  # みぎにあるRの個数を計数
        ans.append(max(W, R))

    print(min(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
s=input()
arr=[]
for i in s:
	if i =="W":
		arr.append(1)
	else:
		arr.append(0)
h=[]

answer=[1,0]
count=0
for i in range(len(arr)):
	if i == 0:
		h.append(arr[i])
	else:
		h.append(arr[i])
		if h==answer:
			count+=1
			h.pop(0)
			#h[0]=1
		else:
			h.pop(0)
            
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-08-06 00:24:21 +0900
# LastModified: 2020-08-06 00:31:52 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd



def main():
    n = int(input())
    c = input()

    if 'W' in c:
        print(c.count('W')-1)
    else:
        print(0)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

wcount = c.count('R')
count = 0

for i in range(n):
    if c[i] == 'W' and i >= wcount:
        count += 1
print(count)

Submission status: Wrong Answer

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

wcount = c.count('R')
count = 0

for i in range(n):
    if c[i] == 'W' and i<= wcount:
        count += 1
print(count)

Submission status: Wrong Answer

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

wcount = c.count('R')
count = 0

for i in range(n):
    if c[i] == 'W' and i<= wcount:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
ans = 0
for i in range(n-1):
    c1 = S[i]
    c2 = S[i+1]
    if c1 == "W" and c2 == "R":
        ans += 1
        if i > 0 and S[i-1] == "W" and i < n-2 and S[i+2] == "R":
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
for c in list(input()):
  a = 0
  if c == "R":
    a = 1
  C.append(a)
L = -1
R = N
cnt = 0
while L < R:
  L += 1
  if L < R:
    break
  if C[L] != 0:
    continue
  while L < R:
    R -= 1
    if L < R:
      break
    if C[R] != 1:
      continue
    cnt += 1
    break     
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
l,r=0,N-1
ans=0
f=0
while l<r:
  while S[l]=='R':
    l+=1
    if l==N:
      f=1
      break
  while S[r]=='W':
    r-=1
    if r==-1:
      f=1
      break
  if f==1:
    break
  ans+=1
  l,r=l+1,r-1
print(ans)

Submission status: Wrong Answer

Solution code:
X = input()
count_w, n, count = X.count('W'), len(X), 0
for i in range(n - 1, n -1 - count_w, -1):
  count += 1 if X[i] == 'R' else 0
  
print(count)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
N = int(input())
WHITE = 0
RED = 1
str = list(map(str, list(input())))
r = []
w = []

for i in range(N):
  w.append(i) if str[i] == "W" else r.append(i)
  str[i] = WHITE if str[i] == "W" else RED
r.reverse()
if len(r) == 0 or len(w) == 0:
  print("0")
  exit()
r_count = 0
w_count = 0

pivot = N/2
for i in r:
  if i >= pivot: r_count += 1
for i in w:
  if i < pivot: w_count += 1
res = max(r_count, w_count)
print(res)

Submission status: Wrong Answer

Solution code:

N = int(input())
C = [str(i) for i in input().split()]
r = 0
w = 0   
a = 0
r = int(C.count('R'))
for i in range(r):
  if [a] == w:
    b+=1
  a+=1
print(w)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
k=list(input())
if len(set(k))==1:
    print("0")
print(round(math.log2(n)))

Submission status: Wrong Answer

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

cntw=[0]*(n+1)
totr=0
totw=0

for i in range(n):
    if s[i]=='W':
        cntw[i+1]=cntw[i]+1
        totr+=1
    else:
        cntw[i+1]=cntw[i]
        totw+=1
ans=10**6
for i in range(n+1):
    w=cntw[i]
    r=n-i-(totw-cntw[i])
    ans=min(ans,max(w,r))

print(ans)

Submission status: Wrong Answer

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

cntw=[0]*(n+1)
totr=0
totw=0

for i in range(n):
    if s[i]=='W':
        cntw[i+1]=cntw[i]+1
        totr+=1
    else:
        cntw[i+1]=cntw[i]
        totw+=1
ans=10**6
for i in range(n):
    w=cntw[i]
    r=n-i-(totw-cntw[i])
    ans=min(ans,max(w,r))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[c for c in input()]

left=0
right=n-1
ans=0
while left<n and s[left]=='W':
    while left<right and s[right]=='W':
        right-=1
    
    if left==right:
        break

    s[left]='R'
    s[right]='W'
    ans+=1
    left+=1

while left<n and s[left]=='R':
    left+=1

for i in range(left,n-1):
    if s[i]=='W' and s[i+1]=='R':
        s[left]='R'
        s[i+1]='W'
        left+=1
        ans+=1

print(ans)

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mychr = input().rstrip()

result = float('inf')
red = 0
for i in mychr:
    if i == "R":
        red += 1

R = 0
W = 0

for index, i in enumerate(mychr):
    if i == "R":
        R+=1
    else:
        W+=1
    temp = max(W,red-R)
    result = min(result, temp)

print(result)

Submission status: Wrong Answer

Solution code:
num = int(input())
wr = str(input())

r_num = wr.count("R")
i_counts = [r_num]

for i in range(num):
  rw_count = r_num
  wr_count = 0
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

ans = min(i_counts)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R > W:
    for i in range(cnt):
        if list[N-cnt-1]=="R":
            ans +=1

if R<=W:
    for j in range(cnt):
        if list[j] == "W":
            ans +=1


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R >= W:
    for i in range(cnt):
        if list[N-cnt-1]=="R":
            ans +=1

if R<W:
    for j in range(cnt):
        if list[j] == "W":
            ans +=1


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
ans = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

if R >= W:
    for i in range(cnt):
        if list[N-cnt]=="R":
            ans +=1

if R<W:
    for j in range(cnt+1):
        if list[j] == "W":
            ans +=1


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
ans = 0
for i in s[0:n//2]:
    if i == "W":
        ans += 1
if n % 2 != 0:
    if s[0:n//2+1] == "R":
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list=[]
list = (str(input()))
cnt = 0
R = 0
W = 0
for i in range (N):
    if list[i] == "R":
        R += 1

W = N-R

cnt = min(R, W)

for j in range(cnt):
    if list[N-j-1] == "W":
        cnt -=1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
list=[]
list = (str(input()))
cnt = 0

for i in range(N-1):
    if list[i] == 'W':
        for j in range(N-1):
            if list[N-j-1] == 'R' and (N-j-1) > i:
                cnt +=1
                break
ans = cnt
for k in range (cnt-1):
    if list[N-k-1] == 'W':
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
c = 0
tmp = 0
r = 0
for i in range(n-1):
  if s[i] == "W":
    tmp += 1
    if s[i+1] == "R":
      c += tmp
      r += 1
      tmp = 0
print(c - r//2)

Submission status: Wrong Answer

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

r_cnt = C.count('R')
w_cnt = 0
ans = 200000
for i in range(N):
    if C[i] == 'R':
        r_cnt -= 1
    else:
        w_cnt += 1

    if w_cnt <= r_cnt:
        ans = min(ans, r_cnt)
    else:
        ans = min(ans, w_cnt)
print(ans)

Submission status: Wrong Answer

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

W = 0                  #仕切りより左側の白い石の個数
R = C.count('R')       #仕切りより右側の赤い石の個数

ans = max(W, R)

for i in range(N):
    if C[i] == 'W':    #仕切りの左側に'W'が移動する
        W += 1
    else:              #仕切りの左側に'R'が移動する
        R += 1
    ans = min(ans, max(W, R))

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=list(input())
R=c.count('R')
W=0
ans=10**10
for i in range(N):
    if c[i]=='W':
        W+=1
    else:
        R-=1
    ans=min(ans,max(W,R))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

print(C[0:math.ceil(N/2)].count('W'))

Submission status: Wrong Answer

Solution code:
num = int(input())
wr = str(input())


r_num = wr.count("R")
i_counts = [r_num]

for i in range(num):
  rw_count = r_num
  wr_count = 0
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1
  i_count = abs(wr_count - rw_count)
  i_counts.append(i_count)

  ans = min(i_counts)

print(ans)

Submission status: Wrong Answer

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

def solve_fixed(p):
    w_cnt = 0
    r_cnt = 0

    for i in range(p):
        if(c[i] == "W"):
            w_cnt += 1
    
    for j in range(p,n):
        if(c[j] == "R"):
            r_cnt += 1
    
    return (w_cnt,r_cnt)

ans = 10**9
w_cnt,r_cnt = solve_fixed(0)

for i in range(n):
    if(c[i] == "W"):
        w_cnt += 1
    else:
        r_cnt -= 1
    
    tmp = max(w_cnt,r_cnt)
    ans = min(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
wr = str(input())

i_counts = []
r_num = wr.count("R")

for i in range(num):
  rw_count = r_num
  wr_count = 0
  if wr[i] == "W":
    wr_count += 1
  else:
    rw_count -= 1

  i_count = max(wr_count, rw_count)
  i_counts.append(i_count)

  ans = min(i_counts)

print(ans)

Submission status: Wrong Answer

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

cand1 = cs[:cs.count('R')].count('W')
cand2 = cs[cs.count('W'):].count('R')
if cand1 > cand2:
  print(min(cand1, cand2))
else:
  print(max(cand1, cand2))

Submission status: Wrong Answer

Solution code:
#D - Alter Altar /
N = int(input())
C =[]
C = list(map(str,input()))
total = 0
red_C = C[: : -1]
write_ko = len(list(filter(lambda x :x == 'W',C)))
red_ko   = N - write_ko
if red_ko == 0: total += 1
if write_ko > red_ko:
    M = red_ko
    sabun = write_ko - red_ko
else:
    M = write_ko
    sabun = red_ko - write_ko  
#if N % 2 == 1: L = int(N / 2)    
for i in range(M):
    a = C.index('W')
    b = red_C.index('R')
    if (a < N -b ):
        del C[0:a+1]
        del red_C[0:b+1]
        del C[N-b:N]
        del red_C[N-a:N]
        total += 1
        N = N - (a+1) - (b+1)
        if (len(C) < 1 or len(red_C) < 1):
            break
    else:
        break   
# 出力
print(total)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    flag = True
    cnt = 0
    ans = 0
    # RRRRR WWWWWW
    for i in range(N):
        c = C[i]
        if flag:
            if c == "R":
                flag = False
            else:
                cnt += 1
        else:
            if c == "R":
                if cnt > 0:
                    ans += 1
                    cnt -= 1
                else:
                    ans += 1

    if cnt > 0:
        ans += cnt

    # RRRRRRRRRRRR
    # WWWWWWWWWWWWW
    c = Counter(C)
    print(min(ans, c["R"], c["W"]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n  = int(input())
print(input().count('W'))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    flag = True
    ans1 = 0
    # WWWW RRRRR
    for c in C:
        if flag:
            if c == "R":
                flag = False
        else:
            if c == "W":
                ans1 += 1

    c = Counter(C)
    print(min(ans1, c["R"], c["W"]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

r_cnt = 0
for c in C:
    if c == 'R':
        r_cnt += 1

ans = N
r2w = r_cnt
w2r = 0

for c in C:
    if c == 'W':
        w2r += 1
    elif c == 'R':
        r2w -= 1
    ans = min(ans, max(r2w, w2r))
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i] == "R":
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
word = input()
num_R = word.count('R')
num_W,min_count= 0,float('inf')
for i in range(N):
  if word[i] == 'W':
    num_W += 1
  else:
    num_R -= 1
  min_count = min(min_count,max(num_W,num_R))
print(min_count)

Submission status: Wrong Answer

Solution code:
# alter altar
length = int(input())
stone = input()
red = [0] * (length + 1)
white = [0] * (length + 1)
[red_num, white_num] = [0, 0]
for i in range(1, length + 1):
	if(stone[i-1] == "W"):
		white_num += 1
	if(stone[length-i] == "R"):
		red_num += 1
	white[i] = white_num
	red[length - i] = red_num
# print(white)
# print(red)
mini = 200000
for i in range(1, length+1):
	trial = max(white[i], red[i])
	mini = min(mini, trial)
print(mini)

Submission status: Wrong Answer

Solution code:
def q4():
    n = int(input())
    line = input()
    if 'WR' in line:
        r = line.count('R')
        safe = line[0:r-1].count('R')
    else:
        r = 0
        safe = 0
    print(r-safe)

if __name__ == "__main__":
    q4()

Submission status: Wrong Answer

Solution code:
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex < backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

Submission status: Wrong Answer

Solution code:
balls = list(input())

backindex = len(balls) - 1
frontindex = 0
actions = 0

while frontindex != backindex:
  if balls[frontindex] == 'W':
    while backindex > frontindex:
      if balls[backindex] == 'R':
        balls[frontindex] = 'R'
        balls[backindex] = 'W'
        actions += 1
        break
      backindex -= 1
  frontindex += 1

print(actions)

Submission status: Wrong Answer

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

#色を揃えるパターン
#全部赤
ans = 0
right = 0
for i in range(len(c)):
    if i >= (n-right-1):
        break
    if c[i] == "W":
        for j in range(right,len(c)):
            if c[-(j+1)] == "R":
                right = j+1
                ans += 1
                break
print(ans)