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=list(input())
wcnt=0
rcnt=0
ans=0


for i in range(len(c)):
    if c[i]=="R" and wcnt==0:
        pass
    elif c[i]=="R" and wcnt!=0:
        rcnt+=1
    elif c[i]=="W" and rcnt!=0:
        ans+= min(wcnt,rcnt)
        wcnt=0
        rcnt=0
        wcnt+=1
    elif c[i]=="W" and rcnt==0:
        wcnt+=1
if rcnt != 0:
    ans+= min(wcnt,rcnt)
print(ans)

Submission status: Wrong Answer

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

a = N // 2

if N & 2 == 0:
    right_W = C[:a].count ('W')
else:
    right_W = C[:a+1].count('W')
left_R = C[a:].count ('R')

ans = min(right_W, left_R)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
c = np.array(list(input()))

count = 0

n_white = np.count_nonzero(c=='W')
n_red = np.count_nonzero(c=='R')

if n_red:
    if n_white:
        p_white = np.where(c == 'W')[0].tolist()
        p_red = np.where(c == 'R')[0].tolist()
        num = min(len(p_white), len(p_red))
        i = 0
        while (i < num):
            if p_white[-1-i] < p_red[i]:
                count += 1
            i += 1
else:
    count = n_white

print(count)

Submission status: Wrong Answer

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

move_right = 0
move_left = N-1

count = 0

while move_right < move_left:
    if C[move_right] == 'R':
        move_right += 1

    else:
        while C[move_left] != 'R' and move_left >= 0:
            move_left -= 1

        if move_left < 0:
            # 入れ替えできるものがなかったので置き換え
            if C[move_right + 1] == 'R':
                count += 1

        # 入れ替え
        if C[move_left] == 'R':
            count += 1

        move_right += 1
        move_left -= 1


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

c = list(input())

now = 0

count = 0

while now < len(c):
    print(c)
    if c[now] == "W":
        r = now+1
        found = False
        while r < len(c):
            if c[r] == "R":
                found = True
                break
            else:
                r += 1
        if not found:
            break
        c[now], c[r] = c[r], c[now]
        now += 1
        count += 1

    else:
        now += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D
from functools import reduce as R
import heapq as H

ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())

n = I()
stones = S()
i, j = 0, len(stones)-1
ans = 0

if 'WR' not in stones:
  print('0')
else:
  stones = list(stones)
  while i < j:
    while stones[i] == 'R':
      i += 1
    while stones[j] == 'W':
      j -= 1
    if i < j:
      stones[i] = 'R'
    stones[j] = 'W'
    i += 1
    j -= 1
    ans += 1
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
tmpN = N
C = input()
if N % 2 == 1:
  N -= 1
N = int(N / 2)
result = C.count('R',N)

if C.count('R') == tmpN:
  print('0')
else:
  print(result)

Submission status: Wrong Answer

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

x =[0] * N

ww = 0
rr = 0
for i, cc in enumerate(c):
    if cc == "R":
        x[i] = 1
        rr += 1
    else:
        ww += 1

cmd = 0
for i in range(rr):
    if x[i] == 0:
        cmd += 1

cmd2 = 0
for j in range(rr+1, len(x)):
    if x[i] == 1:
        cmd2 += 1


print(max(cmd, cmd2))

Submission status: Wrong Answer

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

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

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

    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
count = 0
if (C1.count('W') == C2.count('R')):   #左右対象のとき
    count = C1.count('W')
elif(C1.count('R') == C2.count('W')):
    count = C.count('W')
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
while True:
	if S.count('R') == 0:
		break
	if S[0] == 'R':
		S=S.lstrip('R')
	else:
		Rposfirst=S.find('R')
		Rposend = S.rfind('R')
		S = S[Rposfirst:Rposend]
		count += Rposfirst
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D

N=int(input())
c=input()
d=list(c)
w=0
ans=0
w_list=[0]*N
w_cnt=0
r_cnt=0

if c.count("W")==0 or c.count("W")==N:
    ans=0
