Numbers in a range

3.3

9 votes
Combinatorics, Math
Problem

You are given three integers lr, and n. You are also given an array of integers a[1],a[2],...,a[n1] of size n1.

Determine the possible number of ways of selecting n integers x1,x2,...,xn from the range [l,r] such that the selected integers are in strictly increasing order (from left to right).

Note

  •  xi+1xia[i]  1i<n
  • Output must be printed as modulo 1000000007

Input format

  • First line: Three space-separated integers lr, and n
  • Second-line: n1 space-separated integers a[1..n1]

Output format

Print the possible number of ways of selecting n integers x1,x2,...,xn.

Constraints

106lr1062n1060a[i]109

Sample Input
1 6 2
3
Sample Output
6
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The possible solutions for (x1,x2) are (1,4),(1,5),(1,6),(2,5),(2,6),(3,6).

Editor Image

?