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:
def main():
    n = int(input())
    cs = list(input())
    ans = 0
    if n % 2 == 1:
        left_w = cs[:n//2].count("W")
        left_r = cs[:n//2].count("R")
        right_w = cs[(n+1)//2:].count("W")
        right_r = cs[(n+1)//2:].count("R")
    else:
        left_w = cs[:n//2].count("W")
        left_r = cs[:n//2].count("R")
        right_w = cs[n//2:].count("W")
        right_r = cs[n//2:].count("R")
    if left_w == 0:
        print(0)
        exit()
    if right_r >= left_w:
        ans += left_w
        left_r += left_w
        right_r -= left_w
        right_w += left_w
        left_w = 0
    ans += right_r
    right_w += right_r
    right_r = 0
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if len(c) % 2 == 1:
  c.append('W')
l = c[0:len(c)//2]
if c.count('W') == 0 or c.count('R') == 0:
  print(0)
else:
  print(l.count('W'))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
ans = 0
c1 = len(c)//2
cnt_w = 0
cnt_r = 0
for i in range(c1):
  if c[i]=='W':
    cnt_w += 1
for i in range(c1,len(c)):
  if c[i]=='R':
    cnt_r += 1

ans = cnt_w if cnt_w <= cnt_r else cnt_r

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
List=list(input())
a=0
for i in range(N-1):
    if List[i]=="R":
        pass
    else:
        if List[i+1]=="W":
            pass
        else:
            List[i+1]="W"
            a+=1
print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
print(s[:n//2].count('W'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

l = 0
r = n-1

lsl = 0
lsr = 0

while l < n:
  lc = c[l]
  if lc == 'W':
    while 0 <= r:
      rc = c[r]
      if rc == 'R' and l < r:
        ans += 1
        lsl = l
        lsr = r
        r -= 1
        break
      r -= 1
  l += 1
#print('mid : ', ans, lsl, lsr)
if (lsr - lsl) > 1:
  for i in range(lsl+1, lsr):
    if c[i] == 'W':
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
print(a)
a=list(a)
print(a)
t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1
for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

Submission status: Wrong Answer

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

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W >= count_R:
    print(count_W)
else:
    print(count_R)

Submission status: Wrong Answer

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


flag = 0
for i in range(n-1): 
    if(s[i] == "R" and s[i+1] == "W"):
        w_left = i
        r_right = i+1
        flag = 1
        break


#print(w_left)
#print(r_right)
if(flag == 1):
    w_len = len([i for i in s[r_right:] if i == "R"])
    r_len = len([i for i in s[:w_left] if i == "W"])
    print(max(w_len,r_len))
else:
    for i in range(n-1):
        if(s[i] == "W" and s[i+1] == "R"):
            flag = 2
            pnt = i
            ans = min(pnt+1,n-pnt-1)
            print(ans)
            break

if(flag == 0):
    print(0)

Submission status: Wrong Answer

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

count = 0
disastar_list = []
last_one = False
for i in range(0,N-1):
    if c_list[i] == 'W' and c_list[i+1] == 'R':
        disastar_list.append(i)

while len(disastar_list) > 0:
    count = count + 1
    if(len(disastar_list) == 1):
        c_list[disastar_list[0]] = 'R'
    else:
        c_list[disastar_list[len(disastar_list) - 1] + 1] = 'W'
        c_list[disastar_list[0]] = 'R'

    disastar_list = []
    for i in range(0, N -1):
        if c_list[i] == 'W' and c_list[i + 1] == 'R':
            disastar_list.append(i)
            break

    for i in reversed(range(0,N-1)):
        if c_list[i] == 'R' and c_list[i - 1] == 'W':
            if(disastar_list[0] != i-1):
                disastar_list.append(i-1)
                break


print(count)

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)
    if wnoko==lastrr+1:
      print(wnoko-1)
    else:
      print(wnoko-lastrr+1)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
c = S()
ans = 0
if set(c)==1:
    print(0)
    exit()
temp1,temp2 = 0,N-1
while 1:
    if c[temp1]=='R':
        temp1 += 1
    else:
        if c[temp2]=='W':
            temp2 -= 1
    if temp1>=temp2:
        break
    ans += 1
    temp1 += 1
    temp2 -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
def try_count(c, color):
    try:
        if c.count(color)!=0:
            return c.count(color)
        else:
            return n
    except:
        return 0
all_r = try_count(c, 'R')
all_w = try_count(c, 'W')
left_w = try_count(c[:all_w], 'W')
# print(all_r,all_w,left_w)
print(min(all_r,all_w,left_w))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import copy
N = int(input())
C = input()
M = ['']
Ret = []
w_c = 0
r_c = 0
S = ''
cop = 0
for i in range(N):
    if C[i] == 'W':
        if r_c != 0:
            if 'W' in M[-1]:
                M[-1] += S
                Ret.append([cop, r_c])
            else: M.append(S)
            S = ''
            r_c = 0
        w_c += 1
        S += 'W'
    else:
        if w_c != 0:
            M.append(S)
            S = ''
            cop = copy.copy(w_c)
            w_c = 0
        r_c += 1
        S += 'R'
if 'W' in M[-1]:
    M[-1] += S
    Ret.append([cop, r_c])
else: M.append(S)

ret = 0
for r in Ret:
    ret += min(r[0], r[1])

print(ret)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
c = list(input())
ans_1,ans_2 = 0,0
C =  collections.Counter(c)

C_1 = collections.Counter(c[:n//2])
ans_1 = C_1['W']
for i in range(n-1):
    if c[i] == 'W' and c[i+1] == 'R':
        c[i+1] = 'W'
        ans_2 += 1

print(min(ans_1,ans_2))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
line = input()

# print(n)
# print(line.count('W'))
# print(line[:math.floor(n/2)])
# print(line[math.ceil(n/2):])

left_l = line[:math.floor(n/2)]
right_l = line[math.ceil(n/2):]
min_WR = min(left_l.count('W'),right_l.count('R'))

if min_WR > 0:
    print( min_WR + abs(left_l.count('W')-right_l.count('R')))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(sys.stdin.readline().rstrip())
S = [x for x in input()]

C = Counter(S)

W = C["W"]
R = C["R"]

SS = S[:W]
CC = Counter(SS)
WW = CC["W"]

print(WW)

Submission status: Wrong Answer

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

def getLeftR(c, currentIndex):
    for i in range(currentIndex+1, N):
        if c[i] == 'W':
            return i
    return -1

for i in range(N-1):
    if c[i] == 'W' and c[i+1] == 'R':
        leftWindex = getLeftR(c, i+1)
        if leftWindex > 0:
            c[leftWindex], c[i+1] = c[i+1], c[leftWindex]
            count += 1
        else:
            break
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
print(a)
a=list(a)
print(a)
t=0
s=0
for i in range(0,n):
    if a[i]=="R":
        t=t+1

for i in range(0,t):
    if a[i]!="R":
        s=s+1
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
ans = 0
FLG = False
for i in range(N):
    if c[i] == "W":
        j = N - 1
        while c[j] == "W":
            j -= 1
            if j == i:
                FLG = True
                break
        if FLG:
            break
        ans += 1
        c[i], c[j] = c[j], c[i]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
A = int(S.count("R"))
if A == N:
  print(A)
  exit()
s = S[:A]
B = int(s.count("R"))
print(A-B)

Submission status: Wrong Answer

Solution code:
from re import match

n  = int(input())
ci = input()

if len(match('R*W*', ci).group(0)) == n:
    print(0)
    exit()

fst = ci.find('R')
rng = len(match('^R+', ci[fst:]).group(0))
Rs  = ci.count('R')
Ws  = n - Rs

'''
first <= Ws
'''

Rs2 = Rs - fst
Ws2 = Ws - fst

if Rs2 == 0:
    print(fst)

else:
    print(fst + Rs2 - rng)

Submission status: Wrong Answer

Solution code:
# Coding is about expressing your feeling and there is always a better way to express your feeling _feelme
import sys,math,numpy as np
#sys.stdin,sys.stdout=open('input.txt','r'),open('output.txt','w')
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# np.set_printoptions(sign=' ',legacy='1.13') # legacy add space at sign position
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


n = ii1()
s=is1()
a=Counter(s)
W=a['W']
R=a['R']
print(W,R)
if W == n or R == n:
    print(0,'hi')
else:
    countr=0
    countw=0
    for i in range(R,n):
        if s[i]=='R':
            countr+=1
        else:
            countw+=1
    print(countr)

Submission status: Wrong Answer

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

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

    prev = cur
    if changedPoint >= i:
        break

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
C=list(input())
if C.count("W")==0:
    print(0)
elif C.count("W")==1:
    if C[-1]=="W":
        print(0)
    else:
        print(1)
else:
    tmpw=C.count("W")
    #print(tmpw,C)
    C=C[tmpw:]
    #print(tmpw,C)
    print(C.count("R"))

Submission status: Wrong Answer

Solution code:
import sys

def first_white(c):
    for i,ele in enumerate(c):
        if ele == 0:
            return i
    return -1
        
def last_red(c):
    for i in range(len(c)-1, -1, -1):
        if c[i] == 1:
            return i
    return -1

n = int(input())
c = [0 if x=='W' else 1 for x in input()]
counter = 0
while True:
    first_w = first_white(c)
    last_r = last_red(c)
    if (len(c) == 0) or (first_white(c) < 0) or (last_red(c) < 0):
        print(counter)
        sys.exit()
    c = c[first_w+1:last_r]    
    counter += 1

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
ans1 = min(c[0:(n-i-1)].count("R"),c[0:(n-i-1)].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())
stone = list(map(str,input()))
ind = [""]*2
ind[0] = list()
ind[1] = list()
R = 0
W = 0
for i in range(N):
    if(stone[i]=="W"):
        ind[0].append(i)
        W += 1
    else:
        ind[1].append(i)
        R += 1
ind[0].reverse()
ans = 0
newR = 0
for i in range(R):
    if(i != ind[1][i]):
        break
    newR+= 1

if(W != R):
    if(newR != R):
        print(min(W,R-newR))
    else:
        print(min(W,R))
else:
    for i in range(N//2):
        if(ind[0][i]>ind[1][i]):
            break
        ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from typing import List


def main():
    def readline() -> str:
        s = sys.stdin.readline()
        return s.rstrip()

    n: int = int(readline())
    c: List[str] = list(readline())

    if "W" not in c or "R" not in c:
        print(0)
        return

    l_p: int = c.index("W")
    r_p: int = -1
    operations: int = 0

    while n > l_p - r_p:
        if c[r_p] == "R":
            c[l_p] = "R"
            c[r_p] = "W"
            operations += 1
            l_p += 1
        r_p -= 1

    print(operations)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

l = 0
r = len(S) - 1

W = 'W'
R = 'R'

cnt = 0
while l < r:
    if S[l] == R:
        l += 1
        continue
    else:
        while l < r:
            if S[r] == W:
                r -= 1
                continue
            else:
                cnt += 1
                l += 1
                r -= 1
                continue

print(cnt)

Submission status: Wrong Answer

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


flag = 0
for i in range(n-1): 
    if(s[i] == "R" and s[i+1] == "W"):
        w_left = i
        r_right = i+1
        flag = 1
        break


#print(w_left)
#print(r_right)
if(flag == 1):
    w_len = len([i for i in s[r_right:] if i == "R"])
    r_len = len([i for i in s[:w_left] if i == "W"])
    print(max(w_len,r_len))
else:
    for i in range(n-1):
        if(s[i] == "W" and s[i+1] == "R"):
            flag = 2
            pnt = i
            if((pnt+1)*2 < n):
                print(pnt+1)
                break
            else:
                print(n-pnt-1)
                break

if(flag == 0):
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
cl = list(c)
wi = 0
wnum=0
ri = n-1
rnum=0
br=0
bw=0
res1 = n
for i in range(n):
    while(cl[wi] == "R" and bw==0):
        wi+=1
        if(wi >= n-1):
            bw=1
            break
    if(cl[wi] == "W"):
        wnum+=1
    wi+=1
    if(wi >= n-1):
        wi=0
        bw=1
    while(cl[ri] == "W" and br==0):
        ri-=1
        if(ri <= 0):
            br=1
            break
    if(cl[ri] == "R"):
        rnum+=1
    ri-=1
    if(ri <= 0):
        ri=n-1
        br=1
    #print(wi, ri)
    if(ri < wi):
        res1 = i+1
    if(br*bw==1):
        break
print(min(res1, rnum, wnum))

Submission status: Wrong Answer

Solution code:
def function(N, 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())
al = list(input())
cr = al.count('R')
cw = al.count('W')
if cr >= cw:
    print(al[:n//2+1].count('W'))
else:
    print(al[n//2:].count('R'))

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
w_cnt = 0
r_cnt = 0
prev_r = False
ans = 0
for c in C:
    if c == 'W' and not prev_r:
        w_cnt += 1
    if c == 'R':
        r_cnt += 1
        prev_r = True
    if c == 'W' and prev_r:
        ans += min(r_cnt, w_cnt)
        r_cnt = 0
        w_cnt = 1
        prev_r = False
if C[-1] == 'R':
    ans += min(r_cnt, w_cnt)
numw = C.count('W')
numr = C.count('R')
ans = min(ans, numr, numw)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    a, b = c[:len(c)//2], c[len(c)//2:]
    # print(f'{c=}')
    # print(f'{a=}')
    # print(f'{b=}')

    wc = a.count('W')
    rc = b.count('R')
    # print(f'{wc=} {rc=}')

    return min(wc, rc)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
rr = []
ww = []
for i in range(N):
  if (c[i] == "R"):
    rr.append(i)
  if (c[i] == "W"):
    ww.append(i)

wl = len(ww)
rl = len(rr)
l = min([wl,rl])
ans = 0
flag = False
for i in range(l):
  if (ww[i] < rr[-i-1]):
    ans += 1
  else:
    flag = True
  
if (flag):
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
wc = s[:n//2].count('W')
rc = s[n//2:].count('N')
# print(wc)
# print(rc)
print(max(wc, rc))

Submission status: Wrong Answer

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

if c.count('W') == 0 or c.count('R') == 0:
    print(0)
    exit()


count_W = 0
count_R = 0

for i in range(N):
    if i < N/2:
        if c[i] == 'W':
            count_W += 1
    else:
        if c[i] == 'R':
            count_R += 1

if count_W <= count_R:
    print(count_W)
else:
    print(count_R)

Submission status: Wrong Answer

Solution code:
# N = int(input())
# C = input()
# # WとRの数が等しくなるところ？
# red_ruisekiwa = [0]
# for i in range(N):
#     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-1, -1, -1):
#     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:]
# print(red_ruisekiwa)
# # white_ruisekiwa.reverse()
# print(white_ruisekiwa)
N = int(input())
C = input()
left_C = C[:N//2]
right_C = C[N//2:]
# print(left_C)
# print(right_C)
red_right = right_C.count("R")
white_left = left_C.count("W")
print(min(red_right, white_left))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=input()
f=False
ans=0
wc=0

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

for i in range(n):
  if c[i]=="W":
    wc+=1
    f=True
    if rc<=wc:
      print(wc)
      exit()
  else:
    rc-=1
  if f and c[i]=="R":
    ans+=1
print(ans)

Submission status: Wrong Answer

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

count=0
flag=False

for i in range(n):
	if c[i]=="W":
		flag=True
	else:
		if flag==True:
			count+=1
			flag=False
print(count)

Submission status: Wrong Answer

Solution code:
import math

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

count_W = 0
for i in range(math.ceil(N/2)):
    if c[i] == 'W':
        count_W += 1
        
count_R = 0
for i in range(math.ceil(N/2)):
    if c[-1-i] == 'R':
        count_R += 1

print(min(count_R, count_W))

Submission status: Wrong Answer

Solution code:
N=int(input())
c=input()
mid=len(c)//2
rl=c[mid:].count('R')
wf=c[:mid].count('W')
if rl<wf:
  print(rl)
else:
  print(wf)

Submission status: Wrong Answer

Solution code:
N = int(input())
mozi = input()
mozi2 = list(mozi)
a = len(mozi2)
num_w = mozi2.count("W"); num_r = mozi2.count("R")
list_w2 = mozi2[(a-num_w):]; list_w1 = mozi2[:(a-num_w)]
list_r2 = mozi2[(a-num_r):]; list_r1 = mozi2[:(a-num_r)]
if num_w <= num_r:
    if "W" in list_w2:
        print(list_w1.count("W"))
    else:
        print(num_w)
elif num_w==0 or num_r==0:
    print(0)
else:
    if "R" in list_r1:
        print(list_r2.count("R"))
    else:
        print(num_r)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
pre = c[0:(N+1)//2]
suf = c[(N+1)//2:N]
ans = 0

pre_cnt = pre.count('W')
suf_cnt = suf.count('R')

ans = min(pre_cnt,suf_cnt)

print(ans)

Submission status: Wrong Answer

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

N, = map(int, input().split())
c = list(input())

while True:
    if c[0]=='R':
        c = c[1:]
    else:
        break
    if c==[]:
        break

ans = 0
if 'R' not in c:
    ans = 0
else:
    first_R = 0
    for i, cc in enumerate(c):
        if cc=='R':
            first_R = i+1
            break
    num_left_W = first_R - 1
    num_right_R = sum([1 for cc in c[first_R:] if cc=='R'])

    num_W = len(c) - (num_right_R+1)
    ans = num_W

    if num_right_R==0:
        ans = 1
    elif num_right_R>=num_left_W:
        ans = min(ans, num_right_R)
    else:
        ans = min(ans, num_right_R+1)

print(ans)

Submission status: Wrong Answer

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n = I()
c = input()
s = -1
f = 10000000
ans = 0
t = c.find("W")
p= c.rfind("R")
if t == -1 or p == -1:
  print(0)
else:
  
  while s < f:
    s = c[s+1:].find("W")
    f = c[:f].rfind("R")
    ans += 1
  print(ans-1)

Submission status: Wrong Answer

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

'''
Author: andyli
Time: 2020-08-02 19:55:50
'''

import os
from io import BytesIO, IOBase
import sys


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

    def calc(s):
        p = 0
        while p < len(s) and s[p] == 'R': p += 1
        _ans = s.count('R')-p
        p = len(s)-1
        while p >= 0 and s[p] == 'W': p -= 1
        _ans = min(_ans, s.count('W')-(len(s)-p-1))
        return _ans

    ans = calc(s)
    # print(ans)
    p1 = 0
    while p1 < n and s[p1] == 'W': p1 += 1
    p2 = n-1
    while p2 >= 0 and s[p2] == 'R': p2 -= 1

    cnt = min(p1, n-p2-1)
    # print(p1,p2,cnt)
    s2 = 'R'*cnt + 'W' * max(0, p1-cnt) + s[p1:p2+1] + 'R' * max(0,n-p2-1-cnt) + 'W'*cnt
    # print(s2)
    # calc(s2) + min()
    ans = min(ans, calc(s2) + cnt)
    print(ans)
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    N = int(input())
    c = input()
    cnt = collections.Counter(c)
    ans = 200000
    ans2 = 200000

    W_cnt = cnt['W']
    R_cnt = cnt['R']

    if W_cnt == R_cnt:
        cnt2 = collections.Counter(c[:R_cnt])
        ans2 = cnt2['W']
    if c[0] == 'R':
        R_cnt -= 1
    if c[N-1] == 'W':
        W_cnt -= 1
    ans = min(W_cnt, R_cnt)
    print(min(ans, ans2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
h1 = (n + 1) // 2
h2 = n // 2
ans1 = min(c[:h1].count('W'), c[h1:].count('R'))
ans2 = min(c[:h2].count('W'), c[h2:].count('R'))
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(input())
if N%2==0:
  x = a[0:int(N/2)]
  y = a[int(N/2):N]
else:
  x = a[0:int(N/2)]
  y = a[int(N/2)+1:N]
count_ri = x.count('W')
count_le = y.count('R')
if a.count('W') ==0 or a.count('R')==0:
  print(0)
elif x.count('W')==0 and y.count('R')==0:
  print(0)
elif count_ri==count_le:
  print(count_ri)
elif count_ri>count_le:
  print(count_le)
elif count_ri<count_le:
  print(count_ri)

Submission status: Wrong Answer

Solution code:
n = int(input())
C = input()
c_R = 0
c_W = 0
for c in C:
    if c == "R": c_R += 1
    else: c_W += 1
ans = min(c_R, c_W)
flag = 0

if C[0] + C[1] == "WR":
    if "WR" in C[2:]: flag = 1
C = list(C)
if flag:
    C[0] = "R"
    c_R = 0
    c_W = 0
    for i in range(1, n - 1):
        if C[i] + C[i + 1] == "WR":
            C[i] = "R"
            break
    for c in C:
        if c == "R": c_R += 1
        else: c_W += 1
    ans = min(c_R, c_W)+1
    print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
altars = []
transformations = 0

for altar in c:
    altars.append(altar)

rightmost_red_index = len(altars) - 1

for i in range(len(altars) // 2):
    if altars[i] == "W":
        for j in range(rightmost_red_index, 0, -1):
            if altars[j] == "R":
                altars[j] = "W"
                altars[i] = "R"
                rightmost_red_index = j
                transformations += 1
                break

if len(altars) % 2 == 1:
    first_white_index = - 1

    for i in range(len(altars)):
        if altars[i] == "W":
            first_white_index = i
            break
    if first_white_index != -1:
        for j in range(first_white_index, len(altars)):
            if altars[j] == "R":
                transformations += 1

print(transformations)

Submission status: Wrong Answer

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

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

left, right = 0, len(c) - 1
cnt = 0

if left == 0 and c[left] == 'W' and c[left+1] == 'R':
    c[left] = 'R'
    left += 1
    cnt += 1

elif right == len(c)-1 and c[right] == 'R' and c[right-1] == 'W':
    c[right] = 'W'
    right -= 1
    cnt += 1

while left < right:

    if left > 0 and c[left-1] == c[left+1] == 'R' and c[left] == 'W':
        c[left] = 'R'
        left += 1

    elif right < len(c) - 1 and c[right-1] == c[right+1] == 'W' and c[right] == 'R':
        c[right] = 'W'
        right -= 1

    elif c[left] is 'W' and c[right] is 'R':
        c[left] = 'R'
        c[right] = 'W'

    elif c[left] is 'W':
        right -= 1
        continue
    
    elif c[right] is 'R':
        left += 1
        continue

    else:
        left += 1
        right -= 1
        continue

    left += 1
    right -= 1

    cnt += 1

print(cnt)