#K60272. Count Pairs With Given Sum

    ID: 31050 Type: Default 1000ms 256MiB

Count Pairs With Given Sum

Count Pairs With Given Sum

You are given an array of N integers, and a target integer K. Your task is to compute the number of pairs of indices (i, j) satisfying i < j such that:

\( A[i] + A[j] = K \)

The input is provided via standard input and the answer must be printed to standard output. Use an efficient algorithm to solve the problem when possible.

Note: If there are duplicate elements in the array, each unique pair with distinct indices is counted separately.

inputFormat

The first line contains two integers N and K separated by space.

The second line contains N integers separated by spaces representing the array A.

outputFormat

Output a single integer — the number of pairs (i, j) (with i < j) such that A[i] + A[j] = K.

## sample
5 7
1 2 3 4 5
2