Girls
Limits: 2 sec., 256 MiB
Senior knows 2N girls. They are standing in 2 rows and N columns. Two girs are neighbours if they are standing next to each other in the same row or in the same column.
Each girl has either red or black hair. In one turn Senior can do one of the following:
Choose any girl. Let’s denote her hair color as C. Then the girl convinces one of her neighbours (Senior decides which one) to paint hair in color C.
Choose any column and a direction (left or right). Then each of two girls from the column convinces her neighbour in the chosen direction to paint hair in her color.
Choose any range of consecutive girls in one of the rows. Then each of the girls convinces her neighbour in the opposite row to pain hair in her color.
Senior is a big fan of red girls. Thus he would like to know what is the minimal number of turns needed to make all 2N girls red. It is guaranteed that initially there is at least one red girl.
Input
The first line contains integer number N. The second line contains a string of length N. The i-th character of the string is either ’R’ or ’B’ and denotes a color of the i-th girl in the first row (’R’ stands for red hair and ’B’ — for black). The third line describes the second row of girls in the same format.
Output
Print a single integer — the minimal number of turns needed.
Constraints
\(1 \le \mathbf{N} \le 50\).
Samples
Input (stdin) | Output (stdout) |
---|---|
3 RBR BRB | 2 |
Submit a solution
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|
Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
---|