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

Pairs With a Given Sum

EasyProblem #15
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A number s and an array of n different non-negative integers are given. Your task is to count the pairs of elements of the array whose sum is exactly s.

Input

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

  • The first line of each testcase contains two integers n and s - the number of elements and the target sum.
  • The next line contains n different integers a0​,a1​,…,an−1​ - the elements of the array.

Output

For every testcase print a single line with the number of pairs of different elements whose sum equals s.

Example

Input
2
6 7
2 5 4 7 0 6
5 8
1 2 3 4 6
Output
2
1

In the first testcase the pairs are (2,5) and (7,0). In the second testcase the only pair is (2,6) - note that 4 cannot be paired with itself.

Constraints

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


This problem was adapted, with permission, from Broj parova datog zbira, 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