Subsets

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given the set {1,2,,n}\{1, 2, \ldots, n\} and an integer xx with x>1x > 1. Consider the subsets PP of this set with the following property: for every natural number yy, the numbers yy and xyx \cdot y are never both in PP at the same time. In other words, for any yy, at least one of yy and xyx \cdot y is missing from PP.

Count how many such subsets contain exactly kk elements. This number can be very large, so output its remainder modulo mm.

Input

A single line contains four integers nn, mm, kk, and xx, separated by single spaces.

  • 1n10181 \le n \le 10^{18}
  • 2m1062 \le m \le 10^6
  • 0k10000 \le k \le 1000
  • 2x102 \le x \le 10

Output

Print, on a single line, the number of kk-element subsets satisfying the condition, taken modulo mm.

Note

For n=6n = 6, k=3k = 3, and x=2x = 2, the 99 subsets that satisfy the condition are: {1,3,4}\{1, 3, 4\}, {1,3,5}\{1, 3, 5\}, {1,4,5}\{1, 4, 5\}, {1,4,6}\{1, 4, 6\}, {1,5,6}\{1, 5, 6\}, {2,3,5}\{2, 3, 5\}, {2,5,6}\{2, 5, 6\}, {3,4,5}\{3, 4, 5\}, {4,5,6}\{4, 5, 6\}.