Under construction

Still being built. Things may change

Number Pairs

Interview

Time limit2sMemory limit512 MB

Summary
Count pairs of distinct values in a sequence that sum to a target K, where order does not matter and each element is used once.
Level

Easy3 of 10

Topics
Array, Hash map, Two pointers, Sorting
Solved
No attempts yet

Problem

You are given a sequence of NN distinct integers. Count how many pairs of elements in the sequence add up to KK.

A pair is made of two elements at different positions, and the order inside a pair does not matter, so (1,6)(1, 6) and (6,1)(6, 1) are the same pair. The same element cannot be used twice, so when KK is even and K/2K/2 appears in the sequence, that single value does not form a pair by itself.

For the sequence 1,2,3,4,5,61, 2, 3, 4, 5, 6 and K=7K = 7 the pairs (1,6)(1, 6), (2,5)(2, 5), (3,4)(3, 4) satisfy the condition, so the answer is 33. For the same sequence and K=5K = 5 the pairs (1,4)(1, 4) and (2,3)(2, 3) satisfy it, so the answer is 22.

Input

The first line contains the sequence length NN and the target sum KK, separated by a space.

The second line contains the NN elements of the sequence, separated by spaces.

1≤N≤1 0001 \le N \le 1\,000. The elements are pairwise distinct integers between 11 and 10610^6. KK is an integer between 11 and 2×1062 \times 10^6.

Output

Print one integer, the number of pairs whose sum is KK.

Examples2

  1. Example 1

    Input
    6 7
    1 3 2 6 5 4
    
    Expected output
    3
    
  2. Example 2

    Input
    6 3
    1 2 3 4 5 6
    
    Expected output
    1