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.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author whhone
 */
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);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int N = in.nextInt();
      int[] a = in.nextIntArray(N);
      long ans = 0;
      MultiSet<Integer> ms = new MultiSet<Integer>();
      for (int i = 0; i < N; i++) {
        for (int j = 1; j <= 30; j++) {
          int sum = (1 << j);
          int b = sum - a[i];
          ans += ms.count(b);
        }
        ms.add(a[i]);
      }
      out.println(ans);
    }

  }

  static final class OutputWriter extends PrintWriter {
    public OutputWriter(OutputStream stream) {
      super(stream);
    }

    public OutputWriter(Writer writer) {
      super(writer);
    }

  }

  static class MultiSet<T> {
    HashMap<T, Integer> hm;

    public MultiSet() {
      hm = new HashMap<T, Integer>();
    }

    public void add(T object) {
      add(object, 1);
    }

    public void add(T object, int occurrences) {
      if (contains(object)) {
        hm.put(object, hm.get(object) + occurrences);
      } else {
        hm.put(object, occurrences);
      }
    }

    public boolean contains(T object) {
      return hm.containsKey(object);
    }

    public int count(T object) {
      if (hm.containsKey(object)) {
        return hm.get(object);
      } else {
        return 0;
      }
      // getOrDefault() is available since Java 8.
      // return hm.getOrDefault(object, 0);
    }

  }

  static final class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public String cache;

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

    private String nextNoCache() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        tokenizer = new StringTokenizer(nextLine());
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      try {
        return reader.readLine();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    public String next() {
      if (cache != null) {
        String next = cache;
        cache = null;
        return next;
      } else {
        return nextNoCache();
      }
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; ++i) {
        a[i] = nextInt();
      }
      return a;
    }

  }
}

