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
PANKAJ SAINI: 2012-04-22 03:06:45

what is the limit of n??

arjun: 2012-03-14 14:38:48

O(nlogn) +O(n)

张翼德: 2012-02-06 21:10:13

read question twice and google wat predominantly means haha:)

PubLic_AvenGeR: 2012-01-15 15:34:27

nlogn passes with ease....Good ques anyways..... :)

BOND: 2012-01-05 12:46:11

just think how to use increasing sequence ...

Aradhya: 2011-12-31 15:40:47

plz tell the range of n...

Allada Revanth Kumar: 2011-12-31 12:37:01

seems very easy problem... but could not understand why i am getting TLE.. please help

bristy: 2011-12-28 18:31:30

@admin_
can a no. repeat?

Anurag Aggarwal: 2011-12-23 06:45:26

@author
At least correct the input format correctly.
Problem says that that 2nd line will contain all the numbers but 2nd line is not a single line it is a combination of n line

@Mitch Schwartz
Thanks..

tech{{i}}: 2011-12-21 07:19:10

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....


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