def main():

    from collections import Counter

    import sys

    input = sys.stdin.buffer.readline



    _ = int(eval(input()))

    A = [int(i) for i in input().split()]



    ans = 0

    A.sort(reverse=True)

    c = Counter(A)



    for b in A:

        if c[b] == 0:

            continue

        a = (2 ** b.bit_length()) - b

        if a == b:

            cur = c[b]//2

        else:

            cur = min(c[a], c[b])

        ans += cur

        c[b] -= cur

        c[a] -= cur

        # print(a, b, c, ans)



    print(ans)





if __name__ == '__main__':

    main()

def main():

    from collections import Counter

    import sys

    input = sys.stdin.buffer.readline



    _ = int(eval(input()))

    A = [int(i) for i in input().split()]



    ans = 0

    c = Counter(A)

    B = sorted(list(c.keys()), reverse=True)



    for b in B:

        if c[b] == 0:

            continue

        a = (2 ** b.bit_length()) - b

        if a == b:

            cur = c[b]//2

        else:

            cur = min(c[a], c[b])

        ans += cur

        # c[b] -= cur

        c[a] -= cur



    print(ans)





if __name__ == '__main__':

    main()

def main():
    from collections import Counter
    import sys

    input = sys.stdin.buffer.readline
    _ = int(eval(input()))
    A = [int(i) for i in input().split()]
    ans = 0
    A.sort(reverse=True)
    c = Counter(A)
    for b in A:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b] // 2
        else:
            cur = min(c[a], c[b])
        ans += cur
        c[b] -= cur
        c[a] -= cur
        # print(a, b, c, ans)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    from collections import Counter
    import sys

    input = sys.stdin.buffer.readline
    _ = int(eval(input()))
    A = [int(i) for i in input().split()]
    ans = 0
    c = Counter(A)
    B = sorted(list(c.keys()), reverse=True)
    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b] // 2
        else:
            cur = min(c[a], c[b])
        ans += cur
        # c[b] -= cur
        c[a] -= cur
    print(ans)


if __name__ == "__main__":
    main()

-    A.sort(reverse=True) -    for b in A: +    B = sorted(list(c.keys()), reverse=True) +    for b in B: -        c[b] -= cur +        # c[b] -= cur -        # print(a, b, c, ans)