Everyone knows that Bayview's Computer Club owns a sick gaming PC with very sick RGB lights.
The colours of these RGB lights can be represented by a sequence R
if the G
if it is green, and B
if it is blue.
For some reason, the computer club execs have decided that the current sequence of lights is ugly, and want to change the colours to match the sequence
Luckily, each of the lights can be toggled with a special remote control. When a light is toggled:
- If the light was red, it becomes green.
- If the light was green, it becomes blue.
- If the light was blue, it becomes red.
Not so luckily, this special remote has malfunctioned, and can only toggle seemingly random contiguous intervals of lights.
The computer club execs use the remote
Constraints
Input Specification
The first line contains a single integer,
The second line contains R
, G
, or B
.
The third line contains R
, G
, or B
.
The fourth line contains a single integer,
The next
Output Specification
Output a single integer, the minimal value of -1
.
If the sequence of lights equals 0
.
Sample Input 1
3
RRR
BBG
3
1 3
1 2
3 3
Sample Output 1
2
Explanation for Sample Output 1
After the remote is used for the first time, the sequence of lights becomes GGG
.
After the second time, it becomes BBG
, which matches the target sequence.
Sample Input 2
2
RG
BG
2
2 2
1 2
Sample Output 2
-1
Comments