Language: C++

#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/range/numeric.hpp>

#ifdef _MSC_FULL_VER
#include"randomizer.hpp"
#include"debug_print.hpp"
#endif

#include<cstdlib>
#include<ctime>

namespace lib
{
	template<class T>using pair = std::pair<T, T>;
	template<class T>constexpr T pow(T base, std::uint64_t p)
	{
		T ret = T(1);
		for (std::uint64_t i = 0; i <= 63; ++i)
		{
			if (((1ull << i) & p) != 0)
			{
				ret *= base;
			}
			base *= base;
		}
		return ret;
	}
	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

	struct union_find
	{
		std::vector<int> upper;
		union_find(std::size_t size):upper(size, -1) {}

		int group(int index)
		{
			if (upper[index] == -1)
			{
				return index;
			}
			else
			{
				return upper[index] = group(upper[index]);
			}
		}

		bool merge(int x, int y)
		{
			auto gx = group(x);
			auto gy = group(y);
			if (gx != gy)
			{
				upper[gx] = gy;
				return true;
			}
			return false;
		}

		auto get()
		{
			std::map<int, std::set<int>> ret;
			for (int i = 0; i < upper.size(); ++i)
			{
				ret[group(i)].emplace(i);
			}
			return ret;
		}

		auto tops()
		{
			std::set<int> ret;
			for (int i = 0; i < upper.size(); ++i)
			{
				ret.emplace(group(i));
			}
			return ret;
		}

		bool is_same_group(int x, int y)
		{
			return group(x) == group(y);
		}
	};
}

namespace out
{
	namespace detail
	{
		template<class>struct void_out
		{
			typedef void type;
		};
		template<class T>auto write(std::ostream& ost, T const& val)
			->typename void_out<decltype(ost << val)>::type
		{
			ost << val;
		}
		template<class T, class... Ts>void write(std::ostream& ost, T const& val, Ts const&... nexts)
		{
			write(ost, val);
			ost << " ";
			write(ost, nexts...);
		}
	}
	void write_line()
	{
		std::cout << std::endl;
	}
	template<class...Ts>void write_line(Ts const&... args)
	{
		detail::write(std::cout, args...);
		write_line();
	}
	template<class Range>void write_range(Range const& rng)
	{
		for (auto const& v : rng)
		{
			write_line(v);
		}
	}
}

namespace adaptor = boost::adaptors;


namespace lib
{
	int maxflow(std::vector<std::map<int, int>>& edge, int start, int goal)
	{
		struct node_t
		{
			int prev;
			int cap;
		};
		std::vector<boost::optional<int>> node(edge.size());
		int ret = 0;
		while (true)
		{
			for (auto& n : node)
			{
				n = boost::none;
			}
			std::queue<std::pair<int, node_t>> queue;
			for (auto const& e : edge[start])
			{
				if (e.second != 0)
				{
					queue.emplace(e.first, node_t{ 0, e.second });
				}
			}
			while (queue.size())
			{
				auto top = queue.front();
				queue.pop();
				if (node[top.first])
				{
					continue;
				}
				node[top.first] = top.second.prev;
				if (top.first == goal)
				{
					int flow = top.second.cap;
					int v = goal;
					while (v != 0)
					{
						edge[v][*node[v]] += flow;
						edge[*node[v]][v] -= flow;
						v = *node[v];
					}
					ret += flow;
					goto next;
				}
				for (auto const& e : edge[top.first])
				{
					if (e.second != 0)
					{
						queue.emplace(e.first, node_t{ top.first,std::min(top.second.cap,e.second) });
					}
				}
			}
			break;
		next:;
		}
		return ret;
	}
}

bool check(std::vector<std::map<int, int>>const& edge, std::vector<int>& flag, int now, int c)
{
	if (flag[now] != 0)
	{
		return flag[now] == c;
	}
	flag[now] = c;
	for (auto const& v : edge[now])
	{
		if (!check(edge, flag, v.first, 3 - c))
		{
			return false;
		}
	}
	return true;
}

void Main()
{
	int N;
	std::cin >> N;
	lib::randomizer random;
	const std::uint32_t max = 0b111111111111111111111111111111;
	std::map<std::uint32_t, int> count;
	for (auto i : boost::irange(0, N))
	{
		std::uint32_t c;
		std::cin >> c;
		++count[c];
	}
	std::map<std::uint32_t, int> indexes;
	int index = -1;
	int K = count.size();
	std::vector<std::uint32_t> data(K);
	for (auto p : count)
	{
		indexes[p.first] = ++index;
		data[index] = p.first;
	}
	std::vector<std::map<int, int>> edge(K + 2);
	for (std::uint32_t i = 1; i <= max + 1; i <<= 1)
	{
		for (int k : boost::irange(0, K))
		{
			auto d = data[k];
			if (d >= i)
			{
				continue;
			}
			if (i - d != d && indexes.count(i - d))
			{
				edge[k].emplace(indexes[i - d], std::min(count[d], count[i - d]));
			}
		}
	}
	std::vector<int> flag(K);
	for (int i : boost::irange<int>(0, K))
	{
		if (flag[i] != 0)
		{
			continue;
		}
		if (!check(edge, flag, i, 1))
		{
			throw std::logic_error("");
		}
	}
	for (int i : boost::irange(0, K))
	{
		if (flag[i] == 1)
		{
			edge[i].emplace(K, 1);
			edge[K].emplace(i, 1);
		}
		else
		{
			edge[i].emplace(K + 1, 1);
			edge[K + 1].emplace(i, 1);
		}
	}
	out::write_line(lib::maxflow(edge, K, K + 1));
}

int main()
{
	std::cin.tie(nullptr);
	std::cin.sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(5);
	Main();
}


Compiler output:
a.cc:18:9: fatal error: boost/multi_array.hpp: No such file or directory
   18 | #include<boost/multi_array.hpp>
      |         ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.