PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000086. Đếm dãy con tăng độ dài K (Increasing Subsequences)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm dãy con tăng độ dài K (Increasing Subsequences)

Increasing Subsequences

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer sequence S1,S2,…,SNS_1,S_2,\ldots,S_N and an integer KK, a subsequence of length exactly KK is specified by indices

1≤i1<i2<⋯<iK≤N.1\le i_1<i_2<\cdots<i_K\le N.

It is valid if Si1<Si2<⋯<SiKS_{i_1}<S_{i_2}<\cdots<S_{i_K}. Subsequences with identical value sequences but different chosen positions count separately.

Count the strictly increasing subsequences of length KK, and print the result modulo 5 000 0005\,000\,000.

Input

The first line contains integers N,KN,K.

Exactly NN more lines follow; line ii contains one integer SiS_i.

Output

Print one integer between 00 and 4 999 9994\,999\,999: the count modulo 5 000 0005\,000\,000.

Subtasks

  • Subtask 1 (20 points): 1≤N≤91\le N\le 9; 1≤K≤min⁡(50,N)1\le K\le\min(50,N); 0≤Si<1000000\le S_i<100000 for every ii.
  • Subtask 2 (30 points): 1≤N≤5001\le N\le 500; 1≤K≤min⁡(50,N)1\le K\le\min(50,N); 0≤Si<1000000\le S_i<100000 for every ii.
  • Subtask 3 (50 points): 1≤N≤100001\le N\le 10000; 1≤K≤min⁡(50,N)1\le K\le\min(50,N); 0≤Si<1000000\le S_i<100000 for every ii.

Examples

Input

4 3
1
2
2
10

Output

2

Explanation

We must choose three positions with strictly increasing values. Exactly two choices work: indices (1,2,4)(1,2,4) and (1,3,4)(1,3,4). Both yield the values (1,2,10)(1,2,10), but count separately because the value 22 comes from different positions.

The two occurrences of value 22 cannot be selected together. The count is 2 mod 5 000 000=22\bmod5\,000\,000=2.