#K33322. Count Distinct Pairs

    ID: 25062 Type: Default 1000ms 256MiB

Count Distinct Pairs

Count Distinct Pairs

Given an integer array arr and an integer target, your task is to count the number of distinct pairs \( (i, j) \) (with \( i < j \)) such that \( arr[i] + arr[j] = target \). Note that a pair is defined by the indices and different occurrences of the same number are considered distinct if they occur at different positions.

For example, if arr = [1, 5, 7, -1, 5] and target = 6, the valid pairs are \( (0, 1) \), \( (0, 4) \), and \( (2, 3) \), yielding a total count of 3.

Please read the input from standard input and output the result to standard output.

inputFormat

The first line of input contains two integers n and target, where n is the number of elements in the array.

The second line contains n space-separated integers representing the array arr.

If n = 0, the second line will be empty.

outputFormat

Output a single integer, representing the number of distinct pairs \( (i, j) \) such that \( i < j \) and \( arr[i] + arr[j] = target \).

## sample
5 6
1 5 7 -1 5
3