Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2792.   Cows of the Round Table
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 622   Accepted Runs: 229    Multiple test files



Farmer John is calling his N (1 ≤ N ≤ 10) cows to a very important meeting at a round table.

The cows are rather anxious about this meeting since they want to put forth their very best image. To make the table arrangement attractive, they want to ensure that any two cows sitting next to each other to differ in height by no more than K (1 ≤ K ≤ 1,000,000) millimeters (cow i has integer height Hi (1 ≤ Hi ≤ 1,000,000) millimeters).

Help calculate the number of ways the cows can sit down at the round table such that no two adjacent cows differ in height by more than K millimeters. Two ways are different if there is at least one cow with a different cow to its left in each arrangement.

The answer is guaranteed to fit in a 32-bit signed integer.

Input

* Line 1: Two space-separated integers, N and K

* Lines 2..N + 1: Line i+1 contains height Hi

Output

* Line 1: The number of ways that the cows can sit down at the round table such that two adjacent cows do not differ in height by more than K millimeters.

Sample Input

4 10
2
16
6
10

Sample Output

2

Input Details

There are 4 cows, with heights 2, 16, 6, and 10. Two cows whose heights differ by more than 10 do not want to sit next to each other.

Output Details

Clearly the cows with heights 2 and 16 must be opposite each other, so there are 2 ways to place the cows of height 6 and 10.


Source: USACO 2007 March Competition
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:Fxz. Developer: SuperHacker, G.D.Retop, Fxz