HACKRNDM - Hacking the random number generator

You recently wrote a random number generator code for a web application and now you notice that some cracker has cracked it. It now gives numbers at a difference of some given value k more predominantly. You being a hacker decide to write a code that will take in n numbers as input and a value k and find the total number of pairs of numbers whose absolute difference is equal to k, in order to assist you in your random number generator testing.

NOTE: All values fit in the range of a signed integer, n, k>=1

Input

1st line contains n & k.
2nd line contains n numbers of the set. All the n numbers are assured to be distinct.

(Edited: n <= 10^5)

Output

One integer saying the no of pairs of numbers that have a diff k.

Example

Input:
5 2
1 5 3 4 2 Output: 3

Added by:vijay
Date:2011-10-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own Problem

hide comments
2012-08-16 12:22:33 shailendra
very easy problem..think about it

Last edit: 2012-08-16 12:24:46
2012-08-07 02:32:25 killerz
Finally AC... simply O(n).. dnt mess it up guys
2012-07-21 18:25:51 ɥsǝןǝǝu
Got AC...
2012-07-15 10:40:30 ken_taiken
Pheww AC ! ^^
Costed a lot.
2012-07-11 05:47:14 Shubham
after trials,I found n>10000 && n<=100000

Last edit: 2012-07-11 06:38:58
2012-06-16 09:51:21 spock
enjoyed.. :D
2012-06-07 06:52:19 ramchand
any clues about the input?
2012-06-07 06:51:42 ramchand
am still getting time limit exceeded error :-(
2012-06-04 06:34:31 Darky
Finally got AC after many TLE!
2012-05-09 06:42:34 Rishi Mukherje
same problem in interviewstreet got accepted. My O(n) python solution gets WA here. Why?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.