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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

    static class Codeforces_702B {
        InputReader in;
        OutputWriter out;

        public void solve(int testNumber, InputReader in_, OutputWriter out_) {
            in = in_;
            out = out_;

            int n = in.nextInt();
            int[] a = new int[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            TreeMap<Integer, Integer> map = new TreeMap<>();

            for (int i = 0; i < n; i++) {
                map.put(a[i], map.getOrDefault(a[i], 0) + 1);
            }

            int[] p = new int[30];
            int tmp = 2;

            for (int i = 0; i < 30; i++) {
                p[i] = tmp;
                tmp *= 2;
            }

            long ans = 0;

            for (Integer x : map.keySet()) {
                for (int power : p) {
                    int y = power - x;
                    if (y > x) {
                        if (map.containsKey(y)) {
                            ans += (long) map.get(x) * map.get(y);
                        }
                    } else if (y == x) {
                        int count = map.get(x);
                        ans += (long) count * (count - 1) / 2;
                    }
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private final int BUFFER_SIZE = 32768;
        private InputStream stream;
        private byte[] buffer = new byte[BUFFER_SIZE + 1];
        private int pointer = 1;
        private int readLength = 0;
        private int lastWhiteSpace = '\n';

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private void fillBuffer() {
            try {
                readLength = stream.read(buffer, 1, BUFFER_SIZE);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        private byte get() {
            if (pointer > readLength) {
                pointer = 1;
                fillBuffer();
                if (readLength <= 0) return -1;
            }
            return buffer[pointer++];
        }

        public char nextChar() {
            int c = get();

            while (isWhiteSpace(c)) {
                c = get();
            }

            return (char) c;
        }

        public int nextInt() {
            int c = nextChar();
            int sign = 1;

            if (c == '-') {
                sign = -1;
                c = get();
            }

            int abs = 0;

            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                abs *= 10;
                abs += c - '0';
                c = get();
            } while (!isWhiteSpace(c));

            lastWhiteSpace = c;

            return abs * sign;
        }

        public boolean isWhiteSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class OutputWriter {
        private PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (Object object : objects) {
                writer.print(object);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}

