Question: Recently, Tan started learning about trees, especially Explanation In a given array Consider A = 1 , B = 2 , and C = 3

Recently, Tan started learning about trees, especially Explanation
In a given array Consider A=1,B=2, and C=3.
Compute the sum of B and C:2+3=5. Compute
half of this sum: 52=2.5.(not valid)
Compute the sum of A and C:1+3=4. Compute
half of this sum: 42=2(valid) Sample Output
1
Explanation
In a given array Consider A=1,B=2, and C=3.
Compute the sum B and C:2+3=5. Compute
half of this sum: 52=2*5.(not valid)
Compute the sum of A and C:1+3=4. Compute
half of this sum: 42=2(valid)
valid because 2 is present as a remaining element.
Compute the sum of A and B:2+1=3. Compute
half of this sum: 32=1.5(not valid).
So the output will be 1.
Binary Trees. He started thinking of creating a binary
tree that has precisely three nodes. One will be the
root node, and the other will be its child nodes. But the
condition is that the root node's value be equal to half
of the sum of the value of its child nodes.
He asked Taru to give him n integers to create this kind
of binary tree. Seeing all those integers, Tan got
overwhelmed, so he needs your help finding any three
integers that can be created as a tree. Since many
possible combinations exist, you must tell the number
of triplets that can form the above binary tree.
Input Format
The first line will contain an integer n.
The next n line will contain an integer each.
Constraints
1n105
-103 array element s103
Output Format
Recently, Tan started learning about trees,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!