LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDE
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 FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion Find
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPTree DPBitmask DPDigit DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

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