Mock CCC '24 Contest 1 J3 - RGB Words
View as PDFTommy likes the RGB keyboard. He would like to see how many RGB-words are in a given string . An RGB-word is defined as a substring that starts with an 
R and ends with a B, and between this R and the B letter G appears exactly once. For example, RGB, and RAGB are RGB-words. However, RGGB is not an RGB-word. You are given a string , Tommy would like to know how many RGB-words are there in the string, can you write a program to help him?
Input Specification
The first line contains an integer , denoting the length of the given string 
.
The second line contains the given string , consisting of only capital English letters.
The following table shows how the available  marks are distributed.
| Marks Awarded | |
|---|---|
Output Specification
The first and only line of output contains a single integer, representing the number of RGB-words found in the given string .
Sample Input 1
4
RBGB
Sample Output 1
1
Explanation for Sample 1
RBGB is the only RGB-word that occurs in this case. Note that RB is not an RGB-word.
Sample Input 2
5
RGBAB
Sample Output 2
2
Explanation for Sample 2
RGB and RGBAB are RGB-words. Thus, there are a total of  RGB-words in the given string 
.
Sample Input 3
4
RGGB
Sample Output 3
0
Comments
Be sure to test hard ones like RRGBB and RGRGB.
Is there a way to solve this with regular expressions?