Expand the Path solution codeforces – Count the number of cells such that there exists at least one sequence of modifications that the robot visits this cell on the modified path and doesn’t move outside the grid.

Expand the Path solution codeforces

Consider a grid of size 𝑛×𝑛n×n. The rows are numbered top to bottom from 11 to 𝑛n, the columns are numbered left to right from 11 to 𝑛n.

The robot is positioned in a cell (1,1)(1,1). It can perform two types of moves:

  • D — move one cell down;
  • R — move one cell right.

The robot is not allowed to move outside the grid.

You are given a sequence of moves 𝑠s — the initial path of the robot. This path doesn’t lead the robot outside the grid.

You are allowed to perform an arbitrary number of modifications to it (possibly, zero). With one modification, you can duplicate one move in the sequence. That is, replace a single occurrence of D with DD or a single occurrence of R with RR.

Count the number of cells such that there exists at least one sequence of modifications that the robot visits this cell on the modified path and doesn’t move outside the grid.

Expand the Path solution codeforces

Input

The first line contains two integers 𝑛n and 𝑝p (1𝑛,𝑝2105)(1≤n,p≤2⋅105).

The second line contains 𝑛n integers 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an (1𝑎𝑖109)(1≤ai≤109).

It is guaranteed that all the numbers in 𝑎a are distinct.

Output

Print a single integer, the number of elements in 𝑆S that are strictly smaller than 2𝑝2p. Remember to print it modulo 109+7109+7.

Examples

input

Copy
2 4
6 1

output

Copy
9

input

Copy
4 7
20 39 5 200

output

Copy
14

input

Copy
2 200000
48763 1000000000

output

Copy
448201910
Note

In the first example, the elements smaller than 2424 are {1,3,4,6,7,9,12,13,15}{1,3,4,6,7,9,12,13,15}.

In the second example, the elements smaller than 2727 are {5,11,20,23,39,41,44,47,79,80,83,89,92,95}{5,11,20,23,39,41,44,47,79,80,83,89,92,95}.

 

Expand the Path solution codeforces

13
9
3
Note

In the first testcase, it’s enough to consider the following modified paths:

  • RD  RRD  RRRD  RRRDD  RRRDDD — this path visits cells (1,1)(1,1)(1,2)(1,2)(1,3)(1,3)(1,4)(1,4)(2,4)(2,4)(3,4)(3,4) and (4,4)(4,4);
  • RD  RRD  RRDD  RRDDD — this path visits cells (1,1)(1,1)(1,2)(1,2)(1,3)(1,3)(2,3)(2,3)(3,3)(3,3) and (4,3)(4,3);
  • RD  RDD  RDDD — this path visits cells (1,1)(1,1)(1,2)(1,2)(2,2)(2,2)(3,2)(3,2) and (4,2)(4,2).

Thus, the cells that are visited on at least one modified path are: (1,1)(1,1)(1,2)(1,2)(1,3)(1,3)(1,4)(1,4)(2,2)(2,2)(2,3)(2,3)(2,4)(2,4)(3,2)(3,2)(3,3)(3,3)(3,4)(3,4)(4,2)(4,2)(4,3)(4,3) and (4,4)(4,4).

In the second testcase, there is no way to modify the sequence without moving the robot outside the grid. So the only visited cells are the ones that are visited on the path DRDRDRDR.

In the third testcase, the cells that are visited on at least one modified path are: (1,1)(1,1)(2,1)(2,1) and (3,1)(3,1).

Leave a Comment