import std.stdio, std.string, std.conv;
import std.algorithm, std.array, std.range;
auto solve(string s_){
    immutable N = s_.chomp.to!int();
    auto A = readln.split.map!(to!int).array().sort!"a<b"();
    auto g = new int[][N];
    auto p = new int[N]; p[]=N;
    auto used = new bool[N];
    foreach(i;0..N){
        immutable a=A[i];
        foreach(k;1..31){
            immutable t=(1<<k)-a;
            if(t<1) continue;
            if(t>A[$-1]) break;
            int l=i+1, r=N;
            while(l<r){
                immutable m=(l+r)/2;
                immutable b=A[m];
                if(t>b) l=m+1;
                else if(t<b) r=m;
                else{
                    g[i]~=m;
                    g[m]~=i;
                    break;
                }
            }
        }
    }
    bool dfs(int v){
        used[v]=true;
        foreach(u;g[v]){
            immutable w = p[u];
            if(w==N || (!used[w] && dfs(w))){
                p[v]=u;
                p[u]=v;
                return true;
            }
        }
        return false;
    }
    int c=0;
    foreach(v;0..N) if(p[v]==N){
        used[]=false;
        if(dfs(v)) ++c;
    }
    return c;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }