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

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

amax = alist[0]

t = 1

power_of_two = []

while t < 2 * amax:

  t *= 2

  power_of_two.append(t)

result = 0

for a in alist:

  if a not in d or d[a] == 0:

    continue

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

  while True:

    if t not in d or d[t] == 0:

      break

    if a != t:

      i = min(d[a], d[t])

    else:

      i = d[a] // 2

    if i == 0:

      break

    result += i

    d[a] -= i

    d[t] -= i

    if a not in d or d[a] == 0:

      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

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

amax = alist[0]

t = 1

power_of_two = []

while t < 2 * amax:

  t *= 2

  power_of_two.append(t)

result = 0

for a in alist:

  if d[a] == 0:

    continue

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

  while True:

    if t not in d or d[t] == 0:

      break

    if a != t:

      i = min(d[a], d[t])

    else:

      i = d[a] // 2

    if i == 0:

      break

    result += i

    d[a] -= i

    d[t] -= i

    if d[a] == 0:

      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
alist = list(sorted(list(d.keys()), reverse=True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
    t *= 2
    power_of_two.append(t)
result = 0
for a in alist:
    if a not in d or d[a] == 0:
        continue
    t = power_of_two[bisect_right(power_of_two, a)] - a
    while True:
        if t not in d or d[t] == 0:
            break
        if a != t:
            i = min(d[a], d[t])
        else:
            i = d[a] // 2
        if i == 0:
            break
        result += i
        d[a] -= i
        d[t] -= i
        if a not in d or d[a] == 0:
            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
alist = list(sorted(list(d.keys()), reverse=True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
    t *= 2
    power_of_two.append(t)
result = 0
for a in alist:
    if d[a] == 0:
        continue
    t = power_of_two[bisect_right(power_of_two, a)] - a
    while True:
        if t not in d or d[t] == 0:
            break
        if a != t:
            i = min(d[a], d[t])
        else:
            i = d[a] // 2
        if i == 0:
            break
        result += i
        d[a] -= i
        d[t] -= i
        if d[a] == 0:
            break
print(result)

-    if a not in d or d[a] == 0: +    if d[a] == 0: -        if a not in d or d[a] == 0: +        if d[a] == 0: