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.InputStreamReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.StringTokenizer;

public class Edu15B {

	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(bf.readLine());

		StringTokenizer st = new StringTokenizer(bf.readLine());

		Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			int cur = Integer.parseInt(st.nextToken());

			if (counts.containsKey(cur)) {
				counts.put(cur, counts.get(cur) + 1);
			} else {
				counts.put(cur, 1);
			}
		}

		Collection<Integer> pow2 = new LinkedList<Integer>();
		for (int i = 0; i <= 30; i++) {
			pow2.add(1 << i);
		}

		long total = 0;
		for (Integer i : counts.keySet()) {
			for (Integer curPow2 : pow2) {
				int j = curPow2 - i;
				if (j < i) {
					continue;
				} else if (j == i) {
					long count = counts.get(i);
					total += count * (count - 1) / 2;
				} else {
					if (counts.containsKey(j)) {
						total += (long) counts.get(i) * (long) counts.get(j);
					}
				}
			}
		}

		System.out.println(total);
	}
}
