Under construction

Still being built. Things may change

Changho's Preparation for Study Abroad

Time limit2sMemory limit1024 MB

Summary
Count the study sequences of length N over X words where each of the Y well-known words never repeats Z or more times in a row, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Matrix
Solved
No attempts yet

문제

Changho is preparing to study abroad and has been focusing on foreign language study lately. Jaewoo wanted to help, so he gave Changho a list of XX distinct foreign words. However, YY of the words on the list were already well known to Changho. Changho calls these words Well-Known words. To study efficiently, Changho set his own rule: for Well-Known words, he will not study the same word ZZ or more times in a row. After hearing this rule, Jaewoo became curious about the total number of ways Changho can study the words on the list.

Each study session covers exactly one word. Given the number of study sessions NN, the number of words XX on the list, the number of Well-Known words YY, and the limit ZZ, find the total number of ways Changho can study the words on the list. The same word may be studied many times, and some words may never be studied.

입력

The first line contains four integers NN (1≤N≤10181 \leq N \leq 10^{18}), XX (1≤X≤10181 \leq X \leq 10^{18}), YY (1≤Y≤X1 \leq Y \leq X), and ZZ (1≤Z≤1031 \leq Z \leq 10^{3}), separated by spaces.

출력

Print the total number of ways Changho can study the words on the list, modulo 1 000 000 0071\,000\,000\,007, because the answer can be large.

Examples3

  1. Example 1

    Input
    2 3 2 2
    
    Expected output
    7
    
  2. Example 2

    Input
    10 3 2 3
    
    Expected output
    36559
    
  3. Example 3

    Input
    16 5 2 4
    
    Expected output
    455819708