NOI Contest Archive

Archive / 2022 / Selection Test

Kill Team Go

Medium · National Olympiad in Informatics Sri Lanka - Screening Test 2022

Amanda Waller is assembling her “Suicide Squad”. The given roster of players contains Gamma players denoted by “G” that specialize in muscle-power, and Beta players denoted by “B” that specialize in planning. Waller can form a squad by picking a contiguous set of players from the roster while maintaining the original order.

The squad can further break itself into sub-squads. The size of a sub-squad, ranges from a minimum of 2 to the size of the entire squad, and in a sub-squad, the order must be flippable without making a difference to the structure. In other words, the order of specialty of a sub-squad must be a palindrome. For a selected squad to be an ideal squad, every member should be a part of at least one such sub-squad.

How many different ideal squads can Waller form from the given roster?

Note that when forming the squads, the initial order of players should never be altered. Check the explanation given below.

Input Format

Output Format

Constraints

Limits

Sample Input 0

5
GGGBB

Sample Output 0

6

Sample Input 1

5
GGBBG

Sample Output 1

5