Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

struct node {
    int val;
    node *lch;
    node *rch;
};

node *insert(node *p, int x) {
    if (p == NULL) {
        node *q = new node;
        q->val = x;
        q->lch = q->rch = NULL;
        return q;
    } else {
        if (x < p->val) {
            p->lch = insert(p->lch, x);
        } else {
            p->rch = insert(p->rch, x);
        }
        return p;
    }
}

bool find(node *p, int x) {
    if (p == NULL) {
        return false;
    } else if (x == p->val) {
        return true;
    } else if (x < p->val) {
        return find(p->lch, x);
    } else {
        return find(p->rch, x);
    }
}

node *remove(node *p, int x) {
    if (p == NULL) {
        return NULL;
    } else if (x < p->val) {
        p->lch = remove(p->lch, x);
    } else if (x > p->val) {
        p->rch = remove(p->rch, x);
    } else if (p->lch == NULL) {
        node *q = p->rch;
        delete p;
        return q;
    } else if (p->lch->rch == NULL) {
        node *q = p->lch;
        q->rch = p->rch;
        delete p;
        return q;
    } else {
        node *q;
        for (q = p->lch; q->rch->rch != NULL; q = q->rch);
        node *r = q->rch;
        q->rch = r->lch;
        r->lch = p->lch;
        r->rch = p->rch;
        delete p;
        return r;
    }
    return p;
}

int find_max(node *p) {
    if (p == NULL) {
        return 0;
    } else {
        if (p->rch == NULL) {
            return p->val;
        } else {
            return find_max(p->rch);
        }
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector <int> A;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(), A.end());
    bool used[n];
    fill(used, used+n, false);

    int ans = 0;
    int w = (1 << 30);
    int point = n-1;
    while (point >= 0) {
        if (used[point]) {
            point--;
        } else {
            used[point] = true;
            while (A[point] * 2 < w) {
                w /= 2;
            }

            if (A[point] * 2 == w) {
                if (A[point] == A[point-1]) {
                    ans++;
                    used[point-1]
                    point--;
                    continue;
                }
            }
            int t = (upper_bound(A.begin(), A.end(), w-A[point]) - A.begin());
            t--;
            while (true) {
                if (A[t] != w - A[point]) {
                    break;
                } else if (used[t]) {
                    t--;
                } else {
                    used[t] = true;
                    ans++;
                    break;
                }
            }
            point--;
        }
    }

//    int ans = 0;
//    int w = (1 << 30);
//    while (w > 1) {
//        int mx = find_max(root);
//        if (mx == 0) break;
//        while (mx * 2 < w) {
//            w /= 2;
//        }
//        root = remove(root, mx);
//        if (find(root, w-mx)) {
//            ans++;
//            root = remove(root, w-mx);
//        }
//    }

    cout << ans << "\n";
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:118:34: error: expected ';' before 'point'
  118 |                     used[point-1]
      |                                  ^
      |                                  ;
  119 |                     point--;
      |                     ~~~~~