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.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

 public class Test
 {
    static PrintWriter pw = new PrintWriter(System.out);
    
    static class shit
    {
        ArrayList<Integer> indecies = new ArrayList(); 
        
        shit(int x)
        {
            indecies.add(x);
        }
        
        int size(){
            return indecies.size();
        }
        
        int first(){
            return indecies.get(0);
        }
        
        void add(int x)
        {
            indecies.add(x);
        }
        
        int find(int x)
        {
            int L = 0; int R = indecies.size()-1;
            int res = 0;
            while(L<=R)
            {
                int mid = (L+R)/2;
                int temp = indecies.get(mid);
                if(x == temp)
                    return mid;
                else if(x > temp)
                {
                    L = mid + 1;
                    res = L;
                }
                else
                    R = mid - 1;
            }

            return res;
        }
        
    }
    
    public static void main(String[] args)throws Exception
    {
        Reader.init(System.in);
        int n = Reader.nextInt();
        long[] ar = new long[n];
        HashMap<Long , shit> map = new HashMap();
        long[] pows = new long[33];
        long res = 0;
        
        for(int i = 0 ; i<33 ; i++)
            pows[i] = (long)Math.pow(2, i);
        
        for(int i = 0 ; i<n ; i++)
        {
            ar[i] = Reader.nextLong();
            if(!map.containsKey(ar[i]))
                map.put(ar[i], new shit(i));
            else
                map.get(ar[i]).add(i);
        }
        
        for(int i = n-1 ; i>0 ; i--)
        {
            
            for(int j = 0 ; j<33 ; j++)
            {
     
                long b = (long)(pows[j] - ar[i]);

                if(!map.containsKey(b))
                    continue;
                
                int size = map.get(b).size();
                if(size > 1)
                {
                    int r = map.get(b).find(i);
                    res += r;
                    
                    
                }
                    
                else
                {
                    int temp = map.get(b).first();
                    if(temp < i)
                        res ++;
                }
                
            }
            
        }

        pw.print(res);
        pw.close();
        
        
        
    }
        
}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public static int pars(String x) {
        int num = 0;
        int i = 0;
        if (x.charAt(0) == '-') {
            i = 1;
        }
        for (; i < x.length(); i++) {
            num = num * 10 + (x.charAt(i) - '0');
        }

        if (x.charAt(0) == '-') {
            return -num;
        }

        return num;
    }

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static void init(FileReader input) {
        reader = new BufferedReader(input);
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return pars(next());
    }

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

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