else:
    for i,j in enumerate(d):
        if j=="W":
            w_cnt +=1
        else:
            w_list[i]=w_cnt
            r_cnt += 1
            
    #print(w_list)
    #print("r個数",r_cnt)

    for i in range(N-1,-1,-1):
        if d[i]=="R":
            r_cnt -= 1
            
            if w_cnt>0:
                ans += 1
                w_cnt -= 1 
            else:
                break
        else:
            if r_cnt>0:
                ans += 1
                w_cnt -= 1
                r_cnt -= 1
            else:
                break
        #print(N-1-i, r_cnt, w_cnt)
        
print(ans)

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
n = int(input())
c = input()

wcount = c.count("W")
rcount = c.count("R")
check = 0

num = min(wcount, rcount)

if rcount < wcount:
    for i in range(wcount):
        if c[i] == "R":
            check += 1

else:
    for i in range(n - rcount, n):
        if c[i] == "W":
            check += 1

print(num - check)

Submission status: Wrong Answer

Solution code:
# D Alter Altar

n = int(input())
C = input()

# 動かす必要のないWの数
_C = C[::-1]
safe_W = 0
for _c in _C:
  if _c == "W":
    safe_W += 1
  else:
    break

# Rの数
num_R = C.count("R")

# 元々全部R or Wの場合
if len(C) == num_R or num_R == 0:
  print(0)
  exit()

# 一色に染めるときの回数で少ない方
num_all = min(len(C) - num_R, num_R)

#左端にRを固める作戦の回数
space = 0
for c in C:
  if c == "W":
    space += 1
  elif c == "R":
    break
if num_R <= space:
  num_left = num_R
else:
  num_left = min(len(C) - num_R - safe_W, num_R - 1)
  
print(min(num_left, num_all))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(str, stdin.readline().split()))


def main():
    N = int(input())
    ls = str(input())
    rls = []
    wls = []
    for i,item in enumerate(ls):
        if item == 'W':
            wls.append(i)
        if len(wls)==0:
            continue
        if item == 'R':
            rls.append(i)
    count = 0
    ww = len(wls)
    rr = len(rls)
    wls = deque(wls)
    rls = deque(rls)
    while True:
        if ww== 0:
            print(0)
            return
        if ww > rr:
            print(rr+count)
            return
        count += 1
        r = rls.pop()
        w = wls.popleft()
        while True:
            if w+1 in rls:
                rls.popleft()
                w += 1
                if len(rls) == 0:
                    print(count)
            else:
                break
        ww = ww + 1
        rr = len(rls)



main()

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
c = input()
n = int(N/2)
c_1 = c[:n]
print(c_1.count('W'))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    c = list(input())

    W_list = np.zeros(N)
    R_list = np.zeros(N)
    for i in range(N):
        if i == 0:
            if c[i] == 'W':
                W_list[i] = 1
            else:
                W_list[i] = 0
        else:
            if c[i] == 'W':
                W_list[i] = W_list[i-1] + 1
            else:
                W_list[i] = W_list[i-1]

    for i in range(N-1, -1, -1):
        if i == N-1:
            if c[i] == 'R':
                R_list[i] = 1
            else:
                R_list[i] = 0
        else:
            if c[i] == 'R':
                R_list[i] = R_list[i+1] + 1
            else:
                R_list[i] = R_list[i+1]

    ans = 0
    for i in range(N-1, -1, -1):
        if W_list[i] == R_list[i]:
            ans = W_list[i]
            break
    print(int(ans))
    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
n = 0
for i in range(N - 1):
    if c[i] == 'W' and c[i + 1] == 'R':
        if i == 0 or i == N - 2:
            n += 1
        elif c[i - 1] == 'W' and c[i + 2] == 'R':
            n += 2
        else:
            n += 1
print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
b = 0
def wr(x):
    c = 0
    for i in range(1, n):
        if a[i-1] == "W" and a[i] == "R":
            c = c + 1
        else:
            c = c
    return c
            
