Language: C++

using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int64 INF = 1LL << 40 - 1;
constexpr int64 LINF = 1LL << 60 + 1;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;
 
// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
 
// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;
 
// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
 
 
signed main() {
  INIT;
	VAR(int, n);
	map< int, int > mp;
	vector< int > a;
	REP(i, n) {
		VAR(int, j);
		a.push_back(j);
	}
 
	sort(ALL(a));
	a.erase(unique(ALL(a)), a.end());
 
	int ans = 0;
	RREP(i, a.size()) {
		mp[a[i]]++;
		RREP(j, 31) {
			int target = (1 << j) - a[i];

            if (target < a[i]) continue;

			if (target == a[i]) {
				int tmp = mp[target] / 2;
				mp[target] -= tmp * 2;
				ans += tmp;
			} else {
				int tmp1 = mp[target];
				int tmp2 = mp[a[i]];
				mp[target] -= min(tmp1, tmp2);
				mp[a[i]] -= min(tmp1, tmp2);
				ans += min(tmp1, tmp2);
			}
		}
	}
 
	OUT(ans)BR;
  
  return 0;
}

Compiler output:
a.cc:2:15: error: 'int_fast64_t' does not name a type
    2 | using int64 = int_fast64_t;
      |               ^~~~~~~~~~~~
a.cc:3:14: error: 'pair' does not name a type
    3 | using PAIR = pair<int64, int64>;
      |              ^~~~
a.cc:4:11: error: 'int64' does not name a type; did you mean 'int'?
    4 | constexpr int64 INF = 1LL << 40 - 1;
      |           ^~~~~
      |           int
a.cc:5:11: error: 'int64' does not name a type; did you mean 'int'?
    5 | constexpr int64 LINF = 1LL << 60 + 1;
      |           ^~~~~
      |           int
a.cc: In function 'void MACRO_VAR_Scan(T&)':
a.cc:13:49: error: 'cin' was not declared in this scope
   13 | template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
      |                                                 ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc: In function 'void MACRO_VAR_Scan(First&, Rest& ...)':
a.cc:14:92: error: 'cin' was not declared in this scope
   14 | template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
      |                                                                                            ^~~
a.cc:14:92: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc: In function 'int main()':
a.cc:11:14: error: 'ios' has not been declared
   11 | #define INIT ios::sync_with_stdio(false);cin.tie(0);
      |              ^~~
a.cc:35:3: note: in expansion of macro 'INIT'
   35 |   INIT;
      |   ^~~~
a.cc:11:42: error: 'cin' was not declared in this scope
   11 | #define INIT ios::sync_with_stdio(false);cin.tie(0);
      |                                          ^~~
a.cc:35:3: note: in expansion of macro 'INIT'
   35 |   INIT;
      |   ^~~~
a.cc:11:42: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
   11 | #define INIT ios::sync_with_stdio(false);cin.tie(0);
      |                                          ^~~
a.cc:35:3: note: in expansion of macro 'INIT'
   35 |   INIT;
      |   ^~~~
a.cc:10:13: error: 'int64' was not declared in this scope; did you mean 'int'?
   10 | #define int int64
      |             ^~~~~
a.cc:12:24: note: in definition of macro 'VAR'
   12 | #define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
      |                        ^~~~
a.cc:36:13: note: in expansion of macro 'int'
   36 |         VAR(int, n);
      |             ^~~
a.cc:36:18: error: 'n' was not declared in this scope
   36 |         VAR(int, n);
      |                  ^
a.cc:12:56: note: in definition of macro 'VAR'
   12 | #define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
      |                                                        ^~~~~~~~~~~
a.cc:37:9: error: 'map' was not declared in this scope
   37 |         map< int, int > mp;
      |         ^~~
a.cc:1:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
  +++ |+#include <map>
    1 | using namespace std;
a.cc:37:25: error: 'mp' was not declared in this scope
   37 |         map< int, int > mp;
      |                         ^~
a.cc:38:9: error: 'vector' was not declared in this scope
   38 |         vector< int > a;
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:38:23: error: 'a' was not declared in this scope
   38 |         vector< int > a;
      |                       ^
