QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22351. Mixed Up Cows

Statistics

Each of Farmer John's $N$ $(4 \le N \le 16)$ cows has a unique serial number $S_{i}$ $(1 \le S_{i} \le 25,000)$. The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large letters on a gold plate hung around her ample bovine neck.

Gangsta cows are rebellious and line up to be milked in an order called 'Mixed Up'. A cow order is 'Mixed Up' if the sequence of serial numbers formed by their milking line is such that the serial numbers of every pair of consecutive cows in line differs by more than $K$ $(1 \le K \le 3400)$. For example, if $N = 6$ and $K = 1$ then 1, 3, 5, 2, 6, 4 is a 'Mixed Up' lineup but 1, 3, 6, 5, 2, 4 is not (since the consecutive numbers 5 and 6 differ by 1).

How many different ways can $N$ cows be Mixed Up?

For your first 10 submissions, you will be provided with the results of running your program on a part of the actual test data.

Input

  • Line 1: Two space-separated integers: $N$ and $K$
  • Lines $2,\ldots,N+1$: Line $i+1$ contains a single integer that is the serial number of cow $i$: $S_{i}$

Output

  • Line 1: A single integer that is the number of ways that $N$ cows can be 'Mixed Up'. The answer is guaranteed to fit in a 64 bit integer.

Examples

Input 1

4 1
3
4
2
1

Output 1

2

The 2 possible Mixed Up arrangements are: 3 1 4 2 2 4 1 3

Scoring

POINTS: 200

Problem credits: Don Piele, 2007

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.