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

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

HỌC THEO LỘ TRÌNH

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

2 lộ trình

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

Subsequences

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a permutation of 1,2,…,n1,2,\ldots,n, count ways to choose exactly k+1k+1 increasing indices whose corresponding values are strictly increasing. Different index selections count separately. The answer is guaranteed not to exceed 8⋅10188\cdot 10^{18}.

Input

The first line contains integers n,kn,k. Exactly nn integers a1,…,ana_1,\ldots,a_n follow (possibly on separate lines), forming a permutation of 1,…,n1,\ldots,n.

Output

Print one 64-bit integer: the number of strictly increasing subsequences of length exactly k+1k+1. Do not take a modulus.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 0≤k≤100\le k\le 10; the sequence a1,…,ana_1,\ldots,a_n is a permutation of 1,2,…,n1,2,\ldots,n; the number of target subsequences does not exceed 8⋅10188\cdot 10^{18}.
  • Subtask 2 (30 points): 1≤n≤16001\le n\le 1600; 0≤k≤100\le k\le 10; the sequence a1,…,ana_1,\ldots,a_n is a permutation of 1,2,…,n1,2,\ldots,n; the number of target subsequences does not exceed 8⋅10188\cdot 10^{18}.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤k≤100\le k\le 10; the sequence a1,…,ana_1,\ldots,a_n is a permutation of 1,2,…,n1,2,\ldots,n; the number of target subsequences does not exceed 8⋅10188\cdot 10^{18}.

Examples

Input

5 2
1
2
3
5
4

Output

7

Explanation

We need strictly increasing subsequences of length k+1=3k+1=3. The seven value triples are (1,2,3)(1,2,3), (1,2,5)(1,2,5), (1,2,4)(1,2,4), (1,3,5)(1,3,5), (1,3,4)(1,3,4), (2,3,5)(2,3,5), and (2,3,4)(2,3,4). A selection containing 55 followed by 44 is not increasing.