QOJ.ac

QOJ

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

#18885. Rainbow Beads

Statistics

Jaehyun has a bead which consists of $N$ jewels arranged from left to right. Each jewel is in one of the three colors: Red, Blue, and Violet, which is represented as a single character R, B, V. As one of the committees in an important contest, Jaehyun wants to use it as a souvenir for some participant.

Jaehyun likes a bead with diverse colors, so he defines a bead beautiful if every adjacent jewel has different colors. For example, RBVBV is a beautiful bead because every adjacent jewel has a different color. V is a beautiful bead because it does not have adjacent pairs. However, RBBV is not a beautiful bead, because two Bs in the middle are adjacent in the string.

Not only Jaehyun likes a bead with diverse colors, but he likes a contest with diversity. This time, Jaehyun wants to make a bead that is also colorful to colorblind people. For convenience, we will only consider three kinds of people in this problem.

  • Non-colorblind people, who can tell all three colors.
  • Red-colorblind people (Protanopia), who can't tell apart red and violet: They consider violet jewels as red jewels.
  • Blue-colorblind people (Tritanopia), who can't tell apart blue and violet: They consider violet jewels as blue jewels.

In this case, the string RVB is colorful for non-colorblind people, but it is not colorful for red-colorblind people as red and violet jewels are adjacent, and it is also not colorful for blue-colorblind people as violet and blue jewels are adjacent.

Jaehyun wants to pick some contiguous part of the bead and cut it out to give as a souvenir. The part Jaehyun cuts should be colorful to all three kinds of people. Note that, if the whole bead is beautiful, then Jaehyun does not necessarily cut it out, but just give the whole bead. What is the length of the longest bead he can give?

Input

The first line contains an integer $N$, denoting the length of the bead. ($1 \le N \le 250\,000$)

The next line contains string of length $N$, where every character is either R, B, or V.

Output

Print the maximum possible length of contiguous beads, which is colorful for all three kinds of people.

Examples

Input 1

4
RBBB

Output 1

2

Input 2

5
RBRBB

Output 2

4

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.