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
2013-03-06 06:09:46 [Lakshman]
ha...ha sorting and searching...AC.....
2013-02-24 20:33:28 bat2009fifa
how about hashing?
2013-02-13 09:44:24 Ouditchya Sinha
easy question... AC :)
2012-12-23 14:14:23 Philipp Heeg
Input is broken. No wonder only ~10 solutions in Java so far.
2012-12-21 05:20:41 kamalesh
use scanf instead of cin.... finally AC!!!
2012-10-22 10:09:25 gourav
nlogn+nlogn complexity is awesome in this .. very easy to think... ;)
2012-10-02 20:41:37 saurabh
any clue??

Last edit: 2012-10-02 21:01:53
2012-09-05 06:39:06 tantu92
use scanf instead of cin...it costed me two TLEs..
2012-08-16 12:22:33 shailendra
very easy problem..think about it

Last edit: 2012-08-16 12:24:46
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.