Language: C++

#include <bits/stdc++.h>

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

int tob(int x){
	int ret = 0;
	for(;x;x >>= 1)ret++;
	return ret;
}


signed main(){
	int n; cin >> n;
	vector<int> a(n);
	for(auto &e: a)cin >> e;
	int ans = 0;
	sort(ALL(a));
	for(auto itr = a.rbegin(); itr != a.rend(); ++itr){
		if(*itr == -1)break;
		int c = (1 << tob(*itr)) - *itr;
//		cerr << c << " ";
		auto lb = lower_bound(ALL(a), c);
		if(*lb == c && vector<int>::iterator(itr) != lb){
			ans++;
			*lb = -1;
		}
	}
	cout << ans << endl;



	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:26:57: error: no matching function for call to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::__normal_iterator(std::reverse_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >&)'
   26 |                 if(*lb == c && vector<int>::iterator(itr) != lb){
      |                                                         ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:1074:9: note: candidate: 'template<class _Iter, class> __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const __gnu_cxx::__normal_iterator<_Iter, _Container>&) [with <template-parameter-2-2> = _Iter; _Iterator = int*; _Container = std::vector<int>]'
 1074 |         __normal_iterator(const __normal_iterator<_Iter, _Container>& __i)
      |         ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1074:9: note:   template argument deduction/substitution failed:
a.cc:26:57: note:   'std::reverse_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >' is not derived from 'const __gnu_cxx::__normal_iterator<_Iter, std::vector<int> >'
   26 |                 if(*lb == c && vector<int>::iterator(itr) != lb){
      |                                                         ^
/usr/include/c++/14/bits/stl_iterator.h:1067:7: note: candidate: '__gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const _Iterator&) [with _Iterator = int*; _Container = std::vector<int>]'
 1067 |       __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1067:42: note:   no known conversion for argument 1 from 'std::reverse_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >' to 'int* const&'
 1067 |       __normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
      |                         ~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_iterator.h:1063:26: note: candidate: 'constexpr __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator() [with _Iterator = int*; _Container = std::vector<int>]'
 1063 |       _GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
      |                          ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1063:26: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_iterator.h:1038:11: note: candidate: 'constexpr __gnu_cxx::__normal_iterator<int*, std::vector<int> >::__normal_iterator(const __gnu_cxx::__normal_iterator<int*, std::vector<int> >&)'
 1038 |     class __normal_iterator
      |           ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1038:11: note:   no known conversion for argument 1 from 'std::reverse_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >' to 'const __gnu_cxx::__normal_iterator<int*, std::vector<int> >&'
/usr/include/c++/14/bits/stl_iterator.h:1038:11: note: candidate: 'constexpr __gnu_cxx::__normal_iterator<int*, std::vector<int> >::__normal_iterator(__gnu_cxx::__normal_iterator<int*, std::vector<int> >&&)'
/usr/include/c++/14/bits/stl_iterator.h:1038:11: note:   no known conversion for argument 1 from 'std::reverse_iterator<__gnu_cxx::__normal_iterator<int*, std::vector<int> > >' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >&&'