a.cc:39:13: error: expected ';' before 'i'
   39 |         REP(i, n) {
      |             ^
a.cc:30:27: note: in definition of macro 'REP'
   30 | #define REP(i, n) for(int i=0;i<(n);++i)
      |                           ^
a.cc:39:13: error: 'i' was not declared in this scope
   39 |         REP(i, n) {
      |             ^
a.cc:30:31: note: in definition of macro 'REP'
   30 | #define REP(i, n) for(int i=0;i<(n);++i)
      |                               ^
a.cc:40:26: error: expected ';' before 'j'
   40 |                 VAR(int, j);
      |                          ^
a.cc:12:29: note: in definition of macro 'VAR'
   12 | #define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
      |                             ^~~~~~~~~~~
a.cc:40:26: error: 'j' was not declared in this scope
   40 |                 VAR(int, j);
      |                          ^
a.cc:12:56: note: in definition of macro 'VAR'
   12 | #define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
      |                                                        ^~~~~~~~~~~
a.cc:44:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   44 |         sort(ALL(a));
      |         ^~~~
      |         short
a.cc:45:17: error: 'unique' was not declared in this scope
   45 |         a.erase(unique(ALL(a)), a.end());
      |                 ^~~~~~
a.cc:47:13: error: expected ';' before 'ans'
   47 |         int ans = 0;
      |             ^~~
a.cc:48:14: error: expected ';' before 'i'
   48 |         RREP(i, a.size()) {
      |              ^
a.cc:31:28: note: in definition of macro 'RREP'
   31 | #define RREP(i, n) for(int i=(n)-1;i>=0;--i)
      |                            ^
a.cc:48:14: error: 'i' was not declared in this scope
   48 |         RREP(i, a.size()) {
      |              ^
a.cc:31:36: note: in definition of macro 'RREP'
   31 | #define RREP(i, n) for(int i=(n)-1;i>=0;--i)
      |                                    ^
a.cc:50:22: error: expected ';' before 'j'
   50 |                 RREP(j, 31) {
      |                      ^
a.cc:31:28: note: in definition of macro 'RREP'
   31 | #define RREP(i, n) for(int i=(n)-1;i>=0;--i)
      |                            ^
a.cc:50:22: error: 'j' was not declared in this scope
   50 |                 RREP(j, 31) {
      |                      ^
a.cc:31:36: note: in definition of macro 'RREP'
   31 | #define RREP(i, n) for(int i=(n)-1;i>=0;--i)
      |                                    ^
a.cc:51:29: error: expected ';' before 'target'
   51 |                         int target = (1 << j) - a[i];
      |                             ^~~~~~
a.cc:53:17: error: 'target' was not declared in this scope
   53 |             if (target < a[i]) continue;
      |                 ^~~~~~
a.cc:55:29: error: 'target' was not declared in this scope
   55 |                         if (target == a[i]) {
      |                             ^~~~~~
a.cc:56:37: error: expected ';' before 'tmp'
   56 |                                 int tmp = mp[target] / 2;
      |                                     ^~~
a.cc:57:47: error: 'tmp' was not declared in this scope
   57 |                                 mp[target] -= tmp * 2;
      |                                               ^~~
a.cc:58:33: error: 'ans' was not declared in this scope
   58 |                                 ans += tmp;
      |                                 ^~~
a.cc:60:37: error: expected ';' before 'tmp1'
   60 |                                 int tmp1 = mp[target];
      |                                     ^~~~
a.cc:61:37: error: expected ';' before 'tmp2'
   61 |                                 int tmp2 = mp[a[i]];
      |                                     ^~~~
a.cc:62:51: error: 'tmp1' was not declared in this scope
   62 |                                 mp[target] -= min(tmp1, tmp2);
      |                                                   ^~~~
a.cc:62:57: error: 'tmp2' was not declared in this scope
   62 |                                 mp[target] -= min(tmp1, tmp2);
      |                                                         ^~~~
a.cc:62:47: error: 'min' was not declared in this scope; did you mean 'main'?
   62 |                                 mp[target] -= min(tmp1, tmp2);
      |                                               ^~~
      |                                               main
a.cc:64:33: error: 'ans' was not declared in this scope
   64 |                                 ans += min(tmp1, tmp2);
      |                                 ^~~
a.cc:18:19: error: 'cout' was not declared in this scope
   18 | #define OUT(dist) cout<<(dist);
      |                   ^~~~
a.cc:69:9: note: in expansion of macro 'OUT'
   69 |         OUT(ans)BR;
      |         ^~~
a.cc:18:19: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
   18 | #define OUT(dist) cout<<(dist);
      |                   ^~~~
a.cc:69:9: note: in expansion of macro 'OUT'
   69 |         OUT(ans)BR;
      |         ^~~
a.cc:69:13: error: 'ans' was not declared in this scope
   69 |         OUT(ans)BR;
      |             ^~~
a.cc:18:26: note: in definition of macro 'OUT'
   18 | #define OUT(dist) cout<<(dist);
      |                          ^~~~
a.cc:21:18: error: 'endl' was not declared in this scope
   21 | #define BR cout<<endl;
      |                  ^~~~
a.cc:69:17: note: in expansion of macro 'BR'
   69 |         OUT(ans)BR;
      |                 ^~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;