Under construction

Still being built. Things may change

Traces of Binary Search

Time limit1sMemory limit1024 MB

Summary
Given N and a binary search trace of probed values, count the strictly increasing arrays with values from 1 to 100 that produce that exact trace, modulo 10^9+7.
Level

Medium6 of 10

Topics
Binary search, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

Geon-i and Junseong play a game with a sorted array A=[a1,a2,⋯ ,aN]A = [a_1, a_2, \cdots, a_N] of length NN. Junseong picks one element of the array at random. The answer range is the range of indices where the element Junseong picked could be, and it starts as [1,N][1, N].

Geon-i can pick an element in the current answer range and ask whether the number he is thinking of is that element. Junseong answers with one of Yes, Up, or Down. Junseong does not lie, and the game ends when Junseong answers Yes. The sequence [t1,t2,⋯ ,tK][t_1, t_2, \cdots, t_K] of the KK elements Geon-i asked, in order, is called the trace of binary search.

Geon-i always makes the best choice in every game, so when the answer range is [s,e][s, e], he always asks about as+⌊e−s2⌋a_{s + \left\lfloor \frac{e-s}{2} \right\rfloor}.

  • If Junseong answers Up, the next range is [s+⌊e−s2⌋+1,e][s + \left\lfloor \frac{e-s}{2} \right\rfloor + 1, e].
  • If Junseong answers Down, the next range is [s,s+⌊e−s2⌋−1][s, s + \left\lfloor \frac{e-s}{2} \right\rfloor - 1].

Given a trace of binary search, print the number of arrays AA that could produce it.

Input

The first line contains the size NN of the array and the size KK of the trace, separated by a space.

The second line contains the integers t1,t2,⋯ ,tKt_1, t_2, \cdots, t_K that make up the trace, separated by spaces.

Output

Print the number of possible arrays AA, modulo 109+710^9 + 7.

Constraints

  • 1≤N≤1001 \le N \le 100
  • 1≤K≤⌊log⁡2N⌋+11 \le K \le \lfloor \log_2{N} \rfloor + 1
  • 1≤a1<a2<⋯<aN≤1001 \le a_1 < a_2 < \cdots < a_N \le 100
  • 1≤ti≤1001 \le t_i \le 100
  • For all i≠ji \neq j, ti≠tjt_i \neq t_j
  • 1≤i,j≤K1 \le i, j \le K
  • Only traces for which at least one possible array AA exists are given as input.

Examples2

  1. Example 1

    Input
    3 1
    50
    
    Expected output
    2450
    
  2. Example 2

    Input
    5 3
    48 21 31
    
    Expected output
    1326