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

public class B {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long n = Long.valueOf(input.nextLine());
        String[] s = input.nextLine().split(" ");
        long[] ar = new long[(int)n];
        for (int i = 0; i < n; i++) {
            ar[i] = Long.valueOf(s[i]);
//            ar[i] = 1 ;
        }
        Arrays.sort(ar);
        long[] pow = new long[33];
        pow[0] = 1 ;
        for(int i = 1 ;i < 33 ; i ++){
            pow[i] = pow[i-1] * 2 ;
        }
        long ans = 0 ;
//        for(long i : ar) System.out.print(i + " ");
//        System.out.println();
        for (int i = 0; i < n ; i++) {
            for (int j = 1; j < 33; j++) {
                if(ar[i] < pow[j]){
                    long l = findLeft(pow[j] - ar[i] , ar  , i , n );
                    long r = findRight(pow[j] - ar[i], ar , i ,  n );
                    ans += (r - l);
//                    System.out.println("toFind = " + (pow[j]-ar[i]) + " , l = " + l + ", r = " + r + " , r - l =" + (r-l));
                }
            }
        }
        System.out.println(ans);
    }
    private static long findLeft(long l , long[] ar , long f, long e ){
        int from = (int)f, to = (int)e ;
        int mid ;
        while(to - from  > 1){
            mid = (to + from)/2;
            if(ar[mid] >= l ) to  = mid ;
            else from = mid ;
        }
        return (long)to ;
    }
    private static long findRight(long l , long[] ar ,long f , long e){
        int from = (int)f, to = (int)e ;
        int mid ;
        while(to - from > 1){
            mid = (to + from )/2 ;
            if(ar[mid] > l ) to = mid ;
            else from = mid ;
        }
        return (long)to ;
    }
}
