#B4241. Power of Two Pairs

    ID: 11898 Type: Default 1000ms 256MiB

Power of Two Pairs

Power of Two Pairs

Taotao is a computer enthusiast who has a keen interest in binary numbers. He observed that various data sets often reveal connections to powers of two. Now, he obtains a sequence of numbers \(a_1, a_2, \dots, a_n\) and notices that some pairs of elements add up exactly to a power of two. For a given sequence \(a_1, a_2, \dots, a_n\), your task is to count the number of pairs \((i, j)\) satisfying \(a_i + a_j = 2^x\), where \(x \in \mathbb{N}^*\) (i.e. positive integers) and \(i < j\).

Note: The power \(2^x\) is expressed in \(\LaTeX\) format in this description.

inputFormat

The first line contains a single integer \(n\) representing the length of the sequence.

The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).

outputFormat

Output a single integer: the total number of pairs \((i, j)\) (with \(i < j\)) such that \(a_i + a_j = 2^x\) for some positive integer \(x\).

sample

4
1 1 1 1
6