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.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
 
public class Main {
 
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
 
        Arrays.sort(arr);
        long max = arr[arr.length - 1];
 
        long[] powersOfTwo = new long[31];
 
 
        powersOfTwo[0] = 2;
        for (int i = 1; i < 31; i++) {
 
            powersOfTwo[i] = powersOfTwo[i - 1] * 2;
            //System.out.println(powersOfTwo[i]);
        }
 
 
        for (int i = 0; i < n; i++) {
 
            long valueOfI = arr[i];
            ArrayList<Long> sub = new ArrayList<>();
 
            for (int j = lowerBound(powersOfTwo, 0, powersOfTwo.length, valueOfI); j < powersOfTwo.length; j++) {
 
                sub.add(powersOfTwo[j] - valueOfI);
                //System.out.println(powersOfTwo[j] - valueOfI);
 
 
            }
            
 
            for (int j = 0; j < sub.size(); j++) {
 
                long valueOfIndexJ = sub.get(j);
                int exist = binarySearch(valueOfIndexJ, i + 1, arr);
 
                if (exist > -1) {
 
                    int lower = lowerBound(arr, i + 1, n, valueOfIndexJ);
                    int upper = upperBound(arr, i + 1, n, valueOfIndexJ);
                    if (lower==upper) sum++;
                    else
                        sum = sum + (upper - lower) ;
 
 
                }
 
 
            }
 
 
        }
 
 
 
 
 
        System.out.print(sum);
 
 
    }
 
 
    //algos
 
 
    public static boolean check(int size, long[][] matrix) {
        int up, down;
        for (int i = 0; i < (size + 1) >> 1; i++)
            for (int j = 0; j < size; j++) {
                up = size - 1 - i;
                down = size - 1 - j;
                if (matrix[up][down] != matrix[i][j])
                    return false;
            }
 
        return true;
    }
 
    public static int lowerBound(ArrayList<Long> array, int low, int length, long value) {
 
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array.get(mid)) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
    }
 
    public static int lowerBound(long[] array, int low, int length, long value) {
 
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array[mid]) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
    }
 
 
    private static int binarySearch(long i, int begin, long[] a) {
 
 
        int mid = 0;
 
        int end = a.length - 1;
 
        while (begin <= end) {
 
            mid = (begin + end) / 2;
 
            if (a[mid] < i) {
                begin = mid + 1;
 
            } else if (a[mid] > i) {
                end = mid - 1;
 
            } else return mid + 1;
 
 
        }
 
 
        return -1;
    }
 
 
    public static int upperBound(long[] array, int low, int length, long value) {
 
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
 
    public static int upperBound(ArrayList<Long> array, int low, int length, long value) {
 
        int high = length;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array.get(mid)) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
 
 
    public static boolean isContain(String a, char b) {
 
 
        for (int i = 0; i < a.length(); i++) {
 
            if (a.charAt(i) == b) return true;
 
 
        }
 
 
        return false;
    }
 
 
}
 
 
 
 
 
            /*
 
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] x = new int[n];
 
                    for (int i = 0; i < n; i++) {
                    x[i] = sc.nextInt();
                    }
                    Arrays.sort(x);
 
                    int q = sc.nextInt();
                    int[] m = new int[q];
 
                    for (int i = 0; i < q; i++) {
                    m[i] = sc.nextInt();
                    int index = binaryS(x, 0, x.length, m[i]);
 
                    // Arrays.binarySearch();
                    System.out.println(index + 1);
 
                    }
 
 
                    }
 
            private static int binaryS(int[] x, int i, int length, int m) {
 
                    int begin = 0;
                    int last = x.length - 1;
                    int mid = 0;
                    while (begin <= last)// a5r lafa lma el begin y3de el last . s3etha hayo2f
                    {
                    mid = (begin + last) / 2;
                    if (x[mid] < m) begin = mid + 1;
                    else if (x[mid] > m) last = mid - 1;
                    else return mid + 1;
 
 
                    }
 
                    return mid;*/
 
 
//TODO : queries more or less
    /*
 
            Scanner sc = new Scanner(System.in);
            int an = sc.nextInt();
            int bn = sc.nextInt();
            int [] a = new int [an];
            int [] b = new int [bn];
 
            for (int i = 0; i <an ; i++) {
                a[i]=sc.nextInt();
            }
 
 
            Arrays.sort(a);
 
 
 
            for (int i = 0; i <bn ; i++) {
                b[i]=sc.nextInt();
            }
 
 
            for (int i = 0; i < bn; i++) {
                System.out.print(upperBound(a,a.length,b[i])+" ");
            }
    *//* private static void recurseAb(int rem, int a, int b, int counter) {
        counter++;
 
        if (rem % a == 0 && rem / a > counterGlobe) {
 
            counterGlobe = counter + (rem / a) - 1;
            return;
 
        } else {
 
            while (rem > 10 * b) {
                rem = rem - a;
                counter++;
            }
 
            if (rem - a > a) {
 
                recurseAb(rem - a, a, b, counter);
            } else if (rem - a == 0 && counter > counterGlobe) {
                counterGlobe = counter;
                //System.out.print(counter);
                return;
 
            }
 
 
            if (rem - b > b) {
 
 
                recurseAb(rem - b, a, b, counter);
            } else if (rem - b == 0 && counter > counterGlobe) {
                counterGlobe = counter;
                //  System.out.println(counter);
                return;
 
            }
        }
 
 
    }*/