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

public class CF_702_B_POWERS_OF_TWO {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		long counter = 0;

		long[] a = new long[n];

		TreeMap<Long, Long> tm = new TreeMap<>();

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (tm.containsKey(a[i]))
				tm.put(a[i], tm.get(a[i]) + 1);
			else
				tm.put(a[i], 1L);

		}
		long value = tm.firstKey() + tm.lastKey();

		for (int i = 0; i < n; i++) {
			long maxPower = (long) Math.ceil((Math.log(value) / Math.log(2)));
			long maxValue = 1 << maxPower;
			long x = a[i];
			

			while (maxPower>=0) {
				long search = maxValue - x;
				
				
				if (tm.containsKey(search)) {
					if (x == search)
						counter += tm.get(search) -1 ;
					else
						counter+= tm.get(search);
				}
				maxValue = 1 << --maxPower;
				
			}
			tm.put(x, tm.get(x) - 1);
			if(tm.get(x)<0)
				tm.put(x,0L);
			
				
		}

		System.out.println(counter);

	}

	static class Scanner {
		BufferedReader bf;
		StringTokenizer st;

		public Scanner(InputStream i) {
			bf = new BufferedReader(new InputStreamReader(i));

		}

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

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

		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 long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
	}
}
