# https://beta.atcoder.jp/contests/agc029/submissions/3804087

from collections import Counter



N = int(eval(input()))

a = list(map(int, input().split()))

a = sorted(a, reverse=True)

b = Counter(a)



ans = 0

for t in a:

    if b[t] == 0: continue

    s = (1 << t.bit_length()) - t

    if t == s:

        ans += b[t] // 2

        b[t] %= 2

    else:

        u = min(b[s], b[t])

        ans += u

        b[s] -= u

        b[t] -= u



print(ans)

N = int(eval(input()))

a = list(map(int, input().split()))

a = sorted(a, reverse=True)



cnt = {}

for n in a:

    cnt[n] = cnt.get(n, 0) + 1



ans = 0

for n in a:

    g = 2 ** n.bit_length()

    s = g - n

    if n == s:

        pair = cnt.get(s, 0) // 2

        ans += pair

        cnt[s] = cnt.get(s, 0) % 2

    else:

        pair = min(cnt.get(n, 0), cnt.get(s, 0))

        ans += pair

        cnt[n] = cnt.get(n, 0) - pair

        cnt[s] = cnt.get(s, 0) - pair

print(ans)

# https://beta.atcoder.jp/contests/agc029/submissions/3804087
from collections import Counter

N = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = Counter(a)
ans = 0
for t in a:
    if b[t] == 0:
        continue
    s = (1 << t.bit_length()) - t
    if t == s:
        ans += b[t] // 2
        b[t] %= 2
    else:
        u = min(b[s], b[t])
        ans += u
        b[s] -= u
        b[t] -= u
print(ans)

N = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
cnt = {}
for n in a:
    cnt[n] = cnt.get(n, 0) + 1
ans = 0
for n in a:
    g = 2 ** n.bit_length()
    s = g - n
    if n == s:
        pair = cnt.get(s, 0) // 2
        ans += pair
        cnt[s] = cnt.get(s, 0) % 2
    else:
        pair = min(cnt.get(n, 0), cnt.get(s, 0))
        ans += pair
        cnt[n] = cnt.get(n, 0) - pair
        cnt[s] = cnt.get(s, 0) - pair
print(ans)

-# https://beta.atcoder.jp/contests/agc029/submissions/3804087 -from collections import Counter - -b = Counter(a) +cnt = {} +for n in a: +    cnt[n] = cnt.get(n, 0) + 1 -for t in a: -    if b[t] == 0: -        continue -    s = (1 << t.bit_length()) - t -    if t == s: -        ans += b[t] // 2 -        b[t] %= 2 +for n in a: +    g = 2 ** n.bit_length() +    s = g - n +    if n == s: +        pair = cnt.get(s, 0) // 2 +        ans += pair +        cnt[s] = cnt.get(s, 0) % 2 -        u = min(b[s], b[t]) -        ans += u -        b[s] -= u -        b[t] -= u +        pair = min(cnt.get(n, 0), cnt.get(s, 0)) +        ans += pair +        cnt[n] = cnt.get(n, 0) - pair +        cnt[s] = cnt.get(s, 0) - pair