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:
if __name__ == '__main__':
    N = int(input())
    C = list(input())
    C.sort()
    cnt = 0
    red_cnt = 0
    for c in C:
        if c == 'R':
            red_cnt += 1
        else:
            break
    for i in range(N):
        if C[i] == 'W':
            for j in range(red_cnt, N):
                if C[j] == 'R':
                    C[i] = 'R'
                    C[j] = 'W'
                    cnt += 1
                    red_cnt = j+1
    print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

stone = input()
s = list(stone)
score = 0

if 'W' not  in stone:
    print(0)
    exit()
else:
    for i in range (n-1):
        if (s[i] == "W") and (s[i+1] == "R"):
            s[i], s[i+1] = s[i+1], s[i]
            score += 1
    print(score)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input().rstrip())

left_cur = 0
right_cur = n - 1
ans = 0
flag = False
while(left_cur < right_cur and left_cur < n - 1 and right_cur > 0):
    while(s[left_cur] == 'R'):
        left_cur += 1
        if (left_cur == n - 1):
            flag = True
            break
    while(s[right_cur] == 'W'):
        right_cur -= 1
        if (right_cur == 0):
            flag = True
            break
    if(flag):
        break
    ans += 1
    left_cur += 1
    right_cur -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
def abc174d():
    n = int(input())
    s = input()
    cnt = s.count('R')
    if cnt == len(s):
        print(0)
        return
    start = 0
    while s[start] == 'R':
        start += 1
        cnt -= 1
    ans = cnt
    for i in range(start, cnt):
        if s[i] == 'R':
            ans -= 1
    print(ans)
abc174d()

Submission status: Wrong Answer

Solution code:
n=(int)(input())
a=input().split()
sum_red=0
for i in a:
  if i=="R":
    sum_red+=1
    
sum=0
for i in range(sum_red):
  if a[i]=="W":
    sum+=1
    
print(sum)

Submission status: Wrong Answer

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

print(min(cl[:n//2].count('W'), cl.count('W'), cl.count('R')))

Submission status: Wrong Answer

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

ans = cl[:n//2].count('W')
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
w = 0
r = c.count("R")
ans = n
for i in range(n) :
    if c[i] == "W" :
        w += 1
    else :
        r -= 1
    if ans > max(w,r) :
        ans = max(w,r)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
w = 0
r = c.count("R")
ans = n
for i in range(n) :
    if c[i] == "W" :
        w += 1
    else :
        r -= 1
    if ans >= max(w,r) :
        ans = max(w,r)

print(ans)

Submission status: Wrong Answer

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

r = 0
cnt = 0
for i in range(n):
    if c[i] == "R" :
        r += 1
    else :
        cnt = i
        break

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

Submission status: Wrong Answer

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

mid = N // 2

left = 0
right = 0
if N % 2 == 1:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid+1, N):
        if c[i] == "R":
            right += 1
    ans = max(left, right) 
    if c[mid] == "R" and c[mid-1] == "W":
        ans += 1
    if min(left,right) == 0:
        ans = 0
else:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid, N):
        if c[i] == "R":
            right += 1
    ans = max(left, right)
    if min(left,right) == 0:
        ans = 0
print(ans)

Submission status: Wrong Answer

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

mid = N // 2

left = 0
right = 0
if N % 2 == 1:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid+1, N):
        if c[i] == "R":
            right += 1
    ans = min(left, right) + abs(left-right)
    if c[mid] == "R" and c[mid-1] == "W":
        ans += 1
else:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid, N):
        if c[i] == "R":
            right += 1
    ans = min(left, right) + abs(left-right)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
    print(res)
else:
    i, j = 0, len(s)-1
    while i<=j:
        while i <= j and s[i] != 'W': i+=1
        while i <= j and s[j] != 'R':j -= 1
        if s[i] == 'W' and s[j] == 'R':
            res += 1
            i += 1
            j -= 1
    if s.find('WR') != -1:res += 1
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
res = 0
tem = s.find('WR')
if tem == -1:
    print(res)
