SP12366 TAP2012C - Cantor
Description
\[The original version of this problem (in Spanish) can be found at \]
The mathematician Georg Cantor was a lover of both sets and
Input Format
Each test case is described using a single line. This line contains three integers, **D**, **H** and **B**, and a string **L**. The values of **D** and **H** indicate the endpoints of the closed interval **\[D, H\]** we are interested in (**1 ****H** ****10 $ ^{16} $** ). The value of **B** is the base mentioned in the problem statement (**2** ****B** ****10**). The string **L = L $ _{0} $ L $ _{1} $ ... L $ _{B-1} $** has exactly **B** characters, and describes the set **C** also mentioned in the problem statement. The character **L $ _{i} $** is the uppercase letter **'S'** if **i** is in **C**, and the uppercase letter **'N'** otherwise (**i = 0, 1, ..., B-1**). The set **C** is non-empty, so that there is at least one **'S'** character in **L**. The end of the input is signalled by a line containing three times the number **-1** and a single **'\*'** character.**********
Output Format
For each test case, you should print a single line containing an integer number, representing the number of cantigers (with respect to **B** and **C**) that are greater or equal to **D** and lower or equal to **H**.