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.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    public static class TaskB {
        public void solve(InputReader in, PrintWriter out) {
            final int MAX = 31;
            int n = in.nextInt();
            long ar[] = new long[n];
            Hashtable<Long, Long> table = new Hashtable<>();
            for (int i = 0; i < n; i++) {
                long cur = in.nextInt();
                ar[i] = cur;
                if (!table.containsKey(cur))
                    table.put(cur, (long) 1);
                else {
                    long find = table.get(cur);
                    table.replace(cur, find, find + 1);
                }
            }
            long degrees[] = new long[MAX + 1];
            degrees[0] = 1;
            for (int i = 1; i <= MAX; i++)
                degrees[i] = degrees[i - 1] * 2;
            long amount = 0;
            for (int i = 0; i < n; i++) {
                long cur = ar[i];
                for (int j = 0; j <= MAX; j++) {
                    long rest = degrees[j] - cur;
                    if (rest >= 1) {
                        if (table.containsKey(rest) && table.containsKey(cur)) {
                            long rep = table.get(rest);
                            if (rep == 1) {
                                if (cur != rest)
                                    amount++;
                                else
                                    amount += cur != rest ? rep : rep - 1;
                            } else
                                amount += cur != rest ? rep : rep - 1;
                        }
                    }
                }
                long rep2 = table.get(cur);
                table.replace(cur, rep2, rep2 - 1);
            }
            out.println(amount);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}