eval(input())

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



answer = 0

count = {}



for nb in nbs:

    count[nb] = count.get(nb, 0) + 1



for nb in sorted(list(count.keys()), reverse=True):

    searching = (1 << nb.bit_length()) - nb

    nb_count = count[nb]

    sr_count = count.get(searching, 0)

    if sr_count:

        if nb == searching:

            increment = nb_count // 2

        else:

            increment = nb_count if nb_count < sr_count else sr_count

            count[searching] -= increment

        answer += increment



print(answer)
def main(l):

    counts = {}

    answer = 0

    for nb in l:

        counts[nb] = counts.get(nb, 0) + 1

    for a in sorted(list(counts.keys()), reverse=True):

        b = (1 << a.bit_length()) - a

        c_a = counts[a]

        c_b = counts.get(b)

        if c_b:

            if a == b:

                answer += c_a // 2

            else:

                increment = c_a if c_a < c_b else c_b

                counts[a] -= increment

                counts[b] -= increment

                answer += increment



    return answer





if __name__ == '__main__':

    eval(input())

    print((main(list(map(int, input().split())))))
eval(input())
nbs = list(map(int, input().split()))
answer = 0
count = {}
for nb in nbs:
    count[nb] = count.get(nb, 0) + 1
for nb in sorted(list(count.keys()), reverse=True):
    searching = (1 << nb.bit_length()) - nb
    nb_count = count[nb]
    sr_count = count.get(searching, 0)
    if sr_count:
        if nb == searching:
            increment = nb_count // 2
        else:
            increment = nb_count if nb_count < sr_count else sr_count
            count[searching] -= increment
        answer += increment
print(answer)

def main(l):
    counts = {}
    answer = 0
    for nb in l:
        counts[nb] = counts.get(nb, 0) + 1
    for a in sorted(list(counts.keys()), reverse=True):
        b = (1 << a.bit_length()) - a
        c_a = counts[a]
        c_b = counts.get(b)
        if c_b:
            if a == b:
                answer += c_a // 2
            else:
                increment = c_a if c_a < c_b else c_b
                counts[a] -= increment
                counts[b] -= increment
                answer += increment
    return answer


if __name__ == "__main__":
    eval(input())
    print((main(list(map(int, input().split())))))

-eval(input()) -nbs = list(map(int, input().split())) -answer = 0 -count = {} -for nb in nbs: -    count[nb] = count.get(nb, 0) + 1 -for nb in sorted(list(count.keys()), reverse=True): -    searching = (1 << nb.bit_length()) - nb -    nb_count = count[nb] -    sr_count = count.get(searching, 0) -    if sr_count: -        if nb == searching: -            increment = nb_count // 2 -        else: -            increment = nb_count if nb_count < sr_count else sr_count -            count[searching] -= increment -        answer += increment -print(answer) +def main(l): +    counts = {} +    answer = 0 +    for nb in l: +        counts[nb] = counts.get(nb, 0) + 1 +    for a in sorted(list(counts.keys()), reverse=True): +        b = (1 << a.bit_length()) - a +        c_a = counts[a] +        c_b = counts.get(b) +        if c_b: +            if a == b: +                answer += c_a // 2 +            else: +                increment = c_a if c_a < c_b else c_b +                counts[a] -= increment +                counts[b] -= increment +                answer += increment +    return answer + + +if __name__ == "__main__": +    eval(input()) +    print((main(list(map(int, input().split())))))