import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
import core.bitop;
auto solve(string s_){
    immutable N = s_.chomp.to!int();
    auto A = readln.split.map!(to!int).array(); A.sort;
    int[int] m;
    foreach(a;A){
        if(a !in m) m[a]=0;
        ++m[a];
    }
    int c=0;
    foreach_reverse(a;A) if(m[a]>0){
        auto t=a+1;
        if((t&t-1)!=0) t=1<<bsr(t)+1;
        t-=a;
        assert(t<=a);
        --m[a];
        if(t in m && m[t]>0){
            --m[t];
            ++c;
        }
    }
    return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }