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.
//package com.LEarning;

import java.util.*;

public class The2powquestion {
    static ArrayList<Integer> two= new ArrayList();
    static long hi=-1,low=-1;
    public static void f1l(int sea, int s , int e,int arr[]) {
        while(s<=e){
            int mid=(s+e)/2;
//            System.out.println("s= "+s+ "e= "+e+ "mid= "+mid);

            if(arr[mid]==sea && (mid-1)>=s &&  arr[mid-1]!=sea ){
                low=mid;
//                System.out.println("heri1");
                return;
            }
            if(arr[mid]==sea && (mid)==s ){
                low=mid;
//                System.out.println("heri2");
                return;

            }
            if(arr[mid]>=sea){
                e=mid-1;
            }
            if(arr[mid]<sea){
                s=mid+1;
            }


        }


    }
    public static void f2(int sea, int s , int e,int arr[]) {
        while(s<=e){
            int mid=(s+e)/2;
//            System.out.println("s= "+s+ "e= "+e+ "mid= "+mid);
            if((mid+1)<arr.length){
                if(arr[mid]==sea && arr[mid+1]!=sea ){
                    hi=mid;
//                System.out.println("heri3");
                    return;
                }}
            else if (arr[mid]==sea && mid==(arr.length-1)){
                hi=mid;
//                System.out.println("heri 4");
                return;
            }
            if(arr[mid]>sea){
                e=mid-1;
            }
            if(arr[mid]<=sea){
                s=mid+1;
            }



        }



    }



    public static void f1(){
        int temp=1;
        two.add(temp);
        for(int i=1;i<63;i++) {
            temp*=2;
            two.add(temp);
//            System.out.println("i= "+ two.get(i));
        }

    }


    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer,Integer> cmap = new HashMap();

        int ar[]= new int[n];

        long count = 0,c=0;
        for (int i = 0; i < n; i++) {
            ar[i]=sc.nextInt();
//            if(cmap.containsKey(ar[i])){
//                cmap.put(ar[i],cmap.get(ar[i])+1);
            }
//            else
//                cmap.put(ar[i],1);
//        }
        f1();
//        Set<Integer> key= cmap.keySet();
//        for(Integer keys :key){
//            System.out.println(keys + " " + cmap.get(keys));
////            System.out.println(cmap.containsKey(1));
//        }


//        int [][] ch= new int [n+2][n+2];
        int temp =-777;
//        int svc=n;
        long x=1;
        long store=-1;
        Arrays.sort(ar);
        for(int i=0;i<n;i++){
           for(int j=0;j<63;j++) {
            temp=two.get(j)-ar[i];
//           System.out.println("temp "+ temp + " arr[i] "+(ar[i]) + " start= "+ (i+1)+ " end "+ (ar.length-1));
           f1l(temp,i+1,ar.length-1,ar);
           f2(temp,i+1,ar.length-1,ar);
             store=hi-low +1;
//               System.out.println("store = "+ store +" hi = "+ hi + " low "+ low);
                if(store >0 && hi!=-1 && low!=-1){
//                    System.out.println("contains key " + temp + " ar i  "+ ar[i]);
                    if(store>1){
                         x=store;
                    }
                    count+=x;
//                    System.out.println("count increased "+ count);

               }
            x=1;
                hi=-1;low=-1;
           }
        }
        System.out.println(count);
//
    }
}

