loj#P6696. 复读机 加强版

复读机 加强版

Description

We call a sequence aa good iff 1aik(1in)1\le a_i\le k(1\le i\le n) and for all xx, the occurrences of xx in aa is a multiple of dd. Please count the number of good sequences. Since the answer could be extremely large, you just need to calculate it modulo 1949100119491001.

Input Format

One line with three positive integers n,k,dn,k,d.

Output Format

Output one integer which is the answer modulo 1949100119491001.

8 3 4
213
12 4 6
5548

Limits

For 50%50\% of the testcases, d=4,k2×103d = 4, k\le 2\times 10^3.

For the rest 50%50\% of the testcases, d=6,k103d = 6, k\le 10^3.

It's guaranteed that n109n\le 10^9.