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


public class B2 {
	
	
	public static void main(String[] args) throws IOException {
		Scanner sc= new Scanner(System.in);
		int power[]= new int [32];
		int tar=1;
		for(int i=0; i<32; i++){
			power[i]=tar;
			tar<<=1;
		}
		//System.out.println(Arrays.toString(power));
		int n= sc.nextInt();
		int []num= new int [n];
		TreeMap<Integer, Integer>tm= new TreeMap<Integer,Integer>();
		for(int i=0;i<n;i++){
			int x=sc.nextInt();
			num[i]=x;
			if(tm.containsKey(x)){
				int val=tm.get(x);
				tm.put(x, val+1);
			}
			else tm.put(x, 1);
		}
		
		long result=0;
		for(int i=0; i<n; i++){
			int x= num[i];
			for(int j=0; j<32; j++){
				int y= power[j]-x;
				if(tm.containsKey(y)){
					result+= tm.get(y);
					if(y==x)
						result--;
				}
			}
		}
		PrintWriter out= new PrintWriter(System.out);
		out.println(result/2);
		out.flush();
		out.close();
		
		
	
	}
	
	static class Num implements Comparable<Num>{
		int x;
		int ind;
		public Num(int a, int i){
			x=a;
			ind= i;
		}
		@Override
		public int compareTo(Num o) {
			if(x<o.x)
				return -1;
			else if(x>o.x)
				return 1;
			return ind-o.ind;
		}
	}
	
	static void shuffle(Num [] arr, int len){
		for(int i=0; i<len ;i++){
			int x= (int)(Math.random()*len);
			Num temp= arr[i];
			arr[i]= arr[x];
			arr[x]= temp;
		}
		
	}
	
	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
		{
			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 boolean ready() throws IOException {return br.ready();}


	}


}
