#K85557. Minimum Moves to Rearrange Blocks
Minimum Moves to Rearrange Blocks
Minimum Moves to Rearrange Blocks
You are given a sequence of n colorful blocks represented by a string, where each character is either 'R', 'G', or 'B'. Your task is to determine the minimum number of moves required to rearrange the blocks so that no two adjacent blocks have the same color.
A move is defined as changing the color of one block to any of the three available colors, chosen so that it does not match the color of either of its adjacent blocks (if they exist). The modification must lead to a configuration where every pair of adjacent blocks have different colors.
The problem requires you to read input from standard input and produce output to standard output.
Note: If there is only one block, no move is required.
inputFormat
The input consists of two lines:
- The first line contains an integer n (1 ≤ n ≤ 105), representing the number of blocks.
- The second line contains a string of length n consisting of the characters 'R', 'G', and 'B', representing the initial sequence of blocks.
outputFormat
The output is a single integer on a new line indicating the minimum number of moves required to rearrange the blocks so that no two adjacent blocks have the same color.
## sample5
RGRBB
1