else:
    i, j = 0, len(s)-1
    while i<=j:
        while i <= j and s[i] != 'W': i+=1
        while i <= j and s[j] != 'R':j -= 1
        if s[i] == 'W' and s[j] == 'R':
            res += 1
            i += 1
            j -= 1
    print(res)

Submission status: Wrong Answer

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

mid = N // 2

left = 0
right = 0
if N % 2 == 1:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid+1, N):
        if c[i] == "R":
            right += 1
    ans = min(left, right)
    if c[mid] == "R" and c[mid-1] == "W":
        ans += 1
else:
    for i in range(mid):
        if c[i] == "W":
            left += 1
    for i in range(mid, N):
        if c[i] == "R":
            right += 1
    ans = min(left, right)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0 or cou_r == n or n == 1 or cou_r == n - 1:
        return ans
    else:
        for i in range(cou_r):
            if r_lst[i] - ans - i >= cou_r - ans - i:
                ans += cou_r - ans - i
                return ans
            else:
                ans += r_lst[i]
        return ans

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0 or cou_r == n or n == 1:
        return ans
    else:
        for i in range(cou_r):
            if r_lst[i] - ans - i >= cou_r - ans - i:
                ans += cou_r - ans - i
                return ans
            else:
                ans += r_lst[i]
        return ans

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0 or cou_r == n or n == 1:
        return ans
    else:
        for i in range(cou_r):
            if r_lst[i] - ans - i >= cou_r - ans - i:
                ans += cou_r - ans - i
                return ans
            else:
                ans += r_lst[i]

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0 or cou_r == n:
        return ans
    else:
        for i in range(cou_r):
            if r_lst[i] - ans - i >= cou_r - ans - i:
                ans += cou_r - ans - i
                return ans
            else:
                ans += r_lst[i]

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0 or n == 1:
        return ans
    else:
        for i in range(cou_r):
            if r_lst[i] - ans - i >= cou_r - ans - i:
                ans += cou_r - ans - i
                return ans
            else:
                ans += r_lst[i]

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0:
        return ans
    dld = 0
    for i in range(cou_r):
        cou_w = r_lst[i] - dld
        if cou_w >= cou_r - 1:
            ans += cou_w
            return ans
        else:
            cou_r -= 1 + r_lst[i]
            dld += cou_w + 1
            ans += cou_w
    return ans

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
def R_W(val: str, n: int) -> int:
    r_lst = []
    for i in range(n):
        if val[i] == 'R':
            r_lst.append(i)
    cou_r = len(r_lst)
    ans = 0
    if cou_r == 0:
        return ans
    dld = 0
    for i in range(cou_r):
        cou_w = r_lst[i] - dld
        if cou_w >= cou_r - 1:
            ans += cou_w
            return ans
        else:
            cou_r -= 1 + r_lst[i]
            dld += cou_w + 1
            ans += cou_w

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

print(R_W(c, n))

Submission status: Wrong Answer

Solution code:
n = int(input())
li_c = input()
r_index = [i for i,x in enumerate(li_c) if x=="R"]
w_index = [i for i,x in enumerate(li_c) if x=="W"]
r_num = len(r_index)

R = r_num - len([r for r in r_index if r<1])
W = 1-len([r for r in r_index if r<1])
ans = max(R, W)
for i in range(1, n):
    if li_c[i]=="R":
        R -= 1
    else:
        W += 1
    ans = min(ans, max(R, W))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
w = 0
r = N-1
ans = 0
while w < r:
    f = 0
    for i in range(w,r+1):
        if c[i] == "W":
            w = i+1
            f += 1
            ans += 1
            break
    else:
        break
    for j in range(r,w-1,-1):
        if c[j] == "R":
            r = j-1
            if f == 0:
                ans += 1
            break
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = list(input())

count_red = s.count('R')
count_white = 0

