This page is still under construction.

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

Just a bit sorted

Time limit3sMemory limit256 MB

Summary
For each query bound K, count length-N lists with values 1 to K where each value above 1 has its predecessor before its last occurrence.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Math
Solved
No attempts yet

Problem

Jurgen Guntherswarchzhaffenstrassen is known for his guitar playing and for the harsh way he teaches his students. Most people miss one more thing about him. He also likes numbers.

Jurgen has been studying sorted lists lately, and he got bored. Sorted lists are too predictable and there are too few of them, so he changed the rule a little.

Take a list ℓ\ell of NN positive integers. The elements do not have to be distinct. Jurgen calls ℓ\ell just a bit sorted if for every integer x>1x > 1 that occurs in ℓ\ell, the value x−1x-1 occurs at least once before the last occurrence of xx in ℓ\ell. For example:

  • [2,3,1,2][2, 3, 1, 2] is just a bit sorted, because a 1 stands before the last 2 and a 2 stands before the last 3.
  • [2,3,4,3,2,1,3,4][2, 3, 4, 3, 2, 1, 3, 4] is not just a bit sorted, because every 1 stands after the last 2.
  • [1,1,3,1,3,3,1,3][1, 1, 3, 1, 3, 3, 1, 3] is not just a bit sorted, because no 2 stands before the last 3. This list has no 2 at all.

Jurgen wants to know how many different just a bit sorted lists of NN positive integers not greater than KK exist. Two lists are different if they differ in at least one position. Count them for him.

Input

The first line contains the length NN of the lists and the number QQ of queries (1≤N≤50001 \le N \le 5000, 1≤Q≤10001 \le Q \le 1000). The second line contains the integers K1,K2,…,KQK_1, K_2, \dots, K_Q. The lists counted in the ii-th query contain no value greater than KiK_i (1≤Ki≤1091 \le K_i \le 10^9).

Output

Print one line with QQ integers separated by single spaces. The ii-th integer is the number of different just a bit sorted lists of NN positive integers not greater than KiK_i. This number can be very large, so print it modulo 109+710^9+7.

Examples3

  1. Example 1

    Input
    1 1
    1
    
    Expected output
    1
    
  2. Example 2

    Input
    3 4
    2 2 1 10
    
    Expected output
    5 5 1 6
    
  3. Example 3

    Input
    1000 3
    100 5 300
    
    Expected output
    265428620 285047952 668355714