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.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class B {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long p2[] = new long[31];
		long power = 1;
		for (int i = 0; i < p2.length; i++) {
			p2[i] = power;
			power <<= 1;
		}
		Integer[] a = new Integer[N];
		Arrays.fill(a, Integer.MAX_VALUE);
		HashMap<Integer, Long> map = new HashMap<Integer, Long>();
		int k = 0;
		for (int i = 0; i < N; i++) {
			int cur = sc.nextInt();
			if (!map.containsKey(cur))
				map.put(cur, (long) 1);
			else
				map.put(cur, map.get(cur) + 1);
			if (map.get(cur) == 1)
				a[k++] = cur;
		}

		Arrays.sort(a);
		int sz = a.length;
		for (int i = 0; i < a.length; i++)
			if (a[i] == Integer.MAX_VALUE) {
				sz = i;
				break;
			}
		long count = 0;
		for (int i = 0; i < 31; i++)
			for (int j = 0; j < sz; j++) {
				int lo = j + 1;
				int hi = sz - 1;
				long cc = map.get(a[j]);
				if (a[j] + a[j] == p2[i] && (cc > 1))
					count += (cc * (cc - 1)) / 2;
				while (lo <= hi) {
					int mid = lo + (hi - lo) / 2;
					if (a[j] + a[mid] == p2[i]) {
						count += cc * map.get(a[mid]);
						break;
					} else if (a[j] + a[mid] < p2[i])
						lo = mid + 1;
					else
						hi = mid - 1;
				}
			}
		System.out.println(count);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

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

	}
}
