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.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

  static class TaskB {
    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      int n = in.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < n; ++i) {
        a[i] = in.nextInt();
      }
      Arrays.sort(a);
      IntArrayList value = new IntArrayList(n);
      IntArrayList valueCnt = new IntArrayList(n);
      for (int i = 0; i < n; ++i) {
        if (i == 0 || value.get(value.size() - 1) != a[i]) {
          value.add(a[i]);
          valueCnt.add(1);
        } else {
          int lastIdx = valueCnt.size() - 1;
          valueCnt.set(lastIdx, valueCnt.get(lastIdx) + 1);
        }
      }
      long res = 0;
      for (int i = 0; i < value.size(); ++i) {
        int v = value.get(i);
        if (Integer.bitCount(v) == 1) {
          int vc = valueCnt.get(i);
          res += vc * (vc - 1L) / 2;
        }
      }
      for (int sum = 4; ; sum <<= 1) {
        int j = value.size() - 1;
        for (int i = 0; i < j; ++i) {
          for (; i < j && value.get(i) + value.get(j) > sum; --j) ;
          if (i < j && value.get(i) + value.get(j) == sum) {
            res += (long) valueCnt.get(i) * valueCnt.get(j);
          }
        }
        if (sum == 1 << 30) break;
      }
      out.println(res);
    }

  }

  static class IntArrayList implements IntCollection {
    private int[] values;
    private int close;

    public IntArrayList(int capacity) {
      values = new int[Integer.highestOneBit(capacity) << 1];
    }


    public int size() {
      return close;
    }


    public void add(int v) {
      ensureCapacity(size() + 1);
      values[close++] = v;
    }

    public int get(int idx) {
      if (idx >= size()) throw new ArrayIndexOutOfBoundsException();
      return values[idx];
    }

    public void set(int idx, int value) {
      if (idx >= size()) throw new ArrayIndexOutOfBoundsException();
      values[idx] = value;
    }

    protected void ensureCapacity(int capacity) {
      if (capacity < values.length) return;
      int[] newValues = new int[Integer.highestOneBit(capacity) << 1];
      System.arraycopy(values, 0, newValues, 0, values.length);
      close = size();
      values = newValues;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

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

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; ++i) {
        if (i > 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

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

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

  }

  static interface IntCollection {
  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPostion;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPostion = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) {
          throw new RuntimeException();
        }
        res = res * 10 + c - '0';
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPostion >= numberOfChars) {
        currentPostion = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPostion++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' '
          || c == '\n'
          || c == '\r'
          || c == '\t'
          || c < 0;
    }

  }
}

