Honest Chain
In the underground burrows of the valley near the cliffs of Kreid-Moor, two tribes of dwarves lived in peace and harmony for many years. Both tribes worked in the mines, extracting precious stones. The first tribe exclusively mined emeralds, while the second tribe mined rubies. One day, to celebrate the great festival of Fairwind, the dwarves decided to present their goddess Mirabel with a necklace made of emeralds and rubies. The finest blacksmiths from both tribes collaborated to create this necklace, carefully assembling the precious stones one by one. Once the necklace was completed, the tribe leaders decided to count the stones of each type. They realized that if there were fewer stones of one type, the goddess might turn away from the tribe that appeared stingy. To prevent this, they decided to present a non-empty fragment of the necklace (i.e., a sequence of consecutive stones from the necklace) that contained an equal number of rubies and emeralds. There might be several ways to achieve this. To determine how many such ways exist, the dwarves have sought your assistance.
Write a program to find the number of ways to select the required fragment.
Input
A single line contains the sequence of stones in the necklace: the symbol E represents an emerald, and the symbol R represents a ruby. The sequence contains no more than 500000 symbols.
Output
Output the number of ways to choose a fragment with an equal number of emeralds and rubies.