import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    long[long] mp;
    foreach (a; A) mp[a] += 1;

    auto B = mp.keys.array;
    B.sort();

    long[] P;
    for (long i = 0; (1L << i) <= 4 * 10L^^9; ++i) P ~= (1L << i);


    long ans = 0;

    foreach_reverse (a; B) {
        foreach_reverse (p; P) {
            if (p - a == a) {
                long x = mp[a] / 2;
                ans += x;
                mp[a] -= x * 2;
            } else if ((p - a) in mp) {
                long x = min(mp[a], mp[p-a]);
                ans += x;
                mp[a] -= x;
                mp[p-a] -= x;
            }
        }
    }

    ans.writeln;
}
