beecrowd | 1242

Alien Ribonucleic Acid

Maratona de Programação da SBC Brazil

Timelimit: 1

An alien kind of ribonucleic acid (popularly known as RNA) Was discovered. Scientists, for lack of criativity, have named the discovery of alien ribonucleic acid (RNAA). Similar to RNA we know, the RNAA is a ribbon composed of several bases. The bases are C F B S and may connect in pairs. The only possible pairs are between the bases B and S and the bases C and F.
While active, the RNAA fold various intervals of the tape around itself, making connections between its bases. Scientists realized that:

When a range of the RNAA tape bend, all the bases in this range will bind to its corresponding bases:
- Each base can bind to only one other base:
- The folds occur to maximize the number of calls made on ribbons

The images below illustrate folds and connections made on tapes.

Your task is, given the description of a strip of RNAA, determine how many connections are made ​​between their bases if the strip becomes active.


The input consists of several test cases and ends with EOF. Each test case has a line describing the sequence of bases of the RNAA stripe. A RNAA stripe contains at least one and at most 300 bases. There are no blanks between bases of a tape. The bases are 'B', 'C', 'F' and 'S'.


For each test case print a line containing the total number of connections that occurs when the tape is actived.

Sample Input Sample Output