Lanterns with One Repair#13115

Lanterns with One Repair

2 секунде
256 мегабајтова

There are houses arranged in a circle, numbered from to . One lantern stands next to each house.

Each lantern illuminates exactly one of the two neighboring houses:

A lantern does not illuminate the house it stands next to. The left neighbor of house is house i-1, and its right neighbor is house i+1. For house , the left neighbor is house ; for house , the right neighbor is house .

You may turn around at most one lantern, changing its direction from L to R or vice versa.

Find the maximum number of houses that can be illuminated by exactly one lantern afterwards.

Улаз

The first line contains an integer (3\le n\le2\cdot10^5) — the number of houses.

The second line contains a string of length consisting of L and R. Character s_i gives the direction of the lantern next to house .

Излаз

Print one integer — the maximum possible number of houses illuminated by exactly one lantern.

Примери

Пример 1

Loading
Loading

Пример 2

Loading
Loading

Пример 3

Loading
Loading

Напомена

In the first example, turn around the second lantern to obtain RRRRR. Every house is then illuminated by exactly one lantern, so the answer is .

In the second example, houses and initially receive light from two lanterns each, while houses and receive none. Turning around the first lantern makes houses and illuminated by exactly one lantern each. More than two such houses cannot be obtained.

In the third example, all four houses are already illuminated by exactly one lantern, so no change is needed.

Бодовање

  1. Subtask ( points): n\le100.

  2. Subtask ( points): n\le2000.

  3. Subtask ( points): no additional constraints.