import strutils, sequtils, algorithm, tables, math
let get = iterator: string {.closure.} =
  for s in stdin.readAll.split: yield s
proc read: int {.inline.} = get().parseInt
template rep(a,b): seq = newSeqWith(b,a)

let n = read()
let a = read().rep(n).sorted(cmp, Descending)
var re = initTable[int,int]()
for a in a: re.mgetOrPut(a,0).inc
var cnt = 0
for a in a:
  if a notin re: continue
  let b = (a+1).nextPowerofTwo-a
  if b in re:
    if a == b:
      if re[a] >= 2:
        if re[a] == 2: re.del a else: re[a].dec 2
        cnt.inc
    else:
      re[a].dec; if re[a]==0: re.del a
      re[b].dec; if re[b]==0: re.del b
echo cnt
