n=gets.to_i
a=gets.split.map &:to_i
a.sort!
c=0
31.downto(1){|s|
  i=0
  j=a.size-1
  while i<j
    if a[i]+a[j]==2**s
      c+=1
      a[i,1]=[]
      a[j,1]=[]
      j-=2
    elsif a[i]+a[j]<2**s
      i+=1
    else
      j-=1
    end
  end
}
p c