A = []
for i in range(n):
    if s[i] == 'R':
        count_red -= 1
    if s[i] == 'W':
        count_white += 1
    A.append(max(count_red, count_white))
print(min(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
count = list()
W = 0
R = 0
for i in C:
    if i == "R":
        R += 1

for i in C:
    if i == "W":
        W += 1
    else:
        R -= 1

    if W <= R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

Submission status: Wrong Answer

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

for i in range(N):
    W = 0
    R = 0
    for j in range(0,int(N/2+1)):
        if C[j] == 'W':
            W += 1
    for j in range(int(N/2+1),N):
        if C[j] == 'R':
            R += 1
    if W > R:
        count.append(R)
    else:
        count.append(W)

print(min(count))

Submission status: Wrong Answer

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

w = C.count("W")
ans = min(w, N-w)

left = 0
right = N-1
while C[left] != "W" and left < N-1:
    left += 1
while C[right] != "R" and 1 <= right:
    right -= 1

m = 0
while left < right:
    while C[left] != "W" and left < N-1:
        left += 1
    while C[right] != "R" and 1 <= right:
        right -= 1
    m += 1
    left += 1
    right -= 1

print(min(ans, m))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2+1)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W > R:
    print(W)
else:
    print(R)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2+1)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W >= R:
    print(R)
else:
    print(W)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
lW = 0
rW = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        lW += 1
for i in range(int(N/2),N):
    if C[i] == 'W':
        rW += 1
if lW>=rW:
    print(lW)
else:
    print(rW-lW)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2),N):
    if C[i] == 'R':
        R += 1
if W>=R:
    print(R)
else:
    print(W)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(0,int(N/2)):
    if C[i] == 'W':
        W += 1
    print(C[i])
print("-------------")
for i in range(int(N/2),N):
    if C[i] == 'R':
        R += 1
    print(C[i])
if W>=R:
    print(R)
else:
    print(W)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = int(stdin.readline())
c = stdin.readline()[:-1]

red = c.count("R")
ans = red
numwhite = 0
for i in range(n):
    numwhite += 1 if c[i] == "W" else 0
    numred = i - numwhite + 1
    resred = red - numred
    ans = min(ans,min(resred,numwhite))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

j = n
ans = 0
for i in range(0,n):
  if wr[i] == 'W':
    while j>=1:
      j-=1
      if wr[j] == 'R':
        ans+=1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
wr = input()

j = len(wr)
ans = 0
for i in range(0,len(wr)):
  if wr[i] == 'W':
    while j>=1:
      j-=1
      if wr[j] == 'R':
        ans+=1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
wr = input()

j = len(wr)-1
ans = 0
for i in range(0,len(wr)):
  if wr[i] == 'W':
    while j>=1:
      if wr[j] == 'R':
        ans+=1
        break
      j-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
wr = input()

j = len(wr)-1
ans = 0
for i in range(0,len(wr)):
  if wr[i] == 'W':
    while True:
      if wr[j] == 'R':
        ans+=1
        break
      else:
        if j>0:
          j-=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(int(N/2)):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2),N):
    if C[i] == 'R':
        R += 1
if W>=R:
    print(R)
else:
    print(W)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
W = 0
R = 0
for i in range(int(N/2)+1):
    if C[i] == 'W':
        W += 1
for i in range(int(N/2+1),N):
    if C[i] == 'R':
        R += 1
if W>R:
    print(R)
else:
    print(W)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
W_all = c.count("W")
R_all = c.count("R")
W_0 = c[0 : 0].count("W")
R_0 = c[0 : n].count("R")

tmp = n
W = W_0
R = R_0
for i in range(n):
    #print(W, R)
    if c[i] == "W":
        W += 1
        R = R
    elif c[i] == "R":
        W = W
        R -= 1

    if tmp >= max([W ,R]):
        tmp = max([W, R])

print(tmp)

Submission status: Wrong Answer

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

if "R" not in C:
    print(n)
    exit()

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

for c in C:
    if c == "W":
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
print(ans)

