n=gets.chomp.to_i
if n == 1
  puts 0
  exit
end
ary=gets.chomp.split(' ').map(&:to_i)
cary = ary.combination(2)
tary = []
30.times do |i|
  i += 1
  tary << 2**i
end
cdt = []
cary.each do |c|
  cdt << c if tary.any? { |t| t == (c[0] + c[1]) }
end
pr = cdt
f_pr = pr.flatten
hsh = {}
pr.each_with_index do |pa, i|
  if hsh[pa[0]]
    a0 = hsh[pa[0]]
  else
    a0 = f_pr.count(pa[0])
    hsh[pa[0]] = a0
  end
  if hsh[pa[1]]
    a1 = hsh[pa[1]]
  else
    a1 = f_pr.count(pa[1])
    hsh[pa[1]] = a1
  end
  if a0 > 1 && a1 > 1
  	pr.delete_at(i)
    f_pr.delete_at(f_pr.index(pa[0]))
    f_pr.delete_at(f_pr.index(pa[1]))
    hsh[pa[0]] -= 1
    hsh[pa[1]] -= 1
  end
end
pr.each_with_index do |pa, i|
  if hsh[pa[0]]
    a0 = hsh[pa[0]]
  else
    a0 = f_pr.count(pa[0])
    hsh[pa[0]] = a0
  end
  if hsh[pa[1]]
    a1 = hsh[pa[1]]
  else
    a1 = f_pr.count(pa[1])
    hsh[pa[1]] = a1
  end
  if a0 > 1 || a1 > 1
  	pr.delete_at(i)
    f_pr.delete_at(f_pr.index(pa[0]))
    f_pr.delete_at(f_pr.index(pa[1]))
    hsh[pa[0]] -= 1
    hsh[pa[1]] -= 1
  end
end
puts pr.size