This page is still under construction.

Parts of this page are still being built. What you see may change.

Gift

Time limit2sMemory limit512 MB

Summary
Count sequences of length N that split into blocks where each block is 0,1,...,L-1 with L at most K, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

Karev really likes simple sequences of length at most KK. A simple sequence of length LL is the sequence of the numbers from 00 to L−1L-1 written in this order. For example, {0}\{0\}, {0,1,2,3}\{0,1,2,3\} and {0,1,2,3,4,5,6}\{0,1,2,3,4,5,6\} are simple sequences, while {1}\{1\}, {0,1,3,2}\{0,1,3,2\} and {0,1,3}\{0,1,3\} are not.

Karev's birthday is close, so Polly wants to buy a few simple sequences and concatenate them into an interesting sequence. An interesting sequence is a sequence obtained by concatenating several simple sequences, each of length at most KK. For example, let K=3K=3. Then {0,1,2,0}\{0,1,2,0\}, {0,1,0,1}\{0,1,0,1\}, {0,0,0}\{0,0,0\} and {0,1,2}\{0,1,2\} are interesting sequences, while {0,1,2,3}\{0,1,2,3\}, {0,1,1}\{0,1,1\} and {0,0,2}\{0,0,2\} are not.

Polly has so many sequences to choose from that she cannot decide which one to pick, and she wonders how many choices she really has.

Given KK, the maximum length of a simple sequence Polly can buy, and NN, the length of the interesting sequence she wants to form, write a program that counts the different interesting sequences she could make. This number can be very large, so output it modulo 109+710^9+7.

Input

The first line contains two integers NN and KK, in this order, separated by a space.

Output

Print on the first line the number of different interesting sequences Polly can make, modulo 109+710^9+7.

Constraints

  • 1≤K≤N≤2×1061 \le K \le N \le 2 \times 10^6

Note

For N=4N=4 and K=3K=3 the possible interesting sequences are {0,0,0,0}\{0,0,0,0\}, {0,0,0,1}\{0,0,0,1\}, {0,0,1,0}\{0,0,1,0\}, {0,0,1,2}\{0,0,1,2\}, {0,1,0,0}\{0,1,0,0\}, {0,1,0,1}\{0,1,0,1\} and {0,1,2,0}\{0,1,2,0\}, so the answer is 7.

Examples3

  1. Example 1

    Input
    4 3
    
    Expected output
    7
    
  2. Example 2

    Input
    11 5
    
    Expected output
    912
    
  3. Example 3

    Input
    55 35
    
    Expected output
    377876174