import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    int[] pows;
    for (int i = 1; i <= 30; i++) pows ~= 2 ^^ i;

    int[int] d;
    foreach (x; a) d[x]++;

    auto ks = d.keys.array;
    ks.sort();

    int[] keys, vals;
    foreach (k; ks) {
        keys ~= k;
        vals ~= d[k];
    }

    int[][] pairs;
    int ans = 0;
    int[int] refs;
    for (int i = 0; i < keys.length; i++) {
        int k = keys[i];
        foreach (pow; pows) {
            if (k < pow) {
                int x = pow - k;
                if (x > k && x in d) {
                    pairs ~= [k, x];
                    refs[k]++;
                    refs[x]++;
                }
            }
        }
    }

    for (int i = 0; i < pairs.length; i++) {
        int x = pairs[i][0];
        int y = pairs[i][1];
        if (refs[x] == 1 || refs[y] == 1) {
            int p = min(d[x], d[y]);
            ans += p;
            d[x] -= p;
            d[y] -= p;
        }
    }

    for (int i = 0; i < pairs.length; i++) {
        int x = pairs[i][0];
        int y = pairs[i][1];
        if (refs[x] > 1 || refs[y] > 1) {
            int p = min(d[x], d[y]);
            ans += p;
            d[x] -= p;
            d[y] -= p;
        }
    }


    return ans;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}
