You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).

Input

The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.

The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples

Input

4
7 3 2 1


Output

2


Input

3
1 1 1


Output

3

Note

In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).

In the second example all pairs of indexes (i, j) (where i < j) include in answer.
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Fedor Poschmann
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        static int NUM_TWO_POWERS = 30;
        static public int[] twoPowers = new int[NUM_TWO_POWERS + 1];

        static {
            twoPowers[0] = 1;
            for (int i = 1; i <= NUM_TWO_POWERS; i++) {
                twoPowers[i] = twoPowers[i - 1] * 2;
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            HashMap<Integer, Integer> counts = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int el = in.nextInt();
                int num = counts.containsKey(el) ? counts.get(el) : 0;
                counts.put(el, num + 1);
            }
            int uniqueElementsNum = counts.size();
            int[] a = new int[uniqueElementsNum];
            int idx = 0;
            for (Integer integer : counts.keySet()) {
                a[idx] = integer;
                idx++;
            }

            Arrays.sort(a);
            long sumPars = 0;

            for (int i = 0; i < uniqueElementsNum; i++) {
                int currEl = a[i];
                int currCnt = counts.get(currEl);
                if (currCnt > 1 && Arrays.binarySearch(twoPowers, currEl * 2) >= 0) {
                    sumPars += (long) currCnt * (currCnt - 1) / 2;
                }
                if (i < uniqueElementsNum - 1) {
                    for (int j = 1; j <= NUM_TWO_POWERS; j++) {
                        int delta = twoPowers[j] - currEl;
                        // try to find delta
                        if (delta > currEl && Arrays.binarySearch(a, i + 1, uniqueElementsNum, delta) >= 0) {
                            sumPars += (long) currCnt * counts.get(delta);
                        }
                    }
                }
            }

            out.println(sumPars);
        }

    }
}

