N=gets.to_i
A=gets.split.map(&:to_i)
A.sort!
exists=Hash.new(0)
used=Hash.new(0)
A.each do |a|
	exists[a]+=1
end
ans=0
A.reverse_each do |a|
	next if used[a]==exists[a]
	used[a]+=1
	target=1
	b=a
	while b!=0
		b>>=1
		target<<=1
	end
	if exists[target-a]>used[target-a]
		ans+=1
        used[target-a]+=1
	end
end
p ans