Under construction

Still being built. Things may change

Master of Permutation Construction

Time limit2sMemory limit1024 MB

Summary
Count permutations P of length N (up to 5000) so that B = (A_P1, ..., A_PN) has at most K strict left-to-right maxima, modulo 1,000,000,007.
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Sorting
Solved
No attempts yet

Problem

Master of Array Construction Jiro wants to count the permutations PP of length NN that satisfy the conditions below, given a sequence AA of length NN. A permutation PP of length NN is a sequence that uses each integer from 11 to NN exactly once.

  • Sequence BB is defined as (AP1,AP2,…,APN)(A_{P_1}, A_{P_2}, \ldots, A_{P_N}).
  • The annoyance of BB is the number of integers ii with 1≤i≤N1 \le i \le N that satisfy the following condition.
    • i=1i=1 or max⁡(B1,…,Bi−1)<Bi\max(B_1, \ldots, B_{i-1}) < B_i
  • The annoyance of BB is at most KK.

Find the number of permutations PP that satisfy the conditions, modulo 1 000 000 0071\,000\,000\,007.

Input

The first line contains NN and KK, separated by a space. (1≤N≤5 0001 \le N \le 5\,000, 1≤K≤N1 \le K \le N)

The second line contains the sequence A1,A2,…,ANA_1, A_2, \ldots, A_N, separated by spaces. (1≤Ai≤1091 \le A_i \le 10^9)

Output

Print the number of permutations PP that satisfy the conditions, modulo 1 000 000 0071\,000\,000\,007.

Examples2

  1. Example 1

    Input
    3 3
    1 2 3
    
    Expected output
    6
    
  2. Example 2

    Input
    4 2
    1 1 2 2
    
    Expected output
    24