from bisect import bisect_right

n = int(eval(input()))

d = {}

amax = 0

for a in map(int, input().split()):

  if a in d:

    d[a] += 1

  else:

    d[a] = 1

  amax = max(amax, a)

t = 1

valids = []

while t < 2 * amax:

  t *= 2

  valids.append(t)

result = 0

while True:

  prev = result

  keys = list(d.keys())

  keys.sort(reverse = True)

  for x in keys:

    if x not in d:

      continue

    t = valids[bisect_right(valids, x)] - x

    while True:

      if t not in d:

        break

      if x == t and d[x] == 1:

        break

      result += 1

      if d[x] == 1:

        del d[x]

      else:

        d[x] -= 1

      if d[t] == 1:

        del d[t]

      else:

        d[t] -= 1

      if x not in d:

        break

  if prev == result:

    break

print(result)
from bisect import bisect_right

n = int(eval(input()))

d = {}

amax = 0

for a in map(int, input().split()):

  if a in d:

    d[a] += 1

  else:

    d[a] = 1

amax = max(d.keys())

t = 1

valids = []

while t < 2 * amax:

  t *= 2

  valids.append(t)

result = 0

while True:

  prev = result

  keys = list(d.keys())

  keys.sort(reverse = True)

  for x in keys:

    if x not in d:

      continue

    t = valids[bisect_right(valids, x)] - x

    while True:

      if t not in d:

        break

      if x == t and d[x] == 1:

        break

      result += 1

      if d[x] == 1:

        del d[x]

      else:

        d[x] -= 1

      if d[t] == 1:

        del d[t]

      else:

        d[t] -= 1

      if x not in d:

        break

  if prev == result:

    break

print(result)
from bisect import bisect_right

n = int(eval(input()))
d = {}
amax = 0
for a in map(int, input().split()):
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
    amax = max(amax, a)
t = 1
valids = []
while t < 2 * amax:
    t *= 2
    valids.append(t)
result = 0
while True:
    prev = result
    keys = list(d.keys())
    keys.sort(reverse=True)
    for x in keys:
        if x not in d:
            continue
        t = valids[bisect_right(valids, x)] - x
        while True:
            if t not in d:
                break
            if x == t and d[x] == 1:
                break
            result += 1
            if d[x] == 1:
                del d[x]
            else:
                d[x] -= 1
            if d[t] == 1:
                del d[t]
            else:
                d[t] -= 1
            if x not in d:
                break
    if prev == result:
        break
print(result)

from bisect import bisect_right

n = int(eval(input()))
d = {}
amax = 0
for a in map(int, input().split()):
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
amax = max(d.keys())
t = 1
valids = []
while t < 2 * amax:
    t *= 2
    valids.append(t)
result = 0
while True:
    prev = result
    keys = list(d.keys())
    keys.sort(reverse=True)
    for x in keys:
        if x not in d:
            continue
        t = valids[bisect_right(valids, x)] - x
        while True:
            if t not in d:
                break
            if x == t and d[x] == 1:
                break
            result += 1
            if d[x] == 1:
                del d[x]
            else:
                d[x] -= 1
            if d[t] == 1:
                del d[t]
            else:
                d[t] -= 1
            if x not in d:
                break
    if prev == result:
        break
print(result)

-    amax = max(amax, a) +amax = max(d.keys())