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.
/**
 * Created by ankeet on 7/29/16.
 */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class B702 {

    static FastReader in = null;
    static PrintWriter out = null;

    public static void solve()
    {
        int n = in.nint();
        Integer[] a = new Integer[n];
        HashMap<Integer, Integer> occ = new HashMap<Integer, Integer>();

        for(int i=0; i<n; i++)
        {
            a[i] = in.nint();
            if(occ.containsKey(a[i]))
            {
                occ.put(a[i], occ.get(a[i])+1);
            }
            else occ.put(a[i], 1);
        }
        long max = (int)(1e9);
        long ways = 0;
        for(int i=0; i<n; i++)
        {
            long m = 1;
            while(m<=a[i]) m*=2;
            while(m-a[i] <= max)
            {
                int tar = (int) (m-a[i]);
                if(occ.containsKey(tar))
                {
                    ways+=occ.get(tar);
                    if(tar == a[i]) ways--;
                }
                m*=2;
            }
        }
        out.println(ways/2);


    }

    public static void main(String[] args)
    {
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try{
                    tokenizer = new StringTokenizer(read.readLine());
                }catch(Exception e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nint()
        {
            return Integer.parseInt(next());
        }
        public long nlong()
        {
            return Long.parseLong(next());
        }
        public double ndouble()
        {
            return Double.parseDouble(next());
        }

        public int[] narr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nint();
            }
            return a;
        }

        public long[] nlarr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nlong();
            }
            return a;
        }
    }


}


