Problem: 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?

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.rfind('WR')
        wnum = a[rightmostW:].count('R')
        print(wnum + 1)

if __name__ == '__main__':
    main()


import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.find('WR')
        wnum = a[rightmostW+2:].count('R')
        print(wnum)

if __name__ == '__main__':
    main()

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

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

if __name__ == '__main__':
    main()


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

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

if __name__ == '__main__':
    main()

read = sys.stdin.read
from collections import deque
def main():
    n = int(input())
    a = input()
    if not 'WR' in a:
        print(0)
        sys.exit()
    a = list(a)
    rnum = a.count('R')
    r = 0
    for i1 in range(rnum):
        r += a[i1] == 'W'
    for j1 in range(n - rnum):
        r += a[rnum + j1] == 'R'

    r = r // 2
    print(r)


if __name__ == '__main__':
    main()


import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.rfind('RW')
        wnum = a[:rightmostW+1].count('W')
        print(wnum)

if __name__ == '__main__':
    main()


import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.find('WR')
        wnum = a[rightmostW+2:].count('R')
        leftmostR = a.rfind('R')
        wnum2 = a[:leftmostR].count('W')
        r = min(wnum, wnum2)
        print(r)

if __name__ == '__main__':
    main()

import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a = input()

    if not 'WR' in a:
        print(0)
    else:
        rightmostW = a.find('RW')
        wnum = a[rightmostW+1:].count('R')
        leftmostR = a.rfind('R')
        wnum2 = a[:leftmostR+1].count('W')
        ri = a.find('WR')
        wnum3 = a[ri+2:].count('R')
        r = min(wnum, wnum2,wnum3)
        print(r)

if __name__ == '__main__':
    main()


import sys
read = sys.stdin.read

def main():
    n = int(input())
    rc = tuple(input())
    rc2 = [c == 'W' for c in rc]
    r1 = sum(rc2) 
    r2 = n - r1  
    r3 = sum(rc2[:r2]) 
    print(min(r1, r2, r3))

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted