import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

alias Ele = Tuple!(long, "val", int, "idx");

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(long[]);

    int[][long] asc;
    auto bh = new BinaryHeap!(Array!Ele, "a.val < b.val")();

    auto cp = new int[][](n, 0);

    foreach (i ; 0 .. n) {
        asc[a[i]] ~= i;
        bh.insert(Ele(a[i], i));
    }

    auto used = new bool[](n);
    int ans;

    while (!bh.empty) {

        auto e = bh.front;
        bh.removeFront();

        debug {
            writeln(e);
            writeln(asc);
        }

        if (used[e.idx]) {
            continue;
        }

        int d = bitlen(e.val);
        long msk = (1L<<d) - 1;
        long pr = ((~e.val) & msk) + 1;

        if (!(pr in asc)) {
            continue;
        }

        while (!asc[pr].empty && used[asc[pr].front]) {
            asc[pr].popFront();
        }

        while (!asc[pr].empty && used[asc[pr].back]) {
            asc[pr].popBack();
        }

        if (asc[pr].empty) {
            continue;
        }
        if (asc[pr].front != e.idx) {
            used[e.idx] = true;
            used[asc[pr].front] = true;
            asc[pr].popFront();
            ans++;
            continue;
        }
        if (asc[pr].back != e.idx) {
            used[e.idx] = true;
            used[asc[pr].back] = true;
            asc[pr].popBack();
            ans++;
            continue;
        }

    }

    debug {
        writeln(asc);
    }

    writeln(ans);
}

int bitlen(long x) {
    return x > 0 ? bitlen(x>>1) + 1 : 0;
}

















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}