LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Height Difference

EasyProblem #20
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Watch out for the size of the answer.

A class is choosing actors for the school play "Laurel and Hardy" - a comedy duo famous for their large difference in height. The heights of all n students are known, and a duo looks right exactly when the difference in height of its two members is exactly r.

Your task is to count in how many ways two students can be picked so that their height difference is exactly r. Two students with equal heights are still two different students - pairs are counted by who is in them, not by their heights.

Input

The first line contains a single integer t - the number of testcases.

  • The first line of each testcase contains two integers n and r - the number of students and the required height difference.
  • The next line contains n integers a0​,a1​,…,an−1​ - the heights of the students in millimeters. Heights can repeat.

Output

For every testcase print a single line with the number of pairs of students whose height difference is exactly r.

Example

Input
2
5 2350
15745 18095 15745 16234 13395
4 1
7 7 8 9
Output
4
3

In the first testcase the pairs are: the first and the second student, the first and the fifth, the second and the third, and the third and the fifth. In the second testcase both students of height 7 pair with the one of height 8, and the one of height 8 pairs with the one of height 9.

Constraints

1≤t≤1000
1≤n≤2⋅105
1≤ai​≤109
1≤r≤109
n1​+n2​+…+nt​≤2⋅105


This problem was adapted, with permission, from Razlika visina, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit