Language: C++

/* Accepted. */
#pragma GCC optimize(3)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<unordered_map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
#define MAXN 200006
ll A[MAXN];
unordered_map<ll,ll> to,bac;
vector<ll> G[MAXN];
set<ll> pre;
ll fa[MAXN];
ll find( ll x ) { return x==fa[x]?x:(fa[x]=find(fa[x])); }
ll num[MAXN] , p;
ll dp[MAXN][2];
void work( ll u , ll fa ) {
	dp[u][1] = 1 , dp[u][0] = 0;
	ll t = 0;
	for( ll i = 0 ; i < G[u].size() ; ++ i ) {
		ll v = G[u][i];
		if( v == fa ) continue;
		work( v , u );
		dp[u][0] += dp[v][0];
		dp[u][1] += dp[v][0] + 1 ;
		t = max( t , max(dp[v][1] - dp[v][0] , 0) );
	}
	dp[u][0] += t;
}
int main() {
	freopen("input","r",stdin);
    ll n ;
    cin >> n;
	for( ll i = 1 ; i < MAXN ; ++ i ) fa[i] = i;
    for( ll i = 0 ; i < n ; ++ i ) 
        scanf("%lld",&A[i]);
    sort( A , A + n );
    for( ll i = 0 ; i < n ; ++ i ){
		if(!to[A[i]]) to[A[i]] = ++p ;
        if(to[(1LL<<(ll)log2(A[i])+1LL) - A[i]]) 
			G[to[(1LL<<(ll)log2(A[i])+1LL) - A[i]]].push_back(to[A[i]]),
			G[to[A[i]]].push_back(to[(1LL<<(ll)log2(A[i])+1LL) - A[i]]),
			fa[to[A[i]]] = to[(1LL<<(ll)log2(A[i])+1LL) - A[i]];
   	}
	for( ll i = 1 ; i <= p ; ++ i ) if( find(i)!=i && !pre.count(find(i)) )
		pre.insert(find(i)) ;
	ll ans = 0;
	for( auto& it : pre ) 
		 work( it , it ) , ans += dp[it][0];
	
    cout << ans;
}//qwq



Compiler output:
a.cc: In function 'void work(ll, ll)':
a.cc:31:33: error: no matching function for call to 'max(ll, int)'
   31 |                 t = max( t , max(dp[v][1] - dp[v][0] , 0) );
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   31 |                 t = max( t , max(dp[v][1] - dp[v][0] , 0) );
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   31 |                 t = max( t , max(dp[v][1] - dp[v][0] , 0) );
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~