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 );
                    if(r != -1 && l != -1) {
                        ans += (r - l + 1);
                        if(ar[i] == pow[j] - ar[i]) ans -- ;
                    }
//                    if(r != -1 || l != -1)
//                    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 val , long[] array , long start , long end){
        int _start  = (int)start, _end = (int)end ;
        long _val = val ;
        long[] _array = array ;

        if(_end < _start || _start < 0 || _end < 0 ) return -1 ;

        int _from = _start , _to = _end ;
        int _mid ;

        while(_to - _from  > 1){
            _mid = (_to + _from)/2;
            if(_array[_mid] >= _val ) _to  = _mid ;
            else _from = _mid ;
        }
//        System.out.println(_from  + " " + _to);
        if(_from - 1 >= _start && _array[_from - 1] == _val) return _from - 1 ;
        if(_array[_from] == _val ) return _from ;
        if(_to - 1 >= _start && _array[_to - 1] == val) return _to - 1;
        if(_to < end && _array[_to] == _val) return _to ;
        return -1 ;
    }

    /**
     * 右边界
     */
    private static long findRight(long val , long[] array ,long start , long end){
        int _start  = (int)start, _end = (int)end ;
        long _val = val ;
        long[] _array = array ;

        if(_end < _start || _start < 0 || _end < 0 ) return -1 ;

        int _from = _start , _to = _end ;
        int _mid ;

        while(_to - _from  > 1){
            _mid = (_to + _from)/2;
            if(_array[_mid] > _val ) _to  = _mid ;
            else _from = _mid ;
        }
//        System.out.println(_from  + " " + _to);
        if(_to < end && _array[_to] == _val) return _to ;
        if(_to - 1 >= _start && _array[_to - 1] == val) return _to - 1;
        if(_array[_from] == _val ) return _from ;
        if(_from - 1 >= _start && _array[_from - 1] == _val) return _from - 1 ;
        return -1 ;
    }
}
