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

    aux = 0 # quantidade de pedras 'W' antes da primeira pedra 'R'
    r = False
    b = False
    qnt_r = 0 #não conta com a primeira pedra 'R'
    qnt_r2 = 0
    for pedra in pedras:
        if r == False and pedra == 'W':
            aux += 1
        elif r == True and aux == 0 and pedra == 'R' and b == True:
            qnt_r2 += 1
        elif pedra == 'R':
            r = True
            qnt_r += 1

        if pedra == 'W':
            b = True

    if aux > 0 and aux <= qnt_r - 1:
        print(qnt_r - 1)
    elif aux > qnt_r - 1:
        print(qnt_r)
    elif aux == 0:
        print(qnt_r2)

main()

Submission status: Wrong Answer

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

w = 0
r = s.count('R')
ans = N

for i in range(N):
    if s[i] == 'R':
        r -= 1
    else:
        w += 1
    ans = min(ans, max(w, r))

print(ans)

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':

    n = int(input())
    A = list(input())

    white = A.count("W")
    red = A.count("R")

    ans = 0
    if red > white:
        ind = n // 2 + 1
    else:
        ind = n // 2

    left = A[:ind]
    ans = left.count("W")
    print(ans)

Submission status: Wrong Answer

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

for i in c:
    if i=="R":
        red += 1

br = 0
ans = 10**12
for i in range(red):
    if c[i]=="R":
        br += 1
    white = i+1 - br
    disappear = red - br - white
    ans = min(ans, white+disappear)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = input()
print(min(c.count("W"), c.count("R"), c[:c.count("W")].count("W")))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(input())
ans=0
flag=0
for i in c:
  if i=="W":
    flag+=1
  elif flag==0 and i=="R":
    pass
  else:
    flag-=1
    ans+=1
cnt=0
for i in range(n-1):
  if c[i]=="W" and c[i+1]=="R":
    cnt+=1
