Dice Game Win Probability

A token moves on states 0 to N, stepping down with probability Q/P and up otherwise; find the probability of ending at N and print it modulo 1e9+7 as a reduced fraction.

Medium6Dynamic programmingProbabilityMathInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

You roll a PP-sided die. Each face has one integer from 11 to PP written on it, and every face comes up with the same probability on a single roll.

You play the following game.

  • You start holding the number KK.
  • If the number you hold is 00 or NN, the game ends.
  • Otherwise you roll the die once. If the rolled number is at most QQ, subtract 11 from the number you hold. If it is greater than QQ, add 11. Then go back to the second rule and repeat.

Write a program that computes the probability that the number you hold when the game ends is NN.

Input

The first line contains the integer PP. (1P1001 \le P \le 100)

The second line contains the integer QQ. (0QP0 \le Q \le P)

The third line contains the integer NN. (1N1001 \le N \le 100)

The fourth line contains the integer KK. (0KN0 \le K \le N)

Output

Print the probability that the number you hold when the game ends is NN. For exact judging, write the answer as a reduced fraction a/ba/b and print (a×b1)mod1,000,000,007(a \times b^{-1}) \bmod 1{,}000{,}000{,}007 instead. Here b1b^{-1} is the modular multiplicative inverse of bb modulo 1,000,000,0071{,}000{,}000{,}007. The answer exists for every input that can be given.