Language: C++

#include <bits/stdc++.h>
using namespace std;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair <int, int> PR;
typedef long long ll;
typedef unsigned long long ull;

inline void OPEN(string s){
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

const int maxx = 2e5 + 7;
deque <ll> que[3];
vector <ll> a;
int n, ans;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		LL x; scanf("%lld", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	for(int i = 0; i < a.size(); i++) que[1].push_back(a[i]);
	for(int k = 31; k >= 0; k--) {
		LL ned = (1LL << k);
		int now = (k & 1);
		LL x = 0, y = 0;
		while(!que[now].empty()) {
			if(x == 0) {
				x = que[now].front();
				que[now].pop_front();
			}
			if(y == 0) {
				if(que[now].empty()) {
					que[!now].push_back(x);
					x = 0;
					break;
				}
				y = que[now].back();
				que[now].pop_back();
			}
			if(x + y == ned) {
				ans++;
				x = y = 0;
			}
			else if(x + y < ned) {
				que[!now].push_back(x);
				x = 0;
			}
			else if(x + y > ned) {
				que[2].push_back(y);
				y = 0;
			}
		}
		if(x != 0) que[!now].push_back(x);
		if(y != 0) que[2].push_back(y);
		while(!que[2].empty()) {
			que[!now].push_back(que[2].front());
			que[2].pop_front();
		}
	}
	printf("%d\n", ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:17: error: 'LL' was not declared in this scope; did you mean 'll'?
   22 |                 LL x; scanf("%lld", &x);
      |                 ^~
      |                 ll
a.cc:22:38: error: 'x' was not declared in this scope
   22 |                 LL x; scanf("%lld", &x);
      |                                      ^
a.cc:28:17: error: 'LL' was not declared in this scope; did you mean 'll'?
   28 |                 LL ned = (1LL << k);
      |                 ^~
      |                 ll
a.cc:30:19: error: expected ';' before 'x'
   30 |                 LL x = 0, y = 0;
      |                   ^~
      |                   ;
a.cc:32:28: error: 'x' was not declared in this scope
   32 |                         if(x == 0) {
      |                            ^
a.cc:36:28: error: 'y' was not declared in this scope
   36 |                         if(y == 0) {
      |                            ^
a.cc:38:61: error: 'x' was not declared in this scope
   38 |                                         que[!now].push_back(x);
      |                                                             ^
a.cc:45:28: error: 'x' was not declared in this scope
   45 |                         if(x + y == ned) {
      |                            ^
a.cc:45:32: error: 'y' was not declared in this scope
   45 |                         if(x + y == ned) {
      |                                ^
a.cc:45:37: error: 'ned' was not declared in this scope
   45 |                         if(x + y == ned) {
      |                                     ^~~
a.cc:58:20: error: 'x' was not declared in this scope
   58 |                 if(x != 0) que[!now].push_back(x);
      |                    ^
a.cc:59:20: error: 'y' was not declared in this scope
   59 |                 if(y != 0) que[2].push_back(y);
      |                    ^