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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import java.util.*;

public class codeforces {
    public static void main(String[] args) {

        InputReader in= new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        long []ele = new long[n];
        for (int i = 0 ;i<n;i++)
        {
            ele[i] = in.nextLong();
        }
        HashMap<Long, Long> hm = new HashMap<>();
        long ans = 0;
        for (int i = 0 ; i<n ; i++)
        {
            for (int j = 1; j < 32 ; j++)
            {
                long poweroftwo = 1<<j;
                long diff = poweroftwo - ele[i];
                if (hm.containsKey(diff)){
                    ans += hm.get(diff);
                }
//                out.println(diff+" ");
            }
            if(hm.containsKey(ele[i]))
            {
                hm.put(ele[i], hm.get(ele[i]) + 1);
            }else {
                hm.put(ele[i], 1L);
            }
        }

        out.println(ans);
        out.close();


    }

    static void mergesort(int []arr, int left ,int right)
    {
        if(right>left)
        {
            int mid = (right+left)/2;
            mergesort(arr,left,mid);
            mergesort(arr,mid+1,right);
            MERGE(arr,left,mid,right);
        }

    }
    static void MERGE(int []arr,int left,int mid,int right)
    {
        int n1 = mid - left + 1;
        int n2 = right - mid;
        int []templ = new int[n1];
        int []tempr = new int[n2];

        for(int i = 0 ;i<n1 ;i++)
        {
            templ[i] = arr[left + i];
        }
        for (int i = 0 ; i<n2 ; i++)
        {
            tempr[i] = arr[mid + 1 +i];
        }

        int i = 0;
        int j = 0;
        int k = 1;
        while (i<n1 && j<n2)
        {
            if(templ[i]<=tempr[j])
            {
                arr[k] = templ[i];
                i++;
            }
            else
            {
                arr[k] = tempr[j];
                j++;
            }
            k++;
        }

        while (i<n1)
        {
            arr[k] = templ[i];
            i++;
            k++;
        }

        while(j<n2)
        {
            arr[k] = tempr[j];
            j++;
            k++;
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


