Mex division

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Given an array A of n nonnegative integers. Find the number of ways to partition/divide the array into subarrays, such that mex in each subarray is not more than k. For example, mex of the arrays [1, 2] will be 0, and that of [0, 2] will be 1, and that of [0, 1, 2] will be 3. Due to the fact that the answer can turn out to be quite large, calculate it modulo 10^{9} + 7.
Input
 The first line of the input contains two integers n, k denoting the number of elements and limit of mex.
 The second line contains n spaceseparated integers A_{1}, A_{2}, ... , A_{n} .
Output
 Output a single integer corresponding to the answer of the problem.
Constraints
 1 ≤ n ≤ 5 * 10^{5}
 0 ≤ k, A[i] ≤ 10^{9}
Example
Input: 3 1 0 1 2 Output: 2
Input: 10 3 0 1 2 3 4 0 1 2 5 3 Output: 379
Explanation
Example 1. The valid ways of partitioning will be 0], [1, 2 (mex of first subarray is 1, while that of the second is zero), and 0], [1], [2 (mex of first subarray is 1, and that of others is 0). There is no other way to partition the array such that mex is less than or equal to 1. For example, 0, 1], [2 is not a valid partitioning as mex of first subarray is 2 which is more than 1.
Author:  gomelfk 
Tags  gomelfk 
Date Added:  2062017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 