Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
const int M6 = 1e6+5, M5 = 1e5+5;
#define out2d(n,m,s,v) for(int i=s;i<n;i++){for(int k=s;k<m;k++)cout<<v[i][k]<<" ";cout<<endl;}
ll gcd(ll first, ll second)
{
    return !second ? first : gcd(second, first % second);
}
ll lcm(ll first, ll second)
{
    return (first / gcd(first, second)) * second;
}
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
#define loop(i,n,s) for(int i=s;i<n;i++)
#define mim(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define szz(x) ll(x.size())
#define stop exit(0);
#define mk(x,y) make_pair(x,y)
using namespace std;
#define endl '\n'
#define scanint(x) scanf("%d",&x);
#define scanll(w) scanf("%lld",&w);
#define scanchar(z) scanf("%c",&z);

/**************/


int main()
{FAST


    ll n , ans = 0 , a , mx = 0 ;
    scanll(n);
  //  cin >> n ;
    vector < ll > v ;
    vector < ll > vv(n) ;
    map < ll , ll > mp , mp1;

    for(ll i = 1 ; i <= 1e9 ;i*=2){
        v.push_back(i);
        if(i>=1e9)break;
    }

    for(int i = 0 ; i  < n ; i++){
        scanll(a);
    //    cin >> a ;
        mp[a]++;
        vv[i]=a;
    }
    sort(all(vv));
    mp1=mp;

    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r!=vv[i]&&mp[vv[i]]&&mp[r]){
                ans++;
                mp[r]--;
                mp[vv[i]]--;
            }
        }
    }
    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r==vv[i]&&mp[vv[i]]>=2){
                mp[vv[i]]-=2;
                ans++;
            }

        }
    }
    reverse(all(vv));
    mx = max(mx,ans);
    ans = 0 ;
    mp=mp1;

    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r!=vv[i]&&mp[vv[i]]&&mp[r]){
                ans++;
                mp[r]--;
                mp[vv[i]]--;
            }
        }
    }
    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r==vv[i]&&mp[vv[i]]>=2){
                mp[vv[i]]-=2;
                ans++;
            }

        }
    }
    reverse(all(v));
    mx = max(mx,ans);
    ans = 0 ;
    mp=mp1;

    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r!=vv[i]&&mp[vv[i]]&&mp[r]){
                ans++;
                mp[r]--;
                mp[vv[i]]--;
            }
        }
    }
    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r==vv[i]&&mp[vv[i]]>=2){
                mp[vv[i]]-=2;
                ans++;
            }

        }
    }
    reverse(all(vv));
    mx = max(mx,ans);
    ans = 0 ;
    mp=mp1;

    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r!=vv[i]&&mp[vv[i]]&&mp[r]){
                ans++;
                mp[r]--;
                mp[vv[ia]]--;
            }
        }
    }
    for(int i = 0 ; i <  n ;i++){
        for(int k = 0 ; k < szz(v);k++){
            ll r = max(vv[i],v[k])-min(vv[i],v[k]);
            if(r==vv[i]&&mp[vv[i]]>=2){
                mp[vv[i]]-=2;
                ans++;
            }

        }
    }
    cout << ans << endl;
















}


Compiler output:
a.cc: In function 'int main()':
a.cc:138:23: error: 'ia' was not declared in this scope; did you mean 'i'?
  138 |                 mp[vv[ia]]--;
      |                       ^~
      |                       i