AmazonOA #201
Get Max Discount Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)HashingBits & Math
Count product pairs with distinct indices i<j such that price[i]+price[j] equals 3^e for some non-negative integer e, including 3^0=1. Different products with the same price are counted as different index combinations.
Input
The first line contains n; the second line contains the prices. This site uses 1≤n≤200000, 0≤price≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
3
2 1 8
Output:
2
Example 2
Input:
3
0 1 1
Output:
2
Example 3
Input:
4
1 1 2 2
Output:
4
Example notes
The answers are 2, 2 and 4.
Editorial
Loading solution…