Count The Triplets

easy
1. You are given an array of distinct integers.
 2. You have to find the count all the triplets such that sum of two elements equals the third element.
 3. For example,
 Input: {1, 4, 3, 2}
 
 Output: 2
 
 Explanation: The two triplets are: {1,4,3} (1 + 3 = 4) and {1,3,2} (1 + 2 = 3)
 
 Note:
 1. main takes input from the users.
 2. display is a utility function that displays an array. Feel free to use it for debugging purposes.
 3. This is a functional problem.
 4. You have to complete the function count. It takes as input the given array. It should return the required count.

Input Format

First line takes input N, the length of the given array. Second line takes input N space separated integers representing the elements of the array. Input is handled for you.

Output Format

The required count. Output is handled for you.

Constraints

N/A

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
1 4 3 2
Output
2
Previous
Count Possible Triangles
Next
Count Zeros In A Sorted Matrix

Related Questions