A famous Italian restaurant allows guests to enter only if they are present in pairs and the sum of the wealth of the people of the pair is a power of 3. A group of people wants to eat at the restaurant. Mathematically, if there are two people of wealth a and b, it forms a valid pair if a+b=3k for some positive integer k. They want to know how many possible pairs would be allowed entry.
Task
Given the individual wealth of the people, find the number of valid pairs.
Notes
Example
Assumptions
Output
1
Approach
The pair of the first and second person has a sum of wealth of 3 which is a power of 3.
Function description
Complete the function solve provided in the editor. This function takes the following 2 parameters and returns the required answer:
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output format
Print a single integer indicating the number of valid pairs.
Constraints
1≤N≤105
1≤wealth[i]≤320
Given
Output
2
Approach
The pair of first and third person has a sum of wealth of 3 which is a power of 3.
The pair of second and fourth person has a sum of wealth of 9 which is a power of 3.