#K74692. Minimum Removals for Forbidden Substrings

    ID: 34254 Type: Default 1000ms 256MiB

Minimum Removals for Forbidden Substrings

Minimum Removals for Forbidden Substrings

Given a string S consisting solely of the characters R, G, and B, your task is to determine the minimum number of characters that must be removed so that no forbidden adjacent pairs remain.

A forbidden adjacent pair is defined as follows:

  • If a character R is immediately followed by either G or B.
  • If a character G is immediately followed by either R or B.
  • If a character B is immediately followed by either R or G.

Whenever a forbidden pair is encountered, one removal is counted and the next character in the pair is skipped. The goal is to achieve a string in which every pair of consecutive characters does not form any of the above forbidden combinations.

Example: For the input string RGBG, the minimal number of removals is 2.

inputFormat

The input consists of a single string S on one line, where S contains only the characters 'R', 'G', and 'B'.

outputFormat

Output a single integer representing the minimum number of removals required to eliminate all forbidden adjacent pairs.

## sample
RGBG
2