Increasing subsequences of length K

Count length-K index subsequences whose values are strictly increasing, modulo 5,000,000.

Medium7Dynamic programmingSegment treeSortingCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a sequence A1,A2,,ANA_1, A_2, \dots, A_N of length NN and an integer KK. Count the subsequences of AA that have length KK and are increasing.

A subsequence is Ai1,Ai2,,AiKA_{i_1}, A_{i_2}, \dots, A_{i_K} for indices i1<i2<<iKi_1 < i_2 < \dots < i_K. It is increasing when Ai1<Ai2<<AiKA_{i_1} < A_{i_2} < \dots < A_{i_K} holds, so two equal values can never sit next to each other in it. Two subsequences that use different index sets are counted separately even when their values are identical.

Input

The first line contains the length of the sequence NN (1N1000001 \le N \le 100000) and an integer KK (1K501 \le K \le 50, KNK \le N), separated by a space.

The second line contains A1,A2,,ANA_1, A_2, \dots, A_N, separated by spaces. (1Ai1000001 \le A_i \le 100000)

Output

Print the number of increasing subsequences of length KK, modulo 5,000,000, on the first line.