407436: GYM102791 B Look At The Same One

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

Description

B. Look At The Same Onetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $$$n$$$ soldiers in the line, standing shoulder to shoulder from left to right. Each soldier's head is turned either to the left or to the right, that is, each of the soldiers is looking either strictly to the left or strictly to the right.

You need to give some of the soldiers an order to turn their heads in the opposite direction. That means, after executing this order, a soldier looking to the left should turn his head to the right, and a soldier looking to the right should turn his head to the left. After executing the order, there should exist a soldier such that all other soldiers look at him (it doesn't matter in which direction that soldier looks). Only the soldiers who were given the order turn their heads.

For example, if there are $$$5$$$ soldiers in the line, the first three soldiers are looking to the right, and the fifth soldier is looking to the left, then they all are looking at the fourth soldier.

Find the minimum number of soldiers who should be given the order to turn their heads so that all the soldiers were looking in the direction of some single soldier.

Input

The first line contains an integer $$$n$$$ ($$$2 \le n \le 2\,000$$$) — the number of soldiers in the line.

The second line contains a string $$$s$$$ of length $$$n$$$, consisting of the letters "L" and "R". If the $$$i$$$-th character of the string is "L", then the $$$i$$$-th soldier is looking to the left. If the $$$i$$$-th character of the string is "R", then the $$$i$$$-th soldier is looking to the right.

Output

Print the minimum number of soldiers who should be given the order to turn their heads so that there exists a soldier such that all other soldiers look at him (it doesn't matter in which direction that soldier looks).

ExamplesInput
6
LRRRLR
Output
2
Input
3
LLL
Output
0
Input
10
LLRRLRRRRL
Output
3
Note

In the first example, you need to give the order, for example, to the first and sixth soldiers. After that, the line would look like "RRRRLL". So everyone except the fifth soldier would be looking at the fifth soldier.

In the second example, all the soldiers are looking to the left, so the second and third soldiers are looking at the first soldier, so you don't need to give any orders.

加入题单

上一题 下一题 算法标签: