QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18933. Morning Medicine

Statistics
problem_18933_a3d09dfd60c8e69e0c4e0ae286b322fb.png

Subin received a prescription at a hospital and purchased enough medicine for $N$ days from a pharmacy. Each day's medicine consists of one packet for the morning, one for lunch, and one for dinner. The resulting $3N$ medicine packets are connected in a row in the following order:

morning medicine, lunch medicine, dinner medicine, morning medicine, lunch medicine, dinner medicine, $\cdots$

An ordinary person could simply eat all three meals every day and take the medicine packets by cutting them off one by one from the front. However, Subin's daily routine is not ordinary. On some days, Subin eats only dinner, while on others, Subin skips breakfast. Therefore, rather than taking the medicine in order from the front, Subin wants to take it according to the order of their meals. Of course, Subin intends to take all the medicine without leaving any packet unused.

However, Subin strongly dislikes seeing the connected medicine packets split into two separate pieces. Therefore, whenever Subin takes medicine, they cut off exactly one packet from either the front or the back of the remaining connected packets. Cutting off a packet from the middle, which would split the remaining packets into two pieces, is not allowed.

Given the order in which Subin wants to take the medicine, determine whether all the medicine can be taken in that order while following the condition above.

Input

The first line contains an integer $N$, the number of days' worth of medicine purchased. ($1 \le N \le 1\,000\,000$)

The second line contains a string $S$ of length $3N$, representing the order in which Subin wants to take the medicine. The string $S$ consists only of B, L, and D, and each of the three characters appears exactly $N$ times.

The characters B, L, and D represent morning medicine, lunch medicine, and dinner medicine, respectively.

Output

Print Yes if Subin can take all the medicine in the order given by $S$ while following the condition above. Otherwise, print No.

Examples

Input 1

1
LBD

Output 1

No

Input 2

2
BLDDBL

Output 2

Yes

Note

In the first example, the initial sequence of medicine packets is, from front to back, morning medicine, lunch medicine, and dinner medicine. The first medicine to be taken is the lunch medicine, but it is at neither the front nor the back, so it cannot be taken while satisfying the condition.

In the second example, Subin can take all the medicine in the given order by cutting off packets from the front, front, front, back, front, and front, in that order.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.