101743: [AtCoder]ABC174 D - Alter Altar

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:1 Solved:0

Description

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

Input

题意翻译

### 题目简述 给定一个长为 $n$ 的字符串 $c$,记 $c$ 中的第 $i$ 个字符为 $c_i$($1 \le i \le n$)。现在可以按任意顺序执行以下两个操作之一: - 选择两个字符并交换它们; - 选择一个字符并改变它。 请问:至少要进行多少次操作,才能使字符串中没有`WR`这个子串? ### 输入格式 两行,第一行是一个正整数 $n$,第二行是一个长度为 $n$ 的字符串 $c$。 ### 输出格式 一行一个非负整数,即达到目标所需的最少操作次数。 ### 说明/提示 #### 输入输出样例 #1 说明 例如,下面的两个操作就可以实现目标。 首先,交换 $c_1$ 和 $c_3$,使 $c$ 变为`RWWR`;然后,改变 $c_4$ 为`W`,使 $c$ 满足条件。 #### 输入输出样例 #2 说明 有时可能不需要任何操作。 #### 数据规模与约定 对于全部的输入数据,保证 $2 \le n \le 200000$ 且 $n$ 为整数,同时 $c_i$ 必为`W`或`R`中的一个。

加入题单

算法标签: