Language: C++

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int N, A[200000];
vector<vector<int>> G(200000);

struct edge {
  int to;
  int label;
};

vector<pii> gabow_edmonds(const vector<vector<int>>& gra){
  // E0 - 初期化
  int N = gra.size();
  vector<vector<edge>> g(N + 1);
  vector<pii> edges;
  {
    int cnt = N + 1;
    for(int i = 0;i < N;i++){
      for(auto to : gra[i]){
        if(i < to){
          g[to + 1].push_back({i + 1, cnt});
          g[i + 1].push_back({to + 1, cnt++});
          edges.push_back({i + 1, to + 1});
        }
      }
    }
  }
  vector<int> mate(N + 1 , 0);
  vector<int> label(N + 1 , -1);
  vector<int> first(N + 1 , 0);
  queue<int> que;

  // firstの遅延評価
  function<int(int)> eval_first = [&](int x){
    if(label[first[x]] < 0) return first[x];
    first[x] = eval_first(first[x]);
    return first[x];
  };

  // サブルーチンR
  function<void(int, int)> rematch = [&](int v, int w){
    // R1
    int t = mate[v];
    mate[v] = w;
    if(mate[t] != v) return;
    // R2
    if(label[v] <= N){
      mate[t] = label[v];
      rematch(label[v] , t);
    }
    // R3
    else{
      int x = edges[label[v] - N - 1].first;
      int y = edges[label[v] - N - 1].second;
      rematch(x , y);
      rematch(y , x);
    }
  };

  function<void(int, int, int)> assignLabel = [&](int x, int y, int num){
    // L0
    int r = eval_first(x);
    int s = eval_first(y);
    int join = 0;
    if(r == s) return;
    // -numがフラグ
    label[r] = -num;
    label[s] = -num;
    while(true){
      // L1
      if(s != 0) swap(r , s);
      // L2
      r = eval_first(label[mate[r]]);
      if(label[r] == -num){
        join = r;
        break;
      }
      label[r] = -num;
    }
    // L3
    int v = first[x];
    // L4
    while(v != join){
      que.push(v);
      label[v] = num;
      first[v] = join;
      v = first[label[mate[v]]];
    }
    // L3
    v = first[y];
    // L4
    while(v != join){
      que.push(v);
      label[v] = num;
      first[v] = join;
      v = first[label[mate[v]]];
    }
    // L5は遅延評価しているため不要
    // L6
    return;
  };

  function<bool(int)> augment_check = [&](int u){
    // E1 後半
    first[u] = 0;
    label[u] = 0;
    que.push(u);
    while(!que.empty()){
      // E2
      int x = que.front();
      que.pop();
      for(auto e : g[x]){
        int y = e.to;
        // E3
        if(mate[y] == 0 && y != u){
          mate[y] = x;
          rematch(x , y);
          return true;
        }
        // E4
        else if(label[y] >= 0){
          assignLabel(x , y , e.label);
        }
        // E5
        else if(label[mate[y]] < 0){
          label[mate[y]] = x;
          first[mate[y]] = y;
          que.push(mate[y]);
        }
        // E6
      }
    }
    return false;
  };

  for(int i = 1;i <= N;i++){
    // E1
    que = queue<int>();
    if(mate[i] != 0) continue;
    if(augment_check(i)){
      // E7
      fill(label.begin(), label.end(), -1);
    }
  }

  vector<pii> ans;
  for(int i = 1;i <= N;i++){
    if(i < mate[i]){
      ans.push_back({i , mate[i]});
    }
  }
  return ans;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N);

    REP(i, N) {
        ll p = 2;
        while (true) {
            if (p > 2e9) break;

            int rest = p - A[i];
            p <<= 1;
            if (rest < 1) continue;

            auto lb = lower_bound(A, A + N, rest);
            auto ub = upper_bound(A, A + N, rest);
            for (auto it = lb; it != ub; it++) {
                if (it - A == i) continue;
                G[i].push_back(it - A);
            }
        }
    }

    cout << gabow_edmonds(G).size() << endl;
    return 0;
}

Compiler output:
a.cc: In function 'std::vector<std::pair<int, int> > gabow_edmonds(const std::vector<std::vector<int> >&)':
a.cc:50:3: error: 'function' was not declared in this scope
   50 |   function<int(int)> eval_first = [&](int x){
      |   ^~~~~~~~
a.cc:8:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    7 | #include <queue>
  +++ |+#include <functional>
    8 | 
a.cc:50:12: error: expected primary-expression before 'int'
   50 |   function<int(int)> eval_first = [&](int x){
      |            ^~~
a.cc:57:25: error: expression list treated as compound expression in functional cast [-fpermissive]
   57 |   function<void(int, int)> rematch = [&](int v, int w){
      |                         ^
a.cc:57:12: error: expected primary-expression before 'void'
   57 |   function<void(int, int)> rematch = [&](int v, int w){
      |            ^~~~
a.cc:76:30: error: expression list treated as compound expression in functional cast [-fpermissive]
   76 |   function<void(int, int, int)> assignLabel = [&](int x, int y, int num){
      |                              ^
a.cc:76:12: error: expected primary-expression before 'void'
   76 |   function<void(int, int, int)> assignLabel = [&](int x, int y, int num){
      |            ^~~~
a.cc:119:12: error: expected primary-expression before 'bool'
  119 |   function<bool(int)> augment_check = [&](int u){
      |            ^~~~
a.cc:156:8: error: 'augment_check' was not declared in this scope
  156 |     if(augment_check(i)){
      |        ^~~~~~~~~~~~~