Public Judge

pjudge

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#21858. 【NOIP Round #7】Permutation Counting

Statistiques

Given a sequence of positive integers $a_1, a_2, \dots, a_n$ ($a_1 < a_2 < \dots < a_n$), where all elements are distinct.

Find the number of permutations $p_1, \dots, p_n$ of $1 \sim n$ such that for all $1 \le i \le n-1$, $|a_{p_i} - a_{p_{i+1}}| \ne k$. Output the answer modulo $998244353$.

Input

The first line contains two integers $n$ and $k$.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$.

Output

Output a single integer representing the answer.

Examples

Input 1

4 1
1 2 3 4

Output 1

2

Note 1

The permutations $3, 1, 4, 2$ and $2, 4, 1, 3$ satisfy the condition.

Input 2

(See provided files)

Output 2

(See provided files)

Constraints

For all test cases:

  • $1 \le n \le 5 \times 10^3$
  • $1 \le k \le 10^6$
  • $1 \le a_i \le 10^9$
Subtask ID Special Properties Score
$1$ $n \le 10$ $20$
$2$ $n \le 400$ $30$
$3$ $n \le 1000$ $20$
$4$ None $30$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.