Anarchy Acres

Time limit: 1s Memory limit: 512MB Input: Output:

Task

After spending a fortnight in Anarchy Acres you have come upon the problem of John's Porks.
Farmer John's farm has been in anarchy ever since he bought his nn naughty pigs. To bring back order, he has decided to turn exactly kk of them into officer pigs and hopes they will keep the rest in line. But not every choice of officers will lead to order on the farm.
We know the following:

  • the pigs are all arranged in a line in a fixed order
  • oio_i = the quantity of oats that pig number ii gets fed in a day
  • in order to have a chance at order, the first and last pig must be turned into officers
  • having order on the farm means all pigs are well-behaved

We also know that pigs are simple minded creatures, so they only notice the closest officer to their left and the closest to their right. And since pigs are so simple we can predict their behavior based on the following rules:

  • an officer pig will always be well-behaved
  • if a naughty pig gets strictly less oats than each of the two officers it sees, he will call this a systemic injustice and start a rebellion (will not be well-behaved)
  • if a naughty pig gets strictly more oats than each of the two officers it sees, he will feel that he is above the law and start comitting crimes (will not be well-behaved)
  • otherwise the naughty pig will be well-behaved

Help John by finding out how many ways of choosing kk officers will lead to order on his farm.

Two ways of choosing officers are considered different if there exists a pig chosen as officer in one but not in the other.

Input data

The first line of the input contains two positive integers nn (1n21051 \le n \le 2 \cdot 10^5), representing the total number of pigs, and kk (1k1001 \le k \le 100) representing the number of officer pigs.
The second line of the input contains nn integers o1o_1, o2o_2, o3o_3, ..., ono_n (1oi1091 \le o_i \le 10^9)

Output data

Let MM be the number of arrays p1p_1, p2p_2, p3p_3, ..., pkp_k such that:

  • p1p_1 = 11
  • pkp_k = nn
  • min(opi,opi+1)ojmax(opi,opi+1)\min(o_{p_i}, o_{p_{i + 1}}) \le o_j \le \max(o_{p_i}, o_{p_{i + 1}}), for all ii (1i<k1 \le i \lt k) and jj (pi<j<pi+1p_i \lt j \lt p_{i + 1})

Print the value of MM modulo 109+710^9 + 7.

Example 1

stdin

10 7
3 15 3 19 3 3 8 20 7 2 

stdout

6

Explanation

There are 66 ways to choose 77 officers:

  • 11 22 33 44 55 88 1010;
  • 11 22 33 44 66 88 1010;
  • 11 44 55 66 77 88 1010;
  • 11 44 55 66 88 99 1010;
  • 11 44 55 77 88 99 1010;
  • 11 44 66 77 88 99 1010.

Example 2

stdin

14 8
14 7 13 13 11 12 2 10 11 9 4 7 3 11 

stdout

8

Explanation

There are 88 ways to choose 88 officers:

  • 11 22 33 44 55 66 77 1414;
  • 11 22 33 44 77 99 1313 1414;
  • 11 22 33 77 88 99 1313 1414;
  • 11 22 33 77 99 1010 1313 1414;
  • 11 22 44 77 88 99 1313 1414;
  • 11 22 44 77 99 1010 1313 1414;
  • 11 77 88 99 1111 1212 1313 1414;
  • 11 77 99 1010 1111 1212 1313 1414.

Example 3

stdin

15 8
5 19 8 7 7 19 19 15 10 11 9 10 9 10 2 

stdout

66

Log in or sign up to be able to send submissions!