This page is still under construction.

Parts of this page are still being built. What you see may change.

El Dorado

Interview

Time limit1sMemory limit128 MB

Summary
Count the increasing subsequences of length exactly k in a sequence of n distinct numbers, for several test cases.
Level

Medium5 of 10

Topics
Dynamic programming, Array, Combinatorics
Solved
No attempts yet

Problem

A casino game shows a sequence of nn numbers on its screen, and the player must guess how many increasing subsequences of length kk the sequence contains.

A subsequence of a sequence a1,a2,…,ana_1, a_2, \ldots, a_n is any ai1,ai2,…,aila_{i_1}, a_{i_2}, \ldots, a_{i_l} chosen by indices 1≤i1<i2<⋯<il≤n1 \le i_1 < i_2 < \cdots < i_l \le n. Such a subsequence is increasing if aij−1<aija_{i_{j-1}} < a_{i_j} holds for every 1<j≤l1 < j \le l.

Given the sequence shown on the screen, write a program that counts the number of increasing subsequences of length kk.

Input

The input consists of several test cases. The first line of each test case contains two integers nn and kk (1≤k≤n≤1001 \le k \le n \le 100). The second line contains the sequence a1,…,ana_1, \ldots, a_n, whose elements are pairwise distinct (−10000≤ai≤10000-10000 \le a_i \le 10000).

The last line of the input contains two zeros and must not be processed.

Output

For each test case, print the number of increasing subsequences of length kk, one per line. This value fits within the range of a 64-bit integer.

Examples3

  1. Example 1

    Input
    10 5
    1 2 3 4 5 6 7 8 9 10
    3 2
    3 2 1
    0 0
    
    Expected output
    252
    0
    
  2. Example 2

    Input
    5 1
    5 3 1 2 4
    0 0
    
    Expected output
    5
    
  3. Example 3

    Input
    6 6
    1 2 3 4 5 6
    0 0
    
    Expected output
    1