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(sorted(list(d.keys()), 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 = {}

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

keys = list(sorted(list(d.keys()), reverse = True))

for a in keys:

  if a not in d:

    continue

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

  while True:

    if t not in d:

      break

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

      break

    result += 1

    if d[a] == 1:

      del d[a]

    else:

      d[a] -= 1

    if d[t] == 1:

      del d[t]

    else:

      d[t] -= 1

    if a not in d:

      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(sorted(list(d.keys()), 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 = {}
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
keys = list(sorted(list(d.keys()), reverse=True))
for a in keys:
    if a not in d:
        continue
    t = valids[bisect_right(valids, a)] - a
    while True:
        if t not in d:
            break
        if a == t and d[a] == 1:
            break
        result += 1
        if d[a] == 1:
            del d[a]
        else:
            d[a] -= 1
        if d[t] == 1:
            del d[t]
        else:
            d[t] -= 1
        if a not in d:
            break
print(result)

-amax = 0 -while True: -    prev = result -    keys = list(sorted(list(d.keys()), 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 +keys = list(sorted(list(d.keys()), reverse=True)) +for a in keys: +    if a not in d: +        continue +    t = valids[bisect_right(valids, a)] - a +    while True: +        if t not in d: +            break +        if a == t and d[a] == 1: +            break +        result += 1 +        if d[a] == 1: +            del d[a] +        else: +            d[a] -= 1 +        if d[t] == 1: +            del d[t] +        else: +            d[t] -= 1 +        if a not in d: +            break