QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#2034. Coin Flipping

الإحصائيات

A coin has a probability of $a/b$ of landing on heads (H) and a probability of $1-a/b$ of landing on tails (T). Now, a child named TT starts playing a coin-tossing game and records the result of each toss, denoting heads as H and tails as T, resulting in a sequence like HTHHT.... She suddenly wonders: if the probability of heads and tails is $1/2$, how many tosses are expected to see the target sequence HT? After thinking for a second, she realizes that if the first toss is T, she still needs the expected number of tosses to get HT; if the first toss is H, she only needs the expected number of tosses to get T, which is clearly 2. Letting $x$ be the expected number of tosses to get HT, she obtains the equation: $$x=1+(1/2 \cdot x + 1/2 \cdot 2)$$ Solving this gives $x=4$, so the expected number of tosses to get HT is 4.

After solving this simplified problem, she begins to think about the general case where the probabilities of heads and tails are not necessarily equal, and the target sequence is not necessarily HT. However, after a long period of deep thought, she remains stuck, so she turns to you for help.

Input

The first line contains two integers $a$ and $b$, with meanings as described above. The next line contains a string $S$ consisting only of 'H' and 'T', representing the target sequence.

Output

Output a single line in the format $p/q$, where $p$ and $q$ are coprime positive integers representing the expected number of tosses required to obtain the target sequence $S$. Note: If $q$ is 1, do not omit the $/1$.

Examples

Input 1

1 2
HT

Output 1

4/1

Note

See the problem description.

Constraints

$a$ $b$ $ S $
1 $=1$ $=2$ $=3$
2 $=1$ $=2$ $=3$
3 $=1$ $=2$ $\le 10$
4 $=1$ $=2$ $\le 20$
5 $ $\le 10$ $\le 15$
6 $ $\le 30$ $\le 50$
7 $ $\le 50$ $\le 100$
8 $ $\le 100$ $\le 300$
9 $ $\le 100$ $\le 500$
10 $ $\le 100$ $\le 1000$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.