Submission status: Wrong Answer

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

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

for c in C:
    if c == "W":
        w += 1
    else:
        r -= 1
    ans = min(ans, max(w, r))
print(ans)

Submission status: Wrong Answer

Solution code:
# Nとcの定義
N = int(input())
C = input()

# 赤色の個数
red_num = str.count(C, "R")

# 左からred_num個までに含まれる白色の個数
white_num_left = str.count(C[:red_num], "W")

# 最小の操作回数
min_ope = white_num_left

# 最小の操作回数の出力
print("最小の操作回数: " + str(min_ope))

Submission status: Wrong Answer

Solution code:
# Nとcの定義
N = int(input())
C = input()

# 赤色の個数
red_num = str.count(C, "R")

# 左からred_num個までに含まれる白色の個数
white_num_left = len(C[red_num:])

# 最小の操作回数
min_ope = white_num_left

# 最小の操作回数の出力
print("最小の操作回数: " + str(min_ope))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
    if i+1<=len(c)/2 and c[i]=='R':
        hrcnt += 1
wcnt = len(c)-rcnt
if rcnt==len(c) or rcnt==0:
    ans = 0
else:
    ans = rcnt-hrcnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
    if i+1<=len(c)/2 and c[i]=='R':
        hrcnt += 1
wcnt = len(c)-rcnt
if rcnt==len(c) or rcnt==0:
    ans = 0
elif rcnt<wcnt:
    ans = rcnt
elif rcnt>wcnt:
    ans = len(c)-rcnt
else:
    ans = rcnt-hrcnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
hrcnt = 0
rcnt = 0
for i in range(len(c)):
    if c[i]=='R':
        rcnt += 1
    if i+1<=len(c)/2 and c[i]=='R':
        hrcnt += 1
if rcnt==len(c) or rcnt==0:
    ans = 0
elif rcnt<len(c)/2:
    ans = rcnt
elif rcnt>len(c)/2:
    ans = len(c)-rcnt