print(ans-cnt//2)

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        # if not ('WR' in c):
        #     return count
        while len(c) > 0 and c[-1] == 'W':
            c = c[:-1]
        while len(c) > 0 and c[0] == 'R':
            c = c[1:]
        if len(c) == 0:
            return count

        c1 = c.replace('WR','WW',1)
        count1=c1.count('WR')
        c2 = c.replace('WR','RR',1)
        count2=c2.count('WR')
        if count1 < count2:
            c = c1
        else:
            c = c2[:-1]
        count += 1

N = int(input())
c= input()
print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        # if not ('WR' in c):
        #     return count
        while len(c) > 0 and c[-1] == 'W':
            c = c[:-1]
        while len(c) > 0 and c[0] == 'R':
            c = c[1:]
        if len(c) == 0:
            return count
        i = c.index('WR')
        c1 = c.replace('WR','WW',1).count('WR')
        c2 = c.replace('WR','RR',1).count('WR')
        if c1 < c2:
            c = c.replace('WR', 'WW', 1)
        else:
            c = c.replace('WR','RR',1)
            c = c[:-1]
        count += 1

N = int(input())
c= input()
print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[-1] == 'W':
            c = c[:-1]
        while c[0] == 'R':
            c = c[1:]
        if (c.index('R') == len(c) - 1):
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

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

print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            c = c[:-1]

        if c.index('R') == len(c) - 1:
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

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

print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            c = c[:-1]

        if c.index('R') + 1 != len(c):
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1
        else:
            return count + 1


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

print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
def checkFunction(c):
    count = 0

    while True:
        if not ('WR' in c):
            return count
        while c[0] == 'R':
            c = c[1:]
        while c[-1] == 'W':
            c = c[:-1]

        if c.index('R') + 1 != len(c):
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1
        return count + 1


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

print(checkFunction(c))

Submission status: Wrong Answer

Solution code:
s = input()
R_num = s.count("R")
print(s[:R_num].count("W"))

Submission status: Wrong Answer

Solution code:
s = input()
R_num = s.count("R")
s[:R_num].count("W")

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
i=0
j=N-1
while i<=j:
  while i<N:
    if S[i]=='W':
      break
    else:
      i+=1
  while j>0:
    if S[j]=='R':
      break
    else:
      j-=1
  if i<=j:
    ans+=1
    i+=1
    j-=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=input()
ans=0
i=0
j=N-1
while i<j:
  while i<N:
    if S[i]=='W':
      break
    else:
      i+=1
  while j>0:
    if S[j]=='R':
      break
    else:
      j-=1
  if i<=j:
    ans+=1
    i+=1
    j-=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
C = list(input())
C_ = sorted(C)

wr = rw = 0
for i in range(len(C_)):
    if C[i] != C_[i]:
        if C[i] == 'R' and C_[i] == 'W':
            rw += 1
        else:
            wr += 1

print(max(wr, rw))

Submission status: Wrong Answer

Solution code:
in_num = int(input())

if in_num % 2 == 0:
    print(-1)
    exit()
elif in_num % 5 == 0:
    print(-1)
    exit()

# 数列のスタート位置を探す
ans = 1
s = 1
while s * 7 < in_num:
    s = int(str(s) + "1")
    ans += 1

import math

while True:
    x = math.gcd(in_num, s * 7)
    if x == 1:
        s = int(str(s) + "1")
        ans += 1
    else:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:

k = int(input())

L = list(input())

ans = 0
w = 0
r = 0
for i in range(1, k):
    if i <= k//2 and L[i] == "W":
        w += 1
    if i >= k//2 and L[i] == "R":
        r += 1

ans = (w + r)//2 + 1

if "W" not in L:
    ans = 0

if "R" not in L:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

C_l = []
ans = []
for _ in range(N):
    w = C_l.count("W")
    r = C.count("R")
    ans.append(max(w, r))
    C_l.append(C.pop(0))
    
print(min(ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# from pdb import set_trace
N = int(input())
C = input()
if C.find("WR")==-1:
    print(0)
    exit()
cnt = 0
l = list(C)
WR = 0
while WR!=1:
    w = C.find("W")
    r = len(C) - C[::-1].find("R") - 1
    l[w] = "R"
    l[r] = "W"
    C = "".join(l)
    index = 0
    WR = 0
    c = C
    while index>=0:
        index = c.find("WR")
        if index>=0:
            WR += 1
        c = c[index+2: ]
    cnt += 1
while True:
    w = C.find("WR")
    if w>=0:
        l[w] = "R"
        C = "".join(l)
        cnt += 1
    else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = input()
W = C.count("W") 
R = N-W
counter = 0

if(W<R):
  wrong = C[:W-1].count("W")
  print(wrong)
else:
  wrong = C[W-1:].count("R")
  print(wrong)

Submission status: Wrong Answer

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = input()
r = seq.count('R')
ans = 0
cnt = 0
for i in xrange(n):
    if seq[i] == 'R':
        cnt += 1
    else:
        ans += 1
        cnt += 1
    if cnt == r:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
i = 0

c = input()

# leftRed = str.count("R", 0,N/2-1)
leftWhite = c.count("W", 0,int(N/2))
rightRed = c.count("R", int(N/2),N)
# rightWhite = str.count("W", N/2,N-1)

ans += min(leftWhite, rightRed)
if leftWhite > rightRed:
    ans += (leftWhite - rightRed)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
left, right = 0, n - 1
cnt = 0
while left <= right:
    while left < n and c[left] == 'R':
        left += 1
    while right > -1 and c[right] == 'W':
        right -= 1
    if left == n or right == -1: break
    left += 1
    right -= 1
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import re
N=int(input())
c = (input())
count=0
while len(re.findall("WR",c)) !=0:
    W_early=max(c.find('\WR'),0)
    R_last=c.rfind('WR')
    c=list(c)
    c[W_early]="R"
    c[R_last+1]="W"
    c="".join(c)
    print(c)
    count +=1
print(count)

Submission status: Wrong Answer

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

while "WR" in c:
    c = c.replace("W", "R", 1)
    c = c.replace("WR", "WW", 1)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
d = c.count('w')
e = c[:d].count('w')
print(d-e)

Submission status: Wrong Answer

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

while "wr" in c:
    c = c.replace("w", "r", 1)
    c = c.replace("wr", "ww", 1)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
#D
import re
N=int(input())
c = (input())
combi=re.findall("WR",c)
print(len(combi))

Submission status: Wrong Answer

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

count = N

numW = S[:0].count('W')
numR = S[0:].count('R')

if(numW == N):
    print(0)

else:
    for i in range(N):
        if(S[i] == 'W'):
            numW += 1
        else:
            numR -= 1

        if(max(numW, numR) < count):
            count = max(numW, numR)

    print(count)

Submission status: Wrong Answer

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

count = N

numW = S[:0].count('W')
numR = S[0:].count('R')

for i in range(N):
    if(S[i] == 'W'):
        numW += 1
    else:
        numR -= 1

    if(max(numW, numR) < count):
        count = max(numW, numR)

print(count)

Submission status: Wrong Answer

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

count = N

for i in range(1, N):
    numW = S[:i].count('W')
    numR = S[i:].count('R')

    if(max(numW, numR) < count):
        count = max(numW, numR)

print(count)

Submission status: Wrong Answer

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

cnt = 0
start = False

for i in range(1,n-1):
    if c[i] + c[i+1] == 'WR':
        cnt+=1
        start = True
    elif c[i] + c[i+1] == 'RR' and start:
        cnt+=1
    else:
        start = False

if c[0]+c[1] == 'WR' and cnt ==0:
    cnt+=1

allw =0

for i in c:
    if i == 'W':
        allw+=1

if cnt<allw:           
    print(cnt)
else:
    print(allw)

Submission status: Wrong Answer

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

cnt = 0
start = False

for i in range(1,n-1):
    if c[i] + c[i+1] == 'WR':
        cnt+=1
        start = True
    elif c[i] + c[i+1] == 'RR' and start:
        cnt+=1
    else:
        start = False

if c[0]+c[1] == 'WR' and cnt ==0:
    cnt+=1
    
print(cnt)

Submission status: Wrong Answer

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

cnt = 0
start = False

for i in range(1,n-1):
    if c[i] + c[i+1] == 'WR':
        cnt+=1
        start = True
    elif c[i] + c[i+1] == 'RR' and start:
        cnt+=1
    else:
        start = False

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N = iRaw()
    cs = sRaw()
    ac_sums =[0]
    for c in cs:
        if c=="W":
            ac_sums.append(ac_sums[-1]+1)
        else:
            ac_sums.append(ac_sums[-1])
    ans = 0
    nW = ac_sums[-1]
    nR = N-nW
    ans = INF
    for n_idx,ac_sum in enumerate(ac_sums):
        ans = min(ans,max(ac_sum,nW-(n_idx-ac_sum)))
    print(ans)
    
main()

Submission status: Wrong Answer

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

w = c.count("W")
r = c.count("R")

ans = r

if w == 0:
    print(0)
else:
    if c[0]=="R":
        for i in range(N):
            if c[i] == "W":
                ans -= i
                print(ans)
                break
    elif c[0]=="W":
        for k in range(N):
            if c[k] == "W" and c[k+1] == "W":
                ans -= k-1
                print(ans)
                break

Submission status: Wrong Answer

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

w = c.count("W")
r = c.count("R")

ans = r

if w == 0:
    print(0)
else:
    if c[0]=="R":
        for i in range(N):
            if c[i] == "W":
                ans -= i
                print(ans)
                break
            break
    elif c[0]=="W":
        for k in range(N+1):
            if c[k] == c[k+1] == "W":
                ans -= k
                print(ans)
                break
            break

Submission status: Wrong Answer

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

w = c.count("W")
r = c.count("R")

ans = r

if w == 0:
    print(0)
else:
    if c[0]=="R":
        for i in range(N):
            if c[i] == "W":
                ans -= i
                print(ans)
                break
            break

Submission status: Wrong Answer

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

count = 0
r = 0
w = 0
for i in range(N // 2):
    c = C[i]
    if c == "W":
        if r > 0:
            r -= 1
            count += 1
        else:
            w += 1
    c = C[N-i-1]
    if c == "R":
        if w > 0:
            w -= 1
            count += 1
        else:
            r += 1
ans = count + w
print(ans)

Submission status: Wrong Answer

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

count = 0
r = 0
w = 0
for i in range(N // 2 + 1):
    c = C[i]
    if c == "W":
        if r > 0:
            r -= 1
            count += 1
        else:
            w += 1
    c = C[N-i-1]
    if c == "R":
        if w > 0:
            w -= 1
            count += 1
        else:
            r += 1
ans = count + w
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
half_N = int(N/2)
words = list(input())
ct_R = words.count('R')
ct_W = words.count('W')

if ct_W == ct_R:
  jhw = words[0:half_N]

  print(jhw.count('W'))
  
if ct_W <= ct_R:
    jhw = words[ct_R:-1]
    print(jhw.count('R'))
    
if ct_W >= ct_R:
    jhw = words[0:ct_R]
    print(jhw.count('R'))

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i <= b:
    r+=1
  if c[i] == 1 and i > b:
    w+=1
 

print(max(w,r))

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
c = [1 if _ == 'R' else 0 for _ in input()]
b = n-sum(c)

w=0
r=0

for i in range(n):
  if c[i] == 0 and i <= b:
    w+=1
  if c[i] == 1 and i > b:
    r+=1

print(max(w,r))

Submission status: Wrong Answer

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

n = int(input())
clist = list(input())

if clist.count("R") == 0:
    print(0)
    exit()

w_cnt = 0
for i in range(n):
    if clist[i] == 'R':
        break
    w_cnt += 1

last = True
for j in range(i,n):
    if clist[j] == 'W':
        break
else:
    last = False

r_cnt = 0
if last:
    for k in range(j,n):
        if clist[k] == 'R':
            r_cnt += 1

print(max(w_cnt,r_cnt))

Submission status: Wrong Answer

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

n = int(input())
clist = list(input())

w_cnt = 0
for i in range(n):
    if clist[i] == 'R':
        break
    w_cnt += 1

last = True
for j in range(i,n):
    if clist[j] == 'W':
        break
else:
    last = False

r_cnt = 0
if last:
    for k in range(j,n):
        if clist[k] == 'R':
            r_cnt += 1

print(max(w_cnt,r_cnt))

Submission status: Wrong Answer

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

t = n
lw, rr = 0, c.count('R')
for ci in c:
    swap = min(lw, rr)
    wtor, rtow = max(0, lw-swap), max(0, rr-swap)
    t = min(t, swap + wtor + rtow)
    lw = lw + (ci == 'W')
    rr = rr - (ci == 'R')

print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = list(input())
ws = 0
rs = 0
moves = 0
for i in range(0, n):
    if k[i] == "W":
        ws += 1
    else :
        rs += 1
if ws == 0 or rs == 0:
    print(0)

else: 
    if rs <= ws:
        for j in range(0, rs):
            if k[j] == "W":
                moves += 1
    else:
        for j in range(n-1, ws-1, -1):
            if k[j] == "R":
                moves += 1
    print(moves)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = list(input())
ws = 0
rs = 0
moves = 0
for i in range(0, n):
    if k[i] == "W":
        ws += 1
    else :
        rs += 1
if ws == 0 or rs == 0:
    print(0)

else: 
    if rs < ws:
        for j in range(0, rs):
            if k[j] == "W":
                moves += 1
    else:
        for j in range(n-1, ws-1, -1):
            if k[j] == "R":
                moves += 1
    print(moves)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = list(input())
ws = 0
rs = 0
moves = 0
for i in range(0, n-1):
    if k[i] == "W":
        ws += 1
    else :
        rs += 1
if ws == 0 or rs == 0:
    print(0)
if rs < ws:
    for i in range(0, rs-1):
        if k[i] == "W":
            moves += 1
else:
    for i in range(n-1, ws):
        if k[i] == "R":
            moves += 1
print(moves)

Submission status: Wrong Answer

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

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

harf = round(len(c)/2)
wCnt = c[:harf].count('W')
rCnt = c[-harf:].count('R')
print(wCnt if wCnt >= rCnt else rCnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
c=0
for i in range(len(s)-1):
  if(s[i]=='W' and s[i+1]=='R'):
    c+=1
print(c)

Submission status: Wrong Answer

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

n = int(input())
clist = list(input())

r_cnt = 0
for i in range(n):
    if clist[i] == 'R':
        r_cnt += 1

if r_cnt == 0:
    print(0)
    exit()

j = 0
w_cnt = 0
while clist[j] != 'R':
    w_cnt += 1
    j += 1

fr = 0
FR = True
for i in range(n):
    if FR:
        if clist[i] == "R":
            FR = False
            fr += 1
    else:
        if clist[i] == "R":
            fr += 1
        else:
            break

if clist.count("W") == 0:
    print(0)

if r_cnt - fr + 1 > w_cnt:
    print(r_cnt - fr )
else:
    print(r_cnt)

Submission status: Wrong Answer

Solution code:
N= int(input())
c=list(str(input()))
#N=4
#c=['W', 'W', 'R', 'R']
#c.reverse()
#print(c)

t1=t2=True

n1=0
n2=0
num=0
while t1:
    t2=True
    if not 0<=N-1-n1<=N-1:
        t1=False
    if c[N-1-n1]=='W':
        n1+=1
        continue
    else:
        while t2:
            if c[n2-1]=='W':
                if n2-1<N-1-n1:
                    c[N-1-n1]='W'
                    c[n2-1]='R'
                    num+=1
                    t2=False
                else:
                    t1=False 
            n2+=1
            if not 0<=n2-1<=N-1:
                t1=False
                t2=False
print(num)

Submission status: Wrong Answer

Solution code:
N=int(input())

c=list(input())

minimum=len(c)
W=0
R=c.count('R')

for i in range(0,len(c)):
    if c[i]=='W':
        W += 1
    else :
        R -= 1
    min_i=max(W,R)
    if min_i < minimum:
        minimum=min_i

print(minimum)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=list(str(input()))
ans=0
wl=0
for r in range(N-1,-1,-1):
  if r=='W':
    continue
  if r==wl:
    break
  for w in range(wl,r):
    if c[w]=='W':
      wl=w+1
      ans+=1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=list(str(input()))
ans=0
wl=0
for r in range(N-1,-1,-1):
  if r=='W':
    print('a')
    continue
  if r==wl:
    break
  for w in range(wl,r):
    if c[w]=='W':
      c[w],c[r]='R','W'
      wl=w+1
      ans+=1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
c=list(str(input()))
ans=0
wl=0
for r in range(N-1,-1,-1):
  if r=='W':
    print('a')
    continue
  for w in range(wl,r):
    if c[w]=='W':
      c[w],c[r]='R','W'
      wl=w+1
      ans+=1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
string = input()
count = 0
for i in range(n+1):
    left = string[:i]
    right = string[i:]
    tmp_max = max(left.count("W"), right.count("R"))
    if count < tmp_max:
        count = tmp_max
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
w = c.count("W")
r = c.count("R")
wr = c[w:].count("W")

print(min(r, w - wr))

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(input())
w = c.count("W")
wr = c[w:].count("W")

print(w - wr)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=list(input())
left=0
right=N-1
count=0
while True:
  while left<N and ls[left]=='R':
    left+=1
  while right>0 and ls[right]=='W':
    right-=1
  if left>right:
    break
  left+=1
  right-=1
  count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
sumr_ = 0
for _ in c:
    sumr_ += (_ == "R")
if sumr_ == len(c) or sumr_ == 0:
    print(0)
    quit()

sumr = sumr_
sumc = 0
minc = 10**8
for i in range(len(c)):
    if c[i] == "R":
        sumc += i
        sumr -= 1
        minc = min(sumr_, sumc + sumr)
print(minc)

Submission status: Wrong Answer

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

ans = n

W = C.count("W")
R = C.count("R")

# 仕切りより左側にある白石の数
w = 0
# 仕切りより右側にある赤石の数
r = R

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
white_count, red_count = 0, 0

for i in range(0, n // 2 + 1):
    if c[i] == 'W':
        white_count += 1
for i in range(n // 2+1, n):
    if c[i] == 'R':
        red_count += 1

print(min(white_count, red_count))

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input()
white_count, red_count = 0, 0

for i in range(0, n // 2 + 1):
    if c[i] == 'W':
        white_count += 1

for i in range(n // 2, n):
    if c[i] == 'R':
        red_count += 1

print(min(white_count, red_count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
# l, r = list(map(int, input().split()))
# n, d = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# n = int(input())
# a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# data = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
# for i in range(1, int(n**0.5)+1):
moji = input()
c = []
r_cnt = 0
for i in range(len(moji)):
    c.append(moji[i])
    if moji[i] == "R":
        r_cnt += 1

a = len(c)
# print(c)
# print(r_cnt)
# print("--------")
j = len(c)-1
count = 0
for i in range(len(c)):
    if c[i] == "W":  # and c[i+1] == "R":
        while j >= 0:
            if c[j] == "R":
                c[i] = "R"
                c[j] = "W"
                count += 1
                a -= 1
                break
            j -= 1
    else:
        a -= 1
    #print(c, " ")
    # print(a)
    if a <= r_cnt:
        break

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
moji = input()
c = []
for i in range(len(moji)):
    c.append(moji[i])
j = len(c)-1
count = 0
for i in range(len(c)//2):
    if c[i] == "W":  # and c[i+1] == "R":
        while j >= 0:
            if c[j] == "R":
                c[i] = "R"
                c[j] = "W"
                count += 1
                break
            j -= 1
    # print(c)

print(count)

Submission status: Wrong Answer

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

R_count = 0
W_count = 0
for i in range(len(stone)):
  if stone[i] == "R":
    R_count = R_count + 1
  else:
    W_count = W_count + 1

W = 0
R = R_count
try_num_prev = -1
for i in range(N):
  if R_count == 0 or W_count == 0:
    try_num = 0
    break
  
  if W <= R:
    try_num = R
  else:
    try_num = W
  
  if try_num_prev > 0 and try_num_prev < try_num:
    try_num = try_num_prev
    break
  else:
    try_num_prev = try_num
    if stone[i] == "R":
      R = R - 1
    else:
      W = W + 1
    
print(try_num)

Submission status: Wrong Answer

Solution code:
import math
from decimal import *
def pfacts(n):
    ans = []
    if(n%2==0):
        ans.append(2)
        while(n%2==0):
            n//=2
    p=3
    while(n!= 1):
        if(n%p==0):
            ans.append(p)
            while(n%p==0):
                n//=p
        p+=1
    return ans


n = int(input())
s = str(input())
pnt1 = -1
ans = 0
remr = 0
r, w = 0,0
for i in range(n):
    if(s[n-i-1]=='W'):
        pnt1 = int(n-i)
        break
    else:
        remr+=1
for i in range(pnt1-1):
    if(s[i]=='W'):
        w+=1
ans = max(remr, w)
if(w+1==pnt1):
    ans = min(remr, w+1)
if(pnt1==-1):
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from decimal import *
def pfacts(n):
    ans = []
    if(n%2==0):
        ans.append(2)
        while(n%2==0):
            n//=2
    p=3
    while(n!= 1):
        if(n%p==0):
            ans.append(p)
            while(n%p==0):
                n//=p
        p+=1
    return ans


n = int(input())
s = str(input())
pnt1 = -1
ans = 0
remr = 0
r, w = 0,0
for i in range(n):
    if(s[n-i-1]=='W'):
        pnt1 = int(n-i)
        break
    else:
        remr+=1
for i in range(pnt1-1):
    if(s[i]=='W'):
        w+=1
ans = max(remr, w)
if(pnt1==-1):
    ans = 0
print(ans)

Submission status: Wrong Answer

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

result = 0
forward_c = ''
backward_c = ''
W_count = 0
R_count = 0

if N % 2 == 0:
    forward_c = c[:int(N/2)]
    backward_c = c[int(N/2):]
    W_count = forward_c.count('W')
    R_count = backward_c.count('R')
    if W_count < R_count:
        result = W_count
    else:
        result = R_count
else:
    forward_c = c[:int(N/2)]
    backward_c = c[int(N/2)+1:]
    if W_count < R_count:
        result = W_count
        if c[int(N/2)] == 'W':
            result += 1
    elif W_count > R_count:
        result = R_count
        if c[int(N/2)] == 'R':
            result += 1
    else:
        result = R_count

print(result)

Submission status: Wrong Answer

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

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