Woburn Challenge 2017-18 Finals Round - Junior Division
After capturing and interrogating all of the alien spies from within the cow army, Bo Vine has learned of the Party of Extraterrestrial Gangsters' plans for an imminent invasion of Earth. An important realization then dawned on him — now is not the time to engage in petty quarrels with the monkeys. All of Scarberia must join forces, at least temporarily, to face an even greater evil. Knowing this, Bo Vine approached the Head-Monkey seeking a truce. After a long night of negotiation, the stubborn Head-Monkey at last admitted to the gravity of the situation. Both the cows and monkeys thus decided to unite their armies against the fearsome PEG!
Now, Bo Vine and the Head-Monkey must discuss battle formations for each
of their battalions. To keep it simple, they have both decided to stick
with a standard line formation, organized into platoons of cows and
monkeys in sequence. In their discussion, they will denote each possible
battle formation as a non-empty string C
or M
, denoting either a
cow platoon or a monkey platoon, respectively. Of course, the big
question is: what is the best possible arrangement of platoons?
The aliens of PEG are a mysterious bunch. Bo Vine and the Head-Monkey
know that they should be prepared to face all kinds of battle styles. As
such, it is certainly a good idea to maximize variety in the formation
they choose. Just what does this mean? For a given cow-monkey formation
Given a particular formation of cow-monkey platoons that Bo Vine and the Head-Monkey are considering, can you help them count the number of redundant sub-formations?
Subtasks
In test cases worth
Input Specification
The first and only line of input consists of a single string,
Output Specification
Output a single line consisting of a single integer, the number of redundant sub-formations.
Sample Input
CCCMMCMMCMM
Sample Output
7
Sample Explanation
The redundant sub-formations are CC
, CMMC
, CMMCM
,
CMMCMM
, MMCM
, MMCMM
, and MCMM
. For example, CC
is
redundant because it appears in
Comments