There are N people standing in a queue from west to east. Each person is facing either west or east.
Input
You will receive a string S of length N, where:
The i-th character of S is L if the i-th person from the west is facing west.
The i-th character of S is R if the i-th person from the west is facing east.
A person is considered happy if the person directly in front of them is facing the same direction. However, a person at the front of the queue cannot be happy, as there is no one in front of them.
You can perform the following operation up to K times (inclusive):
Operation
Choose integers l and r such that 1 ≤ l ≤ r ≤ N, and rotate the section of the queue from position l to r by 180 degrees. This means:
The l-th person becomes the r-th person.
The l+1-th person becomes the r-1-th person.
And so on, swapping their facing directions: L becomes R, and R becomes L.
Goal
Determine the maximum possible number of happy people you can achieve after performing the operations.
Output
Return a single integer, the maximum number of happy people.
Examples
Example 1
Input:
text
S = "RLLR"
K = 1
Output:
text
3
Explanation:
By performing the rotation operation on the segment (1, 3), the string becomes "LLR", resulting in 3 happy people.
Example 2
Input:
text
S = "LLRLLL"
K = 2
Output:
text
5
Explanation:
You can perform the rotation operation on the segment (2, 5) to achieve "LLLLLL", resulting in 5 happy people.
Constraints
1 ≤ N ≤ 100
0 ≤ K ≤ 50
S will only contain the characters L and R.
Implementation
Please implement the solution in the /app/ directory.