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

Solution in Go (1.14.1) (judge verdict: Wrong Answer)

package main

import (
	"fmt"
	"math"
)

func main() {

	var n int
	var c string
	fmt.Scan(&n ,&c)

	cs := split(c)

	cnt:=0
	redRight := len(cs) - 1
	for i := 0; i < len(cs); i++ {
		if cs[i] == "W" {
			for j := redRight; i+ 1 < j; j-- {
				if cs[j] == "R" {
					cs [i] = "R"
					cs[j] = "W"
					redRight= j
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)

	// dp := make([]int, 200010)
	// dp[1] = abs(cs[1] - cs[0])
	// for i := 2; i < n; i++ {
	// 	dp[i] = abs(cs[1] - c[0])

	// 	// 医師を２個選んで入れ替えるか、色変え
	// 	b1:= dp[i-1] + abs(c[i] - c[i-1])
	// 	b2 := dp[i-2] + abs(c[i] - c[i-2])
	// 	if b1 < b2 {
	// 		dp[i] = b1
	// 	} else {
	// 		dp[i] = b2
	// 	}
	// }
	// fmt.Println(dp[n-1])
}
func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}



func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}