#P5224. JerryC's Candy Box Selection

    ID: 18460 Type: Default 1000ms 256MiB

JerryC's Candy Box Selection

JerryC's Candy Box Selection

JerryC has N distinct boxes of candies. Initially, he planned to choose exactly M boxes, but then he decided he wanted even more. Since he likes the number K, he will be satisfied if the total number of boxes chosen, x (with x \ge M), satisfies

$$x \equiv M \pmod{K}$$

Your task is to compute the number of ways to choose boxes (i.e. the number of subsets of boxes) such that the number of boxes chosen x satisfies the condition above. Since the answer can be large, output it modulo 1004535809.

The answer is given by summing up binomial coefficients:

$$\text{Answer} = \sum_{r \ge 0 \;\text{and}\; M + rK \le N} \binom{N}{M + rK} \bmod 1004535809$$

inputFormat

The input consists of a single line containing three integers N, M, and K separated by spaces.

Constraints (implicit): 0 ≤ M ≤ N.

outputFormat

Output a single integer: the number of ways to choose boxes such that the total number of boxes chosen x (with x \ge M) satisfies x \equiv M \pmod{K}, modulo 1004535809.

sample

5 1 2
16