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

#QHD0000017. Mô tả mảng (Array Description)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mô tả mảng (Array Description)

Array Description

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Complete an array of nn elements, each an integer between 11 and mm. Adjacent elements must differ by at most one: ∣ai−ai−1∣≤1|a_i-a_{i-1}|\le1 for 2≤i≤n2\le i\le n.

Some positions already have fixed values. Unknown positions are represented by 00 and may be assigned any integer in [1,m][1,m]. Fixed positions cannot be changed.

Count all distinct completed arrays satisfying these conditions, modulo 109+710^9+7.

Input

The first line contains nn and mm, the array length and maximum allowed element.

The second line contains nn integers. A zero represents an unknown position, and a nonzero value is fixed.

Output

Print the number of valid arrays modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤m≤1001\le m\le 100; 0≤ai≤m0\le a_i\le m.
  • Subtask 2 (30 points): 1≤n≤5001\le n\le 500; 1≤m≤1001\le m\le 100; 0≤ai≤m0\le a_i\le m.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; 1≤m≤1001\le m\le 100; 0≤ai≤m0\le a_i\le m.

Examples

Input

3 5
2 0 2

Output

3

Explanation

The first and third entries are fixed at 22. The middle entry must differ by at most 11 from both, so it can only be 11, 22, or 33. The three valid arrays are (2,1,2)(2,1,2), (2,2,2)(2,2,2), and (2,3,2)(2,3,2).