Equations in Permutations#2438

Equations in Permutations

1 second
256 megabytes
Easy

Let be a fixed natural number. We will define an unusual mapping on the set of permutations of the first natural numbers. Consider a permutation x = (x_1, x_2, \ldots, x_n). From this, we will construct another permutation y = (y_1, y_2, \ldots, y_n) as follows: set y_1 = 1. For each i > 1, if z = x_{y_{i-1}} is not in the set Y_{i-1} = \{y_1, \ldots, y_{i-1}\}, then let y_i = z. Otherwise, y_i will be the smallest natural number not in Y_{i-1}. We call the permutation the image of permutation under the mapping , i.e., f(x) = y. This completes the construction of the mapping.

Let represent the number of solutions to the equation f(x) = y, which is the count of permutations for which f(x) = y. Now, for the task: given non-negative integers and , determine the number of permutations such that L \leq g(y) \leq R. Since the result can be large, provide the answer modulo 10^9+9.

Input

The first line of the input contains natural numbers n \leq 10^5 and T \leq 1000, which represent the length of the permutation and the number of pairs , to be processed for the given . Each of the following lines contains non-negative integers , R \leq 10^{18}.

Output

For each pair , from the input, output on a separate line the remainder when divided by 10^9+9 of the number of permutations of length such that L \leq g(y) \leq R.

Examples

Example 1

Loading
Loading