Under construction

Still being built. Things may change

Number of NKD Sequences

Time limit2sMemory limit512 MB

Summary
Count length-K strictly increasing sequences summing to N where consecutive differences are at most D and the first term is at most D, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math, Sliding window
Solved
No attempts yet

Problem

You are given three integers NN, KK, and DD. Count the natural-number sequences A1,A2,…,AKA_1, A_2, \dots, A_K of length KK that satisfy all of the following conditions.

  • A1+A2+⋯+AK=NA_1 + A_2 + \dots + A_K = N
  • A1<A2<⋯<AKA_1 < A_2 < \dots < A_K
  • For every 1≤i<K1 \le i < K, Ai+1−Ai≤DA_{i+1} - A_i \le D
  • A1≤DA_1 \le D

Input

The first line contains three integers NN, KK, and DD, separated by spaces.

Output

Print the number of sequences satisfying the conditions, modulo 109+710^9 + 7.

Constraints

  • 1≤N,K,D≤1051 \le N, K, D \le 10^5

Examples1

  1. Example 1

    Input
    10 4 1
    
    Expected output
    1