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
kailash: 2015-02-17 13:47:57

O(n) --> TLE O(nlogn)--> AC
@Rahul Jain i used long long int

Last edit: 2015-02-17 13:48:34
Rahul Jain: 2015-02-02 17:48:57

what is the range of the elements. I am using -32768 to 32767, but that gives me wrong answer

MKM: 2015-01-14 17:32:34

Pretty easy!

eightnoteight: 2015-01-09 08:33:01

why! why! why! why am i getting wrong answer for the same algo in python but getting accepted in C++
i have also submitted a solution in python which doesn't print a new line to the output, but still i'm getting wrong answer

Last edit: 2015-01-09 08:34:34
swordfish12: 2014-12-25 17:32:31

misleading problem name :( ... very simple problem

mayank: 2014-11-25 06:29:17

Simple :)

deCodeIt: 2014-10-07 07:29:51

Segmentation fault at running (2).. =="

Now Solved :) ... a single pointer was giving seg fault.. hahahaaaha .. got 4 SIGSEV error for that

Last edit: 2014-10-07 13:29:44
ivar.raknahs: 2014-10-06 13:43:03

this ques really annoyed me .
After 1 tle and 6 runtime error finally AC

fanatique: 2014-08-20 07:25:13

my 100th :) but i am crawling :(

shiva: 2014-08-13 15:05:16

TLE nlogn :(


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