PDP-27 (2015) - Camp juniors - 1 (sumx)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

SUMX

A sequence of N positive integers A_1, A_2, ..., A_N, and an integer X are given. Write a program to find the number of pairs (A_i,\; A_j), where 1 \le i < j \le N and A_i + A_j = X.

Input

The first line of the input contains two numbers N and X, separated by a single space. The second line contains the N integers A_i of the sequence, separated in pairs by spaces.

Output

The output should consist of a single line containing exactly one integer: the desired number of pairs.

Constraints

1 \le N \le 1.000.000
1 \le X \le 2.000.000
1 \le A_i \le 1.000.000
Execution time limit: 1 sec.
Memory limit: 64 MB.

Examples of Input - Output Files:
1st

STDIN (sumx.in)

9 13
5 12 7 10 9 1 2 3 11

STDOUT (sumx.out)

3

Explanation of the first example: In the first example, the possible pairs are three:

A_2 + A_6 = 12 + 1 = 13
A_4 + A_8 = 10 + 3 = 13
A_7 + A_9 = 2 + 11 = 13


2nd

STDIN (sumx.in)

5 12
1 2 3 4 6

STDOUT (sumx.out)

0

Explanation of the second example: In the second example, there is no pair that sums up to 12.


3d

STDIN (sumx.in)

6 10
2 4 6 8 4 6

STDOUT (sumx.out)

5

Explanation of the third example: Finally, in the third example, the possible pairs are five (pay attention to the repeating terms):

A_1 + A_4 = 2 + 8 = 10
A_2 + A_3 = 4 + 6 = 10
A_2 + A_6 = 4 + 6 = 10
A_3 + A_5 = 6 + 4 = 10
A_5 + A_6 = 4 + 6 = 10


Comments

There are no comments at the moment.