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

hide comments
Harsh Gupta: 2013-03-11 07:25:34

What is the range of the input set?

[Lakshman]: 2013-03-06 06:09:46

ha...ha sorting and searching...AC.....

bat2009fifa: 2013-02-24 20:33:28

how about hashing?

Ouditchya Sinha: 2013-02-13 09:44:24

easy question... AC :)

Philipp Heeg: 2012-12-23 14:14:23

Input is broken. No wonder only ~10 solutions in Java so far.

kamalesh: 2012-12-21 05:20:41

use scanf instead of cin.... finally AC!!!

gourav: 2012-10-22 10:09:25

nlogn+nlogn complexity is awesome in this .. very easy to think... ;)

saurabh: 2012-10-02 20:41:37

any clue??

Last edit: 2012-10-02 21:01:53
tantu92: 2012-09-05 06:39:06

use scanf instead of cin...it costed me two TLEs..


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