import bisect



n = int(eval(input()))

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



aa.sort()



a = [aa[0]]

b = [1]



for i in range(1,n):

    if a[-1]==aa[i]:

        b[-1]+=1

    else:

        a.append(aa[i])

        b.append(1)



ans = 0



for i in range(len(a)):

    while b[-i-1]!=0:

        c = 2**(len(bin(a[-i-1]))-2)-a[-i-1]

        d = bisect.bisect_left(a,c)

        if a[d]==c:

            if b[d]>1:

                ans += 1

                b[-i-1] -= 1

                b[d] -= 1

            elif b[d]==1 and a[d]!=a[-i-1]:

                ans += 1

                b[-i-1] -= 1

                b[d] -= 1

            else:

                break

        else:

            break



print(ans)

from collections import Counter



n = int(eval(input()))

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



a.sort()

c = Counter(a)



ans = 0

for x in a[::-1]:

    if c[x]>0:

        c[x]-=1

        y = 2**x.bit_length()-x

        if c[y]>0:

            c[y]-=1

            ans += 1

print(ans)
import bisect

n = int(eval(input()))
aa = list(map(int, input().split()))
aa.sort()
a = [aa[0]]
b = [1]
for i in range(1, n):
    if a[-1] == aa[i]:
        b[-1] += 1
    else:
        a.append(aa[i])
        b.append(1)
ans = 0
for i in range(len(a)):
    while b[-i - 1] != 0:
        c = 2 ** (len(bin(a[-i - 1])) - 2) - a[-i - 1]
        d = bisect.bisect_left(a, c)
        if a[d] == c:
            if b[d] > 1:
                ans += 1
                b[-i - 1] -= 1
                b[d] -= 1
            elif b[d] == 1 and a[d] != a[-i - 1]:
                ans += 1
                b[-i - 1] -= 1
                b[d] -= 1
            else:
                break
        else:
            break
print(ans)

from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
c = Counter(a)
ans = 0
for x in a[::-1]:
    if c[x] > 0:
        c[x] -= 1
        y = 2 ** x.bit_length() - x
        if c[y] > 0:
            c[y] -= 1
            ans += 1
print(ans)

-import bisect +from collections import Counter -aa = list(map(int, input().split())) -aa.sort() -a = [aa[0]] -b = [1] -for i in range(1, n): -    if a[-1] == aa[i]: -        b[-1] += 1 -    else: -        a.append(aa[i]) -        b.append(1) +a = list(map(int, input().split())) +a.sort() +c = Counter(a) -for i in range(len(a)): -    while b[-i - 1] != 0: -        c = 2 ** (len(bin(a[-i - 1])) - 2) - a[-i - 1] -        d = bisect.bisect_left(a, c) -        if a[d] == c: -            if b[d] > 1: -                ans += 1 -                b[-i - 1] -= 1 -                b[d] -= 1 -            elif b[d] == 1 and a[d] != a[-i - 1]: -                ans += 1 -                b[-i - 1] -= 1 -                b[d] -= 1 -            else: -                break -        else: -            break +for x in a[::-1]: +    if c[x] > 0: +        c[x] -= 1 +        y = 2 ** x.bit_length() - x +        if c[y] > 0: +            c[y] -= 1 +            ans += 1