for i in range(1,n-1):
    if (a[i-1] == "W" and a[i] == "R" and a[i+1] == "R") or (a[i-1] == "W" and a[i] == "W" and a[i+1] == "R"):
        b = b + 1
    else: 
        b = b

if (wr(a) - b) % 2 == 0:
    print(((wr(a)-b)//2) + b)
else:
    print(((wr(a)-b-1)//2) + b + 1)

Submission status: Wrong Answer

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

# あかのインデックス
RR=[-1]
# しろのインデックス
WW=[]

for i in range(n):
    if a[i]=='R':
        RR.append(i)
    else:
        WW.append(i)
WW.append(float('inf'))

if a.count('R')==0 or a.count('R')==n:
    print(0)
    exit()
if a.count('W')==1:
    print(1)
    exit()

for i in range(len(RR)-1):
    if RR[-2-i]<WW[i+1]:
        print(i+1)
        exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
tmpN = N
C = input()
if N % 2 == 1:
  N += 1
N = int(N / 2)
result = C.count('R',N)

if C.count('R') == tmpN:
  print('0')
else:
  print(result)

Submission status: Wrong Answer

Solution code:
def solve(ls):
    n = len(ls)
    ls = [int(x == 'R') for x in ls]  # 0: W, 1: R
    num_w = sum(ls)
    num_r = n - num_w
    if num_r == 0:
        return 0
    # TODO: prove/disprove optimality
    left_w = 0
    right_r = num_r
    for i in range(n):
        if ls[i] == 0:
            left_w += 1
        else:
            right_r -= 1
        if left_w == right_r:
            return right_r


def main(istr, ostr):
    n, = list(map(int, istr.readline().strip().split()))
    s = istr.readline().strip()
    result = solve(s)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

Submission status: Wrong Answer

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

prev = S[0]
cur = 'R'
count = 0
wNum = 0
changedPoint = -1
for i in range(N-1, -1, -1):
    cur = S[i]
    if cur == 'R':
        for j in range(wNum, i):
            wNum = j + 1
            if S[j] == 'W':
                changedPoint = j
                break
        if changedPoint != -1 and i > changedPoint:
            count += 1
        else:
            break

    prev = cur
    if wNum == i-1:
        break

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    n = int(input())
    c = list(input())

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

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
WWRR"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
RR"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
WRWWRWRR"""
        output = """3"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
c = input()
s = Counter(c)
if s['W'] == 0 or s['R'] == 0:
  print('0')
elif c.index('R') == 0 and c.index('W') == s['R']:
  print('0')
elif s['R'] > c.index('R'):
  print(s['R'] - (c.index('R')+1) + c.index('R'))
else:
  print(s['R'])

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
f=False
ans=0
a1=0
wb=wc=0
rb=rc=0

for i in range(n):
  if c[i]=="R":
    rc += 1
  else:
    wc += 1

for i in range(n):
  if c[i]=="W":
    f=True

  if f:
    if c[i]=="R":
      rb+=1
      rc-=1
    else:
      wb+=1
      wc-=1

    print("#",rb,rc,wb,wc)
    if wb==rc:
      print(i)
      exit()

print(rb)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
c = input()
n = int(N/2)
c_1 = c[:n]

if N%2==0:
  print(c_1.count('W'))
else:
  cnt = c_1.count('W')
  if c[n] == 'W':
    cnt += 1
  print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
d = [0] * N
for i in range(N):
    if c[i] == 'R':
        d[i] = 1
count = 0
for i in range(0, N):
    if d[i] == 2:
        break
    if d[i] == 0:
        for j in reversed(range(0, N)):
            if d[j] == 1:
                d[i] = 1
                d[j] = 2
                count += 1
                break
            if j == i:
                d[j] = 1
                count += 1
                break
print(count)

Submission status: Wrong Answer

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

x =[0] * N

ww = 0
rr = 0
for i, cc in enumerate(c):
    if cc == "R":
        x[i] = 1
        rr += 1
    else:
        ww += 1

cmd = 0
for i in range(rr):
    if x[i] == 0:
        cmd += 1

for j in range(rr+1, len(x)):
    if x[i] == 1:
        cmd += 1

print(cmd)

Submission status: Wrong Answer

Solution code:
ans = 0
n = int(input())
c = input()
print(c)
check  = c[0]
count = 0
flag=0
for i in c:
    if(i=="R"):
        count+=1
for i,k in enumerate(c):
    print(check,k)
    if check=="W" and k=="R":
        ans+=1
        check = "W"
        if i<count:
            flag+=1
    else:
        check  = k
print(ans-flag)

Submission status: Wrong Answer

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

#色を揃えるパターン
#全部赤
ans1 = 0
for i in range(len(c)):
    if c[-(i+1)] == "R":
        break
dum = c[0:(n-i)]
ans1 = min(dum.count("R"),dum.count("W"))
ans2 = 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
                ans2 += 1
                break
print(min(ans1,ans2))

Submission status: Wrong Answer

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

# あかのインデックス
RR=[-1]
# しろのインデックス
WW=[]

for i in range(n):
    if a[i]=='R':
        RR.append(i)
    else:
        WW.append(i)
WW.append(float('inf'))

if a.count('R')==0 or a.count('R')==n:
    print(0)
    exit()

for i in range(len(RR)-1):
    if RR[-2-i]<WW[i+1]:
        print(i+1)
        exit()

Submission status: Wrong Answer

Solution code:
N=int(input())
white=0
red=0
hu=0
W=list(str(input()))
if "W" not in W or "R" not in W:
  print("0")
  exit()
for i in range(N//2):
  if W[i]=="W":
    white+=1
for i in range(N//2):
  if W[N-1-i]=="R":
    red+=1
for k in range(N):
  if W[k]=="W":
    hu+=1
if hu==white+N//2:
  print(0)
  exit()
elif white>=red:
  print(red)
  exit()
else:
  Z=white*2-red
  if (N/2)%1!=0:
    if W[N//2+1]=="W" and W[N//2+2]=="R":
      Z+=1
  print(Z)

Submission status: Wrong Answer

Solution code:
# D Alter Altar

n = int(input())
C = input()

# 動かす必要のないWの数
_C = C[::-1]
safe_W = 0
for _c in _C:
  if _c == "W":
    safe_W += 1
  else:
    break

# Rの数
num_R = C.count("R")

# 元々全部R or Wの場合
if len(C) == num_R or num_R == 0:
  print(0)
  exit()

# 一色に染めるときの回数で少ない方
num_all = min(len(C) - num_R, num_R)

#左端にRを固める作戦の回数
space = 0
for c in C:
  if c == "W":
    space += 1
  elif c == "R":
    break
if num_R <= space:
  num_left = num_R
else:
  num_left = len(C) - num_R - safe_W
  
print(min(num_left, num_all))

Submission status: Wrong Answer

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

l_tmp = 1
r_tmp = -1
# カウント
count = 0
# デバック
# print("    ", s)
# RRRRWW みたいにRを左におしやりたい
for i in range(n):
    if l_tmp - r_tmp - 1 >= n:
        break

    if s[l_tmp - 1] == "R":
        l_tmp += 1
        # print("cont", s)
        continue

    if s[l_tmp - 1] == "W":
        if s[r_tmp] == "R":
            # 交換処理
            s[l_tmp - 1] = "R"
            s[r_tmp] = "W"
            #
            l_tmp += 1
            r_tmp -= 1
            # カウント
            count += 1
            # デバック
            # print("chan", s)
            continue

        if s[r_tmp] == "W":
            # print("-------")
            # print(l_tmp, r_tmp)
            # print(s[l_tmp], s[r_tmp])
            # print("-------")
            # TODO: ここが更新処理で決めつけられない
            while l_tmp - r_tmp + 1 >= n and s[r_tmp] == "W":
                r_tmp -= 1
                # print(s)

            # もしなければ更新処理
            if l_tmp - r_tmp - 1 == n and s[r_tmp] == "W":
                # 更新処理
                s[l_tmp - 1] = "R"
                #
                l_tmp += 1
                # カウント
                count += 1
                # デバック
                # print("chan", s)
                continue
            # あれば交換処理

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
b = 0
def wr(x):
    c = 0
    for i in range(1, n):
        if a[i-1] == "W" and a[i] == "R":
            c = c + 1
        else:
            c = c
    return c
            
for i in range(1,n-1):
    if (a[i-1] == "W" and a[i] == "R" and a[i+1] == "R") or (a[i-1] == "W" and a[i] == "W" and a[i+1] == "R"):
        b = b + 1
    else: 
        b = b
    print(b)
if (wr(a) - b) % 2 == 0:
    print(((wr(a)-b)//2) + b)
else:
    print(((wr(a)-b-1)//2) + b + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def function(N, c):
    c = c.lstrip('R')
    c = c.rstrip('W')
    N = len(c)
    num_R = c.count('R')
    num_W = c.count('W')

    if (num_R == 0) or (num_W == 0):
        return 0
    else:
        if num_R < num_W:
            num = 0
            for i in range(int(N/2)):
                if c[i] == 'R':
                    num += 1
            if num_R == 1:
                if c[0] == 'R':
                    return 0
                else:
                    return 1
            else:
                return num_R-num
        else:
            num = 0
            for i in range(int(N/2)):
                if c[N-1-i] == 'W':
                    num += 1
            if num_W == 1:
                if c[-1] == 'W':
                    return 0
                else:
                    return 1
            else:
                return num_W-num


if __name__ == '__main__':
    N = int(input())
    c = input()
    print(function(N, c))

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
S = input().strip()
if S.count('W') == 0 or S.count('R') == 0:
    print(0)
else:
    count = 0
    
    SS = S[:len(S)//2]
    A = sorted(S)[:len(S)//2]
    
    for ss,a in zip(SS,A):
        if ss != a:
            count+=1
    print(count)

Submission status: Wrong Answer

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

a = N // 2

right_W = C[:a].count ('W')
left_R = C[a:].count ('R')

ans = min(right_W, left_R)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
if N%2!=0 and C[mid-1] == "W":
  Wcount -= 1
print(Wcount)

Submission status: Wrong Answer

Solution code:
nn = int(input())
ss = str(input())
stones = list(map(str, str(ss)))
#print(stones)


numW = sum(x == 'W' for x in stones)
numR = sum(x == 'R' for x in stones)
if numW == 0:
    print('0')
elif numR == 0:
    print('1')
else:
    addrW = [0]*numW
    addrR = [0]*numR
    countW = 0
    countR = 0

    for i in range(nn):
        if stones[i] == 'W':
            addrW[countW] = i
            countW += 1
        else:
            addrR[countR] = i
            countR +=1

    ind_leftmostW = 0
    ind_rightmostR = len(stones)

    ind = 0

    while ind < min(numR,numW):
        if addrW[ind] < addrR[numR-1-ind]:
    #        stones[addrW[ind]] = 'R'
    #        stones[addrR[numR-1-ind]] = 'W'
    #        print(stones)
            ind += 1
        else:
            break

    print(ind)

Submission status: Wrong Answer

Solution code:
N = int(input())
c= list(input()) 
if c.count('R') == N:
	print(0)
div=0
if N %2 == 1:
	div =1
clist_L = c[:int(N/2)]
clist_R = c[int(N/2)+div:]
Lcnt = clist_L.count('W')
Rcnt = clist_R.count('R')
if Lcnt - Rcnt <=0:
	print(Rcnt)
else:
	print(Lcnt-Rcnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
count = 0
if (C1.count('W') == C2.count('R')):   #左右対象のとき
    count = C1.count('W')
else:
    count = C.count('W')
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = list(input())#ciが R のとき赤、W のとき白
count = 0


for i in range(n-1):
  #print(c)
  if c[i] == "W" and c[i+1] == "R":
    c[i] = "R"
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
n=0
if S.find("W")==-1 or S.find("R")==-1:
  print(0)
else:
  while S.find("W")<S.rfind("R"):
    S = S[S.find("W")+1:S.rfind("R")]
    n+=1
  print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(input())
cr = al.count('R')
print(al[:cr+1].count('W'))

Submission status: Wrong Answer

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

l=S[:x//2].count('W')
r=S[(x+1)//2:].count('R')

print(max(l,r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
#sort = sorted(a)[::-1] 降順
n = int(input())
c = input()

wcount = c.count("W")
rcount = c.count("R")
check = 0

num = min(wcount, rcount)

if wcount < rcount:
    for i in range(wcount):
        if c[i] == "R":
            check += 1

else:
    for i in range(n - rcount, n):
        if c[i] == "W":
            check += 1

print(num - check)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = list(input())
N1 = int(N/2)
C1 = C[0:N1]
C2 = C[N1:N]
print(C1)
print(C2)
count = 0
if (C1.count('W') == C2.count('R')):   #左右対象のとき
    count = C1.count('W')
else:
    count = C.count('W')
print(count)

Submission status: Wrong Answer

Solution code:
def do():
    x=int(input())
    k1=0
    s=input()
    s1=0
    k2=0
    st=""
    for i in range(x-1):
        if s[i]=="W" :
            if s[i+1]=="R":
               k1+=1
            if s[i+1]=="W":
                for j in range(i,x):
                    if s[j]=="W":
                        st+="W"
                    if s[j]=="R":
                        break
                    if j==x:
                        return k1
                for k in range(j+1,x):
                    k2=k
                    if s[k]=="R":
                        st+="R"
                    if s[k]=="W":
                        break
                    if k==x:
                        return k1+st.count("R")
    return k1+st.count("R")

print(do())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
b = 0
def wr(x):
    c = 0
    for i in range(1, n):
        if a[i-1] == "W" and a[i] == "R":
            c = c + 1
        else:
            c = c
    return c
            
for i in range(1,n-1):
    if (a[i-1] == "W" and a[i] == "R" and a[i+1] == "R") or (a[i-1] == "W" and a[i] == "W" and a[i+1] == "R"):
        b = b + 1
    else: 
        b = b

if (wr(a) - b) % 2 == 0:
    print(((wr(a)-b)/2) + b)
else:
    print(((wr(a)-b-1)/2) + b + 1)

Submission status: Wrong Answer

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

    R_l=c.find('R')
    R_n=c.count('R')

    ans=0

    if c.find('WR')==-1:
        print(0)
    else:
        R_info=[]
        p=0
        for i in range(N):
            if c[i]=='R':
                R_info.append(p)
                p=0
            else:
                p+=1

        # print(R_info)
        for i,n in enumerate(R_info):
            # print(i)
            # print("ans="+str(ans))
            # print("R_n="+str(R_n))
            # if R_n==0:
            #     break
            if n==0:
                R_n-=1
            elif n>=1 and R_n-1>=n:
                R_n-=n+1
                ans+=n
                # print(ans)
                # print(R_n)
            else:
                ans+=R_n
                # print(ans)
                break
        print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
if C[mid-1] == "W":
  Wcount -= 1
print(Wcount)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = input()
# WとRの数が等しくなるところ？

red_ruisekiwa = [0]
for i in range(N-1, -1, -1):
    if C[i] == "R":
        red_ruisekiwa.append(red_ruisekiwa[-1]+1)
    else:
        red_ruisekiwa.append(red_ruisekiwa[-1])

white_ruisekiwa = [0]
for i in range(N):
    if C[i] == "W":
        white_ruisekiwa.append(white_ruisekiwa[-1]+1)
    else:
        white_ruisekiwa.append(white_ruisekiwa[-1])
red_ruisekiwa = red_ruisekiwa[1:]
white_ruisekiwa = white_ruisekiwa[1:]

for i in range(N):
    if white_ruisekiwa[i] == red_ruisekiwa[N-(i+1)]:
        print(white_ruisekiwa[i])
        exit()
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
cnt = 0
for i in s:
    if i == "R":
        cnt += 1
    else:
        break

a = s.count("R")-cnt
b = 0

while s[:b+1].count("W") < s[b:].count("R"):
    b += 1

print(min(a,b))