8.4 Bob, Alice and Three Numbers
(RankList for this Question)
Score: 30pts
Time Limit: 1.00 sec
Alice has given Bob an array of distinct integers and his task is to find the number of possible triplets which add up to a given target.

Constraints
\(1 \leq n \leq 1000\)

Input Format
First line contains the number of distinct integers and the target sum
Following line contains the n distinct integers in the array

Output Format
Output the number of possible triplets

Example 1
Input:
8 0
12 3 1 2 -6 5 -8 6

Output:
3

Explanation:
[-8, 2, 6], [-8, 3, 5], [-6, 1, 5] are the possible triplets which add up to the target sum which is 0.

Log In to solve the Question