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.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;

/**
 * Anda hanya ditugaskan untuk menyelesaikan implementasi processQuery.
 * Anda dapat menggunakan variable n dan q dari global variable yang
 * nilainya telah diisi pada method readInput. Anda bebas menambahkan maupun
 * merubah fungsi, variable, dll dalam template ini
 */
public class Rook {
    private static int n, q,ans;
    
    private static InputReader in;
    private static PrintWriter out;
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        in = new InputReader(inputStream);
        OutputStream outputStream = System.out;
        out = new PrintWriter(outputStream);   
        readInput();
        out.close();
    }

    private static long countPairs(int n) 
    { 
        Map <Long,Integer> freq=new HashMap <Long, Integer>();
        long [] a=new long[n];
        for(int i=0;i < n;i++){
            a[i]=in.nextLong();
            freq.put(a[i],0);
        }
        Arrays.sort(a);
        long ans=0;
        for(int i=0;i < n;i++){
            long tmp=1;
            while(tmp <= a[i]){
                if(tmp > a[i] && freq.containsKey(tmp-a[i])){
                    ans+=freq.get(tmp-a[i]);
                }
                tmp*=2;
            }
            if(tmp > a[i] && freq.containsKey(tmp-a[i])){
                ans+=freq.get(tmp-a[i]);
            }
            if(freq.containsKey(a[i]))
                freq.put(a[i],freq.get(a[i])+1);
            else
                freq.put(a[i],1);
        }
        return ans;

    } 
  
    private static void printOutput(long answer) throws IOException {
        out.println(answer);
    }
    
    private static void readInput() throws IOException {
        n = in.nextInt();
        int [] arr=new int[n];
        printOutput(countPairs(n));
    }
    static class InputReader {
            // taken from https://codeforces.com/submissions/Petr
            public BufferedReader reader;
            public StringTokenizer tokenizer;
    
            public InputReader(InputStream stream) {
                reader = new BufferedReader(new InputStreamReader(stream), 32768);
                tokenizer = null;
            }
    
            public String next() {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    try {
                        tokenizer = new StringTokenizer(reader.readLine());
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }
    
            public int nextInt() {
                return Integer.parseInt(next());
            }
            public long nextLong(){
                return Long.parseLong(next());
            }
    
        }
    }