else:
    ans = rcnt-hrcnt

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    C = input()
    sum_r, sum_w = 0, 0
    for c in C:
        if c == 'R':
            sum_r += 1
    ans = 10000000
    if sum_r == 0 or sum_r == n:
        print(0)
        sys.exit()
    for i in range(n-1):
        if C[i] == 'W':
            sum_w += 1
        else:
            sum_r -= 1
        if C[i:i+2] == "WR":
            ans = min(ans, max(sum_w, sum_r))
    else:
        print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    C = input()
    sum_r, sum_w = 0, 0
    for c in C:
        if c == 'R':
            sum_r += 1
    ans = 10000000
    for i in range(n-1):
        if C[i] == 'W':
            sum_w += 1
        else:
            sum_r -= 1
        if C[i:i+2] == "WR":
            ans = min(ans, max(sum_w, sum_r))
    if sum_r*sum_w == 0:
        print(0)
    else:
        print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    C = input()
    sum_r, sum_w = 0, 0
    for c in C:
        if c == 'R':
            sum_r += 1
    ans = 10000000
    for i in range(n-1):
        if C[i] == 'W':
            sum_w += 1
        else:
            sum_r -= 1
        if C[i:i+2] == "WR":
            ans = min(ans, max(sum_w, sum_r))
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    C = input()
    cunt_left, cunt_right = 0, 0
    cunt_r, cunt_w = 0, 0
    if n % 2 == 0:
        for i in range(n//2):
            if C[i] == 'W':
                cunt_left += 1
                cunt_w += 1
            else:
                cunt_r += 1
        for i in range(n//2,n):
            if C[i] == 'R':
                cunt_right += 1
                cunt_r += 1
            else:
                cunt_w += 1 
    else:
        for i in range(n//2):
            if C[i] == 'W':
                cunt_left += 1
                cunt_w += 1
            else:
                cunt_r += 1
        if C[n//2] == 'W':
            cunt_w += 1
        else:
            cunt_r += 1
        for i in range(n//2+1, n):
            if C[i] == 'R':
                cunt_right += 1
                cunt_r += 1
            else:
                cunt_w += 1 
    if cunt_r*cunt_w == 0:
        print(0)
    else:
        print(max(cunt_left, cunt_right))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k >= n-1:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if j +i == n-1:
        k = j
        break
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
      

print(num)

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input())
    c = [i for i in input()]
    a = 0
    f = False
    ans = 0
    for i in range(n):
        for j in range(i, n):
            if c[i] == "W":
                a = i
                f = True
            elif f:
                c[a] = "R"
                c[i] = "W"
                f = False
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans=2000001
for i in range(N+1):
    WL=C[:i].count("W")
    RL=C[:i].count("R")
    WR=C[i:].count("W")
    RR=C[i:].count("R")
    
    if  ans>max(WR,RL):
        ans=max(WR,RL)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
for i in range(N):
    if C[-i]=="R":
        C=C[:-i]
        break    
    

print(min(C.count("R"),C.count("W")))

Submission status: Wrong Answer

Solution code:
N=int(input())
C=input()
C=[str(c) for c in C]

for i in range(N):
    if C[i]=="R":
        C=C[i:]
        break
    
print(min(C.count("R"),C.count("W")))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
W = 0
R = c.count('R')
if R == 0 or W == 0:
  print(0)
  exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
c = list(input())
count = Counter(c)
ans = float('inf')
w = 0
r = 0

if count.get('R'):
    r = count['R']

for i in range(n):
    if c[i]=='W':
        w += 1
    else:
        r -= 1
    ans =min(max(w,r), ans)
print(ans)

Submission status: Wrong Answer

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

if len(set(s)) == 1:
    print(0)
elif n % 2 == 0:
    r = s[:n//2].count('W')
    w = s[n//2:].count('R')
    print(max(r, w))
else:
    r = s[:n//2].count('W')
    w = s[n//2+1:].count('R')
    print(max(r, w))

Submission status: Wrong Answer

Solution code:
N = int(input())
#stones = list(input())
stones = input()
print(stones)
a = stones.count('W')
b = stones.count('R')

left_side =stones.count('W', 0, b)

print(left_side)

Submission status: Wrong Answer

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

a=0
b=0

a = c.count("R")
ans = c.count("R")
for i in range(N):
    print(i)
    if c[i] == "R":
        a -= 1
    else:
        b += 1

    now = max(a,b)
    ans = min(ans, now)

print(ans)

Submission status: Wrong Answer

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

w = C[:N//2].count("W")

if N%2 == 0:
  r = C[N//2:].count("R")  
else:
  r = C[N//2+1:].count("R")
  
print(max(w,r))

Submission status: Wrong Answer

Solution code:
N = int(input())
#stones = list(input())
stones = input()
print(stones)
a = stones.count('W')
b = stones.count('R')

left_side =stones.count('W', 0, a)
print(left_side)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())

A=min(S[:N-N//2].count("W"),S[N-N//2:].count("R"))

print(A)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())

print(min(S[:N//2].count("W"),S[N-N//2:].count("R")))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())

print(S[:N//2].count("W"))

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
ant=[]
str=input()
wnum=0
rnum=0
for i in range(n):
  list.append(str[i])
  if str[i]=="W":
    wnum+=1
  else:
    rnum+=1
ant=list.copy()
ant.reverse()
n1=-5
n2=-5
k=0
if wnum!=0 and rnum!=0:
  for i in range(6000):
    n1=list.index("W")
    n2=n-1-ant.index("R")
    if n1<n2:
      list[n2],list[n1]=list[n1],list[n2]
      ant[n-1-n2],ant[n-1-n1]=ant[n-1-n1],ant[n-1-n2]
    else:
      print(i)
      break
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
ant=[]
str=input()
wnum=0
rnum=0
for i in range(n):
  list.append(str[i])
  if str[i]=="W":
    wnum+=1
  else:
    rnum+=1
ant=list.copy()
ant.reverse()
n1=-5
n2=-5
k=0
if wnum!=0 and rnum!=0:
  for i in range(2000):
    n1=list.index("W")
    n2=n-1-ant.index("R")
    if n1<n2:
      list[n2],list[n1]=list[n1],list[n2]
      ant[n-1-n2],ant[n-1-n1]=ant[n-1-n1],ant[n-1-n2]
    else:
      print(i)
      break
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
ant=[]
str=input()
wnum=0
rnum=0
for i in range(n):
  list.append(str[i])
  ant.append(str[n-1-i])
  if str[i]=="W":
    wnum+=1
  else:
    rnum+=1
n1=-5
n2=-5
k=0
if wnum!=0 and rnum!=0:
  for i in range(800):
    n1=list.index("W")
    n2=n-1-ant.index("R")
#    print(list)
#    print(ant)
#    print(n1,n2)
    if n1<n2:
      list[n2],list[n1]=list[n1],list[n2]
      ant[n-1-n2],ant[n-1-n1]=ant[n-1-n1],ant[n-1-n2]
#      print(list)
#      print(ant)
    else:
      print(i)
      break
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
list=[]
ant=[]
str=input()
wnum=0
rnum=0
for i in range(n):
  list.append(str[i])
  ant.append(str[n-1-i])
  if str[i]=="W":
    wnum+=1
  else:
    rnum+=1
n1=-5
n2=-5
k=0
if wnum!=0 and rnum!=0:
  for i in range(8):
    n1=list.index("W")
    n2=n-1-ant.index("R")
#    print(list)
#    print(ant)
#    print(n1,n2)
    if n1<n2:
      list[n2],list[n1]=list[n1],list[n2]
      ant[n-1-n2],ant[n-1-n1]=ant[n-1-n1],ant[n-1-n2]
#      print(list)
#      print(ant)
    else:
      print(i)
      break
else:
  print(0)

Submission status: Wrong Answer

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

if 'R' not in c:
    print(0)
    exit()

first_R = c.index('R')
num_R = c.count('R')

if first_R>num_R:
    print(num_R)
else:
    print(first_R+c[first_R:first_R+num_R].count('W'))

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    S = input()
    C = [c for c in S]

    left = 0
    right = len(C) -1
    while left < right and C[left] == 'R':
        left += 1
    while left < right and C[right] == 'W':
        right -= 1

    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while left < right and C[right] == 'W':
            right -= 1
        C[left] = 'R'
        C[right] = 'W'
        ans += 1
        left += 1
        right -= 1
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

    left = 0
    right = len(C) -1
    while left < right and C[left] == 'R':
        left += 1
    while left < right and C[right] == 'W':
        right -= 1

    ans = 0
    while left < right:
        while left < right and C[left] == 'R':
            left += 1
        while left < right and C[right] == 'W':
            right -= 1
        ans += 1
        left += 1
        right -= 1
    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
wc = int(0)
rc = int(0)
c = int(0)

for i in range(N):
  if a[i] == "W":
    wc += 1
  else:
    rc += 1

if rc == 0:
  print("0")
else:
  for i in range(rc):
    if a[i] == "W":
      c += 1
    print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
if len(c) == 1:
    print(0)
else:
    for i in range(len(c)//2):
        if c[i] == "R":
            for j in range(len(c)-1, i, -1):
                if c[j] =="W":
                    c[i], c[j] = c[j], c[i]
                    cou += 1
                    break
print(cou)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c[i] == "R":
        for j in range(len(c)-1, i, -1):
            if c[j] =="W":
                c[i], c[j] = c[j], c[i]
                cou += 1
                break
print(cou)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
c2 = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c2[i] == "R":
        cou += 1
for i in range(len(c)//2):
    if c[i] == "W":
        if c[i+1] == "R":
            cou += 1
print(cou)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())
c = c[::-1]
cou = 0
for i in range(len(c)//2):
    if c[i] == "R":
        cou += 1
print(cou)