Problem:


Score : 400 points

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

N
c_{1}c_{2}...c_{N}

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the 1-st and 3-rd stones from the left, resulting in RWWR.

Change the color of the 4-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3



Sample input:
4
WWRR


Sample output:
2

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
c = list(c)
r = 0
w = 0
for i in range(n):
    if c[i] == 'R':
        r += 1
    else:
        w += 1
ans = min(r,w)
t = 0
for i in range(ans):
    if c[i] == 'R':
        t -= 1
ans = ans + t
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
a = c[0:len(c)//2]
if ("W" not in c) or ("R" not in c):
  print(0)
  exit()

print(c.count("R")-a.count("R"))

Submission status: Wrong Answer

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

w=S.count('W')
print(0 if w==0 or w==len(S) else w-S[:w].count('R'))

Submission status: Wrong Answer

Solution code:
# from collections import defaultdict
# N = int(input())
# c = input()
# d = defaultdict(int)
# for i in range(N):
#     if (c[i] == 'W'):
#         d['W'] += 1
#     else:
#         d['R'] += 1

# if (d['W'] == 0 or d['R'] == 0):
#     print(0)
#     exit()

# len_c = len(c)
# len_c_half = len_c // 2
# count = 0
# if (len_c % 2 == 0):
#     s_left = c[:len_c_half]
#     s_right = c[len_c_half:]
#     count_left_W = s_left.count('W')
#     for i in range(len(s_left) - 1, -1, -1):
#         if (s_right[i] == 'R' and count_left_W != 0):
#             count += 1
#             count_left_W -= 1

#     count_right_


# else:
#     s_left = c[:len_c_half]
#     center = c[len_c_half]
#     s_right = c[len_c_half:]
#     count_left_W = 0
#     count_right_R = 0

#     for i in range(len(s_left)):
#         if s_left[i] == 'W':
#             count_left_W += 1
#         if s_right[i] == 'R':
#             count_right_R += 1
#     while count_right_R > 0 or count_left_W > 0:
#         count += 1
#         count_left_W -= 1
#         count_right_R -= 1
#     if (count_right_R == count_left_W or count_right_R == 0):
#         print(count)
#         exit()

#     else:
#         while count_right_R > 0:
#             count += 1
#             count_right_R -= 1
#     print(count)


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

dp = [0] * (N)

len_c_W = c.count('W')
len_c_R = c.count('R')
cnt_W = 0
cnt_R = 0
for i in range(N):
    if c[i] == 'R':
        cnt_R += 1
    else:
        cnt_W += 1
    count = 0
    if (cnt_W <= (len_c_R - cnt_R)):
        count = len_c_R - cnt_R
    else:
        count = cnt_W

    dp[i] = count
print(min(dp))

Submission status: Wrong Answer

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


def main():
    n = int(input())
    c = input()
    r_count = c.count('R')
    ans = 0

    for ci in c:
        if ci == 'W':
            ans += 1

        r_count -= 1

        if r_count == 0:
            print(ans)
            exit()

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
c = input()
d = defaultdict(int)
for i in range(N):
    if (c[i] == 'W'):
        d['W'] += 1
    else:
        d['R'] += 1

if (d['W'] == 0 or d['R'] == 0):
    print(0)
    exit()

len_c = len(c)
len_c_half = len_c // 2
count = 0
if (len_c % 2 == 0):
    s_left = c[:len_c_half]
    s_right = c[len_c_half:]
    count_left_W = 0
    count_right_R = 0
    for i in range(len(s_left)):
        if s_left[i] == 'W':
            count_left_W += 1
        if s_right[i] == 'R':
            count_right_R += 1
    while count_right_R > 0 or count_left_W > 0:
        count += 1
        count_left_W -= 1
        count_right_R -= 1
    if (count_right_R == count_left_W or count_right_R == 0):
        print(count)
        exit()
    else:
        while count_right_R > 0:
            count += 1
            count_right_R -= 1
    print(count)

else:
    s_left = c[:len_c_half]
    center = c[len_c_half]
    s_right = c[len_c_half:]
    count_left_W = 0
    count_right_R = 0

    for i in range(len(s_left)):
        if s_left[i] == 'W':
            count_left_W += 1
        if s_right[i] == 'R':
            count_right_R += 1
    while count_right_R > 0 or count_left_W > 0:
        count += 1
        count_left_W -= 1
        count_right_R -= 1
    if (count_right_R == count_left_W or count_right_R == 0):
        print(count)
        exit()

    else:
        while count_right_R > 0:
            count += 1
            count_right_R -= 1
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
c = input()
d = defaultdict(int)
for i in range(N):
    if (c[i] == 'W'):
        d['W'] += 1
    else:
        d['R'] += 1

if (d['W'] == 0 or d['R'] == 0):
    print(0)
    exit()

len_c = len(c)
len_c_half = len_c // 2
count = 0
if (len_c % 2 == 0):
    s_left = c[:len_c_half]
    s_right = c[len_c_half:]
    count_left_W = 0
    count_right_R = 0
    for i in range(len(s_left)):
        if s_left[i] == 'W':
            count_left_W += 1
        if s_right[i] == 'R':
            count_right_R += 1
    while count_right_R > 0 or count_left_W > 0:
        count += 1
        count_left_W -= 1
        count_right_R -= 1
    if (count_right_R == count_left_W or count_right_R == 0):
        print(count)
        exit()
    else:
        while count_right_R > 0:
            count += 1
            count_right_R -= 1
    print(count)

else:
    s_left = c[:len_c_half]
    center = c[len_c_half]
    s_right = c[len_c_half:]
    count_left_W = 0
    count_right_R = 0

    for i in range(len(s_left)):
        if s_left[i] == 'W':
            count_left_W += 1
        if s_right[i] == 'R':
            count_right_R += 1
    while count_right_R > 0 or count_left_W > 0:
        count += 1
        count_left_W -= 1
        count_right_R -= 1
    if (count_right_R == count_left_W or count_right_R == 0):
        if (center == 'W'):
            print(count)
            exit()
        else:
            print(count + 1)
            exit()
    else:
        while count_right_R > 0:
            count += 1
            count_right_R -= 1

    if (center == 'W'):
        print(count)
    else:
        print(count + 1)

Submission status: Wrong Answer

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

ans = 0

W_left = 0
R_right = 0
for i in range(n):
    if arr[i] == 'R':
        R_right += 1

ans = []
for i in range(n):
    if arr[i] == 'W':
        W_left += 1
    elif arr[i] == 'R':
        R_right -= 1
    ans.append(max(W_left,R_right))
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
C = []
for c_i in c:
    C.append(c_i)
count = 0
left = N
for i in range(N):
    if i >= left:
        print(count)
        break
    if C[i] == 'W':
        for j in reversed(range(left)):
            if i == 1:
                if j == i:
                    C[i] = 'R'
                    left = i
                    break
            else:
                if j == i-1:
                    left = i
                    break
            if C[j] == 'R':
                C[i] = 'R'
                C[j] = 'W'
                left = j
                count += 1
                break

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().strip()
R=s.count('R')
t=0
for i in range(R):
    if s[i]=='W':
        t=t+1
u=R-(n-R-t)
f=max(t,u)
if R==0 or R==n or t==R:
    f=0
print(f)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input().strip()
R=s.count('R')
t=0
for i in range(R):
    if s[i]=='W':
        t=t+1
u=R-(n-R-t)
f=max(t,u)
if R==0 or R==n:
    f=0
print(f)

Submission status: Wrong Answer

Solution code:
def dist(s, r):
  wcount = 0
  for i in range(r):
    wcount += (s[i] == "W")
  rcount = 0
  for i in range(r, n):
    rcount += (s[i] == "R")
  return max(wcount, rcount)

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

minstep = n
for i in range(n):
  minstep = min(dist(s, i), minstep)

print(minstep)

Submission status: Wrong Answer

Solution code:
#D - Alter Altar /
N = int(input())
C =[]
C = list(map(str,input()))
total = 0

write_ko = len(list(filter(lambda x :x == 'W',C)))
red_ko   = N - write_ko
    
for i in range(N):
    for j in range(N-1,1,-1):
        if (C[i] == 'W') and (C[j] == 'R'):
            if (i < j):
                C[i] = 'G'
                C[j] = 'B'
                total += 1   
# 出力
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
f=0
f2=0
wcnt=0
wcnt2=0
rcnt=0
cnt=0
for i in range(n):
    if f and c[i]=="R":
        cnt+=1
    if c[i]=="R":
        f=1
        rcnt+=1
    if c[i]=="W":
        wcnt2+=1
    if f==0 and c[i]=="W":
        wcnt+=1
ans=[rcnt,wcnt2]
if cnt>=wcnt:
    ans.append(cnt)
print(min(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
"""
RWとなってなければおｋ
WRはだめ
"""


def main():
    import sys

    input = sys.stdin.readline

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

    white, red = 0, c.count('R')
    ans = N
    for i in range(N):
        if c[i] == 'W':
            white += 1
        else:
            red -= 1
        res = max(white, red)
        ans = min(ans, res)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
c=input()
d=Counter(c)
wn,rn=Counter(c)["W"], Counter(c)["R"]

MIN=min(wn,rn)
ans={200001}

for i in range(MIN):
  w=Counter(c[:i])["W"]
  r=rn-(i-w)
  if w<=r:
    ans.add(r)
  else:
    ans.add(w)

if ans:
  print(min(ans))
else:
  print(0)

Submission status: Wrong Answer

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

w = [0]*(n+1)
r = [0]*(n+1)
for i in range(0,n):
  w[i+1] = w[i]
  r[n-i-1] = r[n-i]
  if c[i]=='W':
    w[i+1] += 1
  if c[n-i-1]=='R':
    r[n-i-1] += 1

print([w[i]+r[i]-min(w[i],r[i]) for i in range(0,n+1)])

Submission status: Wrong Answer

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
S = input()
allR = 0
for c in S:
    allR += c == 'R'

if allR == 0 or allR == N:
    print(0)
else:
    idx = S.find("R")
    if idx <= allR-1:
        print(allR-1)
    else:
        print(allR)

Submission status: Wrong Answer

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

Nw, Nr = 0, 0
for i in range(len(c)):
    Nw += 1 if c[i] == "W" else 0
    Nr += 1 if c[i] == "R" else 0

left_w = 0
right_r = 0
if c[0] == "W":
    left_w = 1
    right_r = Nr
else:
    left_w = 0
    right_r = Nr - 1

#仕切りの位置をiの横とすると
ans = max(left_w, right_r)
if ans == 0:
    print(0)
    exit()
for i in range(len(c)):
    if i > 0:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1
    swap = max(left_w, right_r)
    ans = min(swap, ans)
print(ans)

Submission status: Wrong Answer

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

Nw, Nr = 0, 0
for i in range(len(c)):
    Nw += 1 if c[i] == "W" else 0
    Nr += 1 if c[i] == "R" else 0

left_w = 0
right_r = 0
if c[0] == "W":
    left_w = 1
    right_r = Nr
else:
    left_w = 0
    right_r = Nr - 1

#仕切りの位置をiの横とすると
ans = max(left_w, right_r)
for i in range(len(c)):
    if i > 0:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1
    swap = max(left_w, right_r)
    ans = min(swap, ans)
print(ans)

Submission status: Wrong Answer

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

Nw, Nr = 0, 0
for i in range(len(c)):
    Nw += 1 if c[i] == "W" else 0
    Nr += 1 if c[i] == "R" else 0

left_w = 0
right_r = 0
if c[0] == "W":
    left_w = 1
    right_r = Nr
else:
    left_w = 0
    right_r = Nr - 1

#仕切りの位置をiの横とすると
ans = N
for i in range(len(c)):
    if i > 0:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1
    swap = max(left_w, right_r)
    ans = min(swap, ans)
print(ans)

Submission status: Wrong Answer

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

Nw, Nr = 0, 0
for i in range(len(c)):
    Nw += 1 if c[i] == "W" else 0
    Nr += 1 if c[i] == "R" else 0

left_w = 0
right_r = 0
if c[0] == "W":
    left_w = 1
    right_r = Nr
else:
    left_w = 0
    right_r = Nr - 1

#仕切りの位置をiの横とすると
ans = float("inf")
for i in range(len(c)):
    if i > 0:
        if c[i] == "W":
            left_w += 1
        else:
            right_r -= 1
    swap = max(left_w, right_r)
    ans = min(swap, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

c = list(input())

leftmost_w = None
rightmost_r = None
left = 0
right = N-1

counter = 0
while left < right:

    if c[left] == "W" and leftmost_w is None:
        leftmost_w = left
        continue

    if c[right] == "R" and rightmost_r is None:
        rightmost_r = right
        continue

    if leftmost_w is not None and rightmost_r is not None:
        c[leftmost_w], c[rightmost_r] = c[rightmost_r], c[leftmost_w]
        counter += 1
        leftmost_w, rightmost_r = None, None
        continue

    left += 1
    right -= 1

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
RL, WL = [0 for _ in range(N+1)], [0 for _ in range(N+1)]

for i in range(N):
  RL[i+1] = RL[i] + (S[i] == 'R')
  WL[i+1] = WL[i] + (S[i] == 'W')
mcnt = int(1e13) + 13
for i in range(N, 0, -1):
  if S[i-1] == 'R':
    mcnt = min(mcnt, RL[N] - RL[i] + max(0, WL[i-1] - RL[N] + RL[i]))
print(mcnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
w = 0
r = c.count('R')
ans = n
for i in c:
    if i == 'W': w += 1
    else: r -= 1
    ans = min(ans, max(w, r))
print(min(ans, c.count('W')))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
w = 0
r = c.count('R')
ans = n
for i in c:
    if i == 'W': w += 1
    else: r -= 1
    ans = min(ans, max(w, r))
print(ans)

Submission status: Wrong Answer

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

ans=0
i,j=0,N-2
while i<j:
    if s[i]=='R':
        i+=1
    elif s[j]=='W':
        j-=1
    else:
        ans+=1
        i+=1
        j-=1

print(ans)

Submission status: Wrong Answer

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

times = len(s)
R, L = 0, s.count("R")
for c in s:
    if c == "W":
        R += 1
    else:
        L -= 1
    if times > max(R, L):
        times = max(R, L)
print(times)

Submission status: Wrong Answer

Solution code:
from collections import deque

N = int(input())
C = deque(input())

ans = 0
while len(C)>1:
  a,b = C.popleft(), C.popleft()
  if b=="R" and a=="W":
    C.appendleft("W")
    ans += 1
  C.appendleft(b)

print(ans)

Submission status: Wrong Answer

Solution code:
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 4
# S = "WWRR"

N = int(input())
S = input()

# N = 2
# S = "WW"

def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        if (leftW == 0) and arr[i] == "R":
            result.append(0)
            continue

        if (rightR == 0) and arr[i] == "W":
            result.append(0)
            continue

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Submission status: Wrong Answer

Solution code:
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 4
# S = "WWRR"

N = int(input())
S = input()

# N = 2
# S = "WW"

def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        if leftW == 0 or rightR == 0:
            result.append(0)
            continue

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Submission status: Wrong Answer

Solution code:
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 4
# S = "WWRR"

N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Submission status: Wrong Answer

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

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer)

Submission status: Wrong Answer

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

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer+count)

Submission status: Wrong Answer

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

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break
answer = i-1
count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(answer-1 + count)

Submission status: Wrong Answer

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

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break

count = 0
for i in range(pre_left+1, pre_right):
    if c[i] == "W":
        count+=1
    else:
        count-=1

print(i-1 + count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = input()
ans = 0
for i in s:
	if i=="R":
		ans+=1

for i in range(0,ans):
	if i=="R":
		ans-=1

print(ans)

Submission status: Wrong Answer

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

count = 0
rui_red = [0 for _ in range(N)]
rui_white = [0 for _ in range(N)]
now_red = 0
now_white = 0
for i in range(N):
    if c[i] == "W":
        now_white += 1
        rui_white[i] = now_white
    if c[-1-i] == "R":
        now_red += 1
        rui_red[-1-i] = now_red

left = 0
right = N-1
for i in range(N):
    pre_left = left
    pre_right = right
    
    while rui_white[left] < i:
        left += 1
        if  left >= N:
             break
    while rui_red[right] < i:
        right -= 1
        if right < 0:
            break
    
    if left>=right:
        break

print(i-1 + pre_right-pre_left-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())#ciが R のとき赤、W のとき白
count = n
a = 0
b = 0
# a: R->W, b: W->Rの回数
for i in range(n+1):
  if i == 0:
    a = c.count("R")
    ans = max(a, b)
    count = min(ans, count)
  else:
    a = a - c[0:i-1].count("R")
    b = b + c[0:i-1].count("W")
    ans = max(a, b)
    count = min(ans, count)
print(count)

Submission status: Wrong Answer

Solution code:
n = input()
m = input()
wcount = 0    
rcount = 0
min_move = len(m)
for i in range(len(m)):
    max_w = m.count("W",0,i)
    max_r = m.count("R",i,len(m))
    if max(max_r,max_w) < min_move:
        min_move = max(max_w,max_r)

print(min_move)

Submission status: Wrong Answer

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

w = 0
r = sum(1 for i, c in enumerate(cn) if cn[i] == 'R')
mn = 10**9
for i, c in enumerate(cn, 1):
    if c == 'W':
        w += 1
    if c == 'R':
        r -= 1

    m = max(r, w)
    mn = min(mn, m)

print(mn)

Submission status: Wrong Answer

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

w_total = sum(1 for i, c in enumerate(cn) if cn[i] == 'W')
w = 0
mn = 10**9
for i, c in enumerate(cn, 1):
    if c == 'W':
        w += 1
    r = (len(cn) - i) - (w_total - w)
    m = max(r, w)
    mn = min(mn, m)

print(mn)

Submission status: Wrong Answer

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

rc=c.count('R')
mini=min(rc,n-rc)
for i in range(n):
  if c[i]=='R':
    rc-=1
  
  mini=min(mini,max(rc,n-rc))
  
print(mini)

Submission status: Wrong Answer

Solution code:

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

nowL = 0 # 今見てる左側の位置
nowR = n-1 # 今見てる右側の位置
ans = 0 # swapした回数

while(True):
    print(nowL,nowR)
    while(nowL < n-1):
        # 左側で、右に移動しながら次のWを探す
        if(s[nowL]=='W'):
            break
        else:
            nowL+=1
    while(nowR > 0):
        # 右側で、次のRを探す
        if(s[nowR]=='R'):
            break
        else:
            nowR-=1
    if(nowR <= nowL):
        #見てる位置がぶつかったら探索終了
        break
    
    nowL+=1
    nowR-=1
    ans+=1
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
# !/usr/bin/python3

"""
https://atcoder.jp/contests/abc174/tasks/abc174_d
Alter Alter.
"""

def solve(a, n):
    count = 0

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

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

    print(solve(a, n))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
ans = 0
n_w = c.count('W')
for i in range(len(c)-1, n_w-1, -1):
    if c[i]=='R': ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
n_w = c.count('W')
n_r = c.count('R')

print(max(n_r, n_w))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
n = len(c)//2
ans = max(c.count('W',0,n), c.count('R',n,n*2))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
l = 0
r = n - 1
ans = 0
while l < r:
    while l < r and s[l] == 'R':
        l += 1
    while l < r and s[r] == 'W':
        r -= 1
    ans += 1
    l += 1
    r -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import io, sys
from collections import deque

def main():
    N = int( sys.stdin.readline() )
    stones = sys.stdin.readline().rstrip()
    stones = list(stones)
    cnt = 0

    while True:
        W_replace, R_replace = search(stones)

        if W_replace and R_replace and (W_replace[0] < R_replace[-1]):
            stones,cnt = replace(stones, W_replace, R_replace, cnt)
        
        else:
            break
    
    
    W_replace, R_replace = search(stones)
    cnt += len(R_replace)
    print(cnt)


def search(stones):
    W_replace = []  # index of the candidate for replace
    R_replace = []  # index of the candidate for replace

    for i in range(len(stones)):
        if stones[i] == "W":
            if (i == 0) or (i != 0  and  stones[i-1] == "R"):
                W_replace.append(i)
        
        if stones[i] == "R":
            if (i != 0  and  stones[i-1] == "W"):
                R_replace.append(i)
    
    return (W_replace , R_replace)


def replace(stones, W_replace, R_replace, cnt):
    dq_W = deque(W_replace)
    dq_R = deque(R_replace)

    while dq_W and dq_R:
        idx_W = dq_W.popleft()
        idx_R = dq_R.pop()

        if idx_W == idx_R:
            dq_W.appendleft(idx_W)
            continue
        
        elif idx_W < idx_R:
            stones[idx_W],stones[idx_R] = stones[idx_R],stones[idx_W]
            cnt += 1
        
        if idx_W > idx_R:
            break
    
    
    return (stones, cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
t = sum(c == 'R' for c in C)
print(sum(c == 'W' for c in C[:n-t]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n = int(input())
    a = list(input())

    if not 'WR' in a:
        print(0)
        sys.exit()
    r = 0
    rnum = a.count('R')
    while True:
        if 'W' in a[:rnum]:
            t1 = a[:rnum].index('W')
            t2 = a[rnum:].index('R')
            a[t1] = 'R'
            a[t2+rnum] = 'W'
            r += 1
        else:
            break
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
t = sum(c == 'R' for c in C)
print(sum(c == 'R' for c in C[:t]))

Submission status: Wrong Answer

Solution code:
def prob_D():
    N = int(input())
    stones = list(input())

    start = 0
    end = len(stones) - 1

    count = 0

    while start <= end:
        white, red = None, None

        for i in range(end + 1):
            if stones[i] == 'W':
                white = i
                break

        for i in range(end, start, -1):
            print(start, end, i)
            if stones[i] == 'R':
                red = i
                break

        if red is not None and white is not None and white < red:
            stones[red], stones[white] = stones[white], stones[red]
            count += 1

        start += 1
        end -= 1

    print(count)


def main():
    prob_D()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
    n = int(input())
    a = list(input())

    if not 'WR' in a:
        print(0)
        sys.exit()
    r = 0
    rnum = a.count('R')
    while True:
        if 'W' in a[:rnum]:
            t1 = a[:rnum].index('W')
            t2 = a[rnum:].index('R')
            a[t1] = 'R'
            a[t2+rnum] = 'W'
            r += 1
        else:
            break
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
m = input()
runlength = []
count = 1
for i in range(len(m)):
    if i == n-1:
        runlength.append([m[i],count])
        break
    if m[i] ==  m[i+1]:
        count += 1
    elif m[i] != m[i+1]:
        runlength.append([m[i],count])
        count = 1


count = 0


for i,j in runlength:
    if i == "W":
        count += j

count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
c = input()

#方針は、全て同じ色にする or 左側にR右側にW
cnt = collections.Counter(c)
w_cnt = cnt['W']
r_cnt = cnt['R']
w_right_cnt = w_cnt
r_right_cnt = r_cnt
w_left_cnt = 0
r_left_cnt = 0
ans = n
for i in range(n):
    #仕切りの両側のWとRの数を数える
    if c[i] == 'W':
        w_left_cnt += 1
        w_right_cnt -= 1
    if c[i] == 'R':
        r_left_cnt += 1
        r_right_cnt -= 1
    #解説PDFの・が2つの部分を調べる
    if w_left_cnt <= r_right_cnt:
        ans = min(r_right_cnt, ans)
    elif w_left_cnt > r_right_cnt:
        ans = min(w_left_cnt, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
c = input()

#方針は、全て同じ色にする or 左側にR右側にW
cnt = collections.Counter(c)
w_cnt = cnt['W']
r_cnt = cnt['R']
w_right_cnt = w_cnt
r_right_cnt = r_cnt
w_left_cnt = 0
r_left_cnt = 0
ans = n + 1
for i in range(n):
    #仕切りの両側のWとRの数を数える
    if c[i] == 'W':
        w_left_cnt += 1
        w_right_cnt -= 1
    if c[i] == 'R':
        r_left_cnt += 1
        r_right_cnt -= 1
    #解説PDFの・が2つの部分を調べる
    if w_left_cnt <= r_right_cnt:
        ans = min(r_right_cnt, ans)
    elif w_left_cnt > r_right_cnt:
        ans = min(w_left_cnt, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
countW = S.count('W')
if countW==0:
	print(0)
	exit()
if countW==N:
	print(0)
	exit()
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
countW = S.count('W')
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
c = list(input())
pos_w=0
pos_r=n-1
count = 0
for i in range(pos_w, n):
  if c[i] != 'W':
    continue
  pos_w = i
  for j in range(pos_r, -1, -1):
    if c[j] != 'R':
      continue
    pos_r = j
    if pos_w > pos_r:
      print(count)
      sys.exit()
    c[i] = 'R'
    c[j] = 'W'
    count += 1
    break

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
n2 = n//2
c = input()
 
if c.count("R") == n:
    print(0)
elif c.count("W") == n:
    print(0)
elif n%2 == 0:
    cnt = c.count("R", n2, n)
    print(cnt)
else:
    cnt = c.count("R", n2+1, n)
    print(cnt)