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
2011-12-21 07:19:10 tech{{i}}
the same code when submitted in java gives TLE but accepted in c++....why this????
is taking input with scanner class takes more time....plz help....
2011-11-27 17:48:26 .::Manish Kumar::.
Misleading problem-name. I thought something would be there regarding Random Number gen.
2011-11-18 11:31:33 ^::^
Will a number repeat???
2011-11-18 11:31:00 ^::^
will a number repeat????
2011-10-29 03:14:18 ****** *** *****
2^32 is the limit ??

Last edit: 2011-10-29 04:30:46
2011-10-29 00:33:53 Mohamed Maher
what are the limits??
2011-10-21 10:21:06 Chandan Giri
easy problem.. :)
2011-10-19 14:40:12 sri
what is the limit for n?
2011-10-19 05:06:57 Nnavneetsinha
@vijay be more formal in problem description writing
2011-10-19 05:06:57 sharad
O(n)+O(nlogn) is ok need not to do binary search every time..:)
@author please use formal lang.. and numeric constraint

Last edit: 2011-10-17 04:05:19
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.