Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
//typedef struct aaaaa{
//  int x,y,t;
//}Grid;
using namespace std;
const int MAX_V=401120;
struct edge{ int to,cap,rev; };
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
vector<int>hoge(222222);
vector<int>be;
vector<int>memomo;
  vector<pair<int,int> >ho;
  vector<int>ser;
void add_edge(int from,int to,int cap){
  G[from].pb((edge){to,cap,(int)G[to].size()});
  G[to].pb((edge){from,0,(int)G[from].size()-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>que;
  level[s]=0;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(e.cap>0 && level[e.to]<0){
	level[e.to]=level[v]+1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e = G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	auto h = lower_bound(ALL(be),ho[v].F);
	if(*h == ho[v].F){
	  memomo[h-be.begin()]+=d;
	}
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  } 
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  for(;;){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}

int main(){
  int n;cin>>n;
  //hoge.resize(n);

  for(int i=0;i<n;i++){
    cin>>hoge[i];
  }

  sort(ALL(hoge));
  int cnt=1;

  int si=0;
  for(int i=0;i<hoge.size()-1;i++){
    while(i<hoge.size()-1&&hoge[i]==hoge[i+1]){
      cnt++;
      i++;
    }
    if(hoge[i]==0){cnt=1;continue;}
    si++;
    ho.pb(mp(hoge[i],cnt));
    ser.pb(hoge[i]);
    add_edge(200009,si-1,cnt);
    add_edge(si-1+200111,200010,cnt);
    cnt=1;
    if(i==hoge.size()-2&&hoge[i]!=hoge[i+1]){
      ho.pb(mp(hoge[i+1],1));
      ser.pb(hoge[i+1]);
      add_edge(200009,si,1);
      add_edge(si+200111,200010,1);
    }
  }

 
  be.pb(1);
  ll kake=2;
  while(kake<=2000000000){
    be.pb((int)kake);
    kake*=2;
  }
  memomo.resize(be.size());
  ser.pb(2*INF);
  for(int i=0;i<ho.size()-1;i++){
    for(int j=0;j<be.size();j++){
      if(be[j]-ho[i].F>=0){
	auto h = lower_bound(ser.begin()+(i+1),ser.end(),be[j]-ho[i].F);
	//cout<<*h<<" "<<be[j]-ho[i].F<<endl;
	if(*h == be[j]-ho[i].F){
	  add_edge(i,(h-ser.begin())+200111,ho[i].S);
	}
      }
    }
  }
  // for(int i=0;i<5;i++){
  //   for(int j=0;j<G[i].size();j++)
  //     cout<<G[i][j].to<<" ";
  //   cout<<endl;
  // }
  //  cout<<"!"<<endl;
  be[i].pb(2*INF);
  int ans=max_flow(200009,200010);
  for(int i=0;i<be.size();i++){
    auto h = lower_bound(ALL(ser),be[i]);
    if(*h==be[i]){
     
      //cout<<ho[(h-ser.begin())].F<<endl;
      ans+=max((G[(h-ser.begin())+200111][0].cap-memomo[i])/2,0);
      //cout<<be[i]<<" "<<ans<<endl;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:140:6: error: 'i' was not declared in this scope; did you mean 'si'?
  140 |   be[i].pb(2*INF);
      |      ^
      |      si