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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class CC {

	static class Pair implements Comparable<Pair> {

		int first, second;

		Pair(int f, int s) {
			first = f;
			second = s;
		}

		public String toString() {
			return first + " " + second;
		}

		@Override
		public int compareTo(Pair p) {
			if (first != p.first)
				return first - p.first;
			if (second != p.second)
				return second - p.second;
			return 0;
		}

	}

	static long findSmallest(long x) {
		long N = 1;
		while (N <= x) {
			N <<= 1;
		}
		return N;
	}

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		TreeSet<Long> set = new TreeSet<>();
		TreeMap<Long, Integer> map = new TreeMap<>();
		long ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			long N = 1;
			while (N < ((1L << 31) - 1)) {
				long key = N;
				if (N < a[i]) {
					N <<= 1;
					continue;
				}
				key -= a[i];
				if (set.contains(key))
					ans += map.get(key);
				N <<= 1;
			}
			set.add(a[i]);
			Integer x = map.get(a[i]);
			x = x == null ? 0 : x;
			map.put(a[i], x + 1);
		}
		out.println(ans);
		out.close();
	}

	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

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