Question
New Year’s Colorful Celebrations

As the world welcomes Happy New Year 2026, a grand celebration street is decorated with a long strip of colorful lights. Each light glows in one of three festive colors:

  • R representing Red

  • G representing Green

  • B representing Blue

The lights are arranged in a row, forming a string s of length n.

A celebration segment is considered perfectly colorful if it contains all three colors Red, Green, and Blue at least once.

Your task is to count the number of substrings of the string that form a perfectly colorful celebration.

Input
The first line contains a single integer KaTeX can only parse string typed expression, the length of the string.
The second line contains a string KaTeX can only parse string typed expression of length KaTeX can only parse string typed expression, consisting only of the characters 'R', 'G', and 'B'.
Output
Print a single integer, the number of substrings that contain all three characters 'R', 'G', and 'B'.
Example
Input
5
RGBRG
Output
6
Explanation
Valid substrings containing all three colors are: RGB, RGBR, RGBRG, GBR, GBRG, and BRG. Hence, the total number of perfectly colorful substrings is 5.

Online