#include <iostream>
#include <set>
#include <algorithm>

struct Vector3 {
	int x, y, z;
};
struct Area {
	Vector3 first;
	Vector3 second;
	inline bool inArea(Vector3 &vec) const
	{
		auto minX = std::min(first.x, second.x);
		auto maxX = std::max(first.x, second.x);
		auto minY = std::min(first.y, second.y);
		auto maxY = std::max(first.y, second.y);
		auto minZ = std::min(first.z, second.z);
		auto maxZ = std::max(first.z, second.z);
		auto &x = vec.x;
		auto &y = vec.y;
		auto &z = vec.z;

		return x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ;
	}

	inline bool operator<(Area const& rhs) const
	{
		return std::max(first.x, second.x) < std::max(rhs.first.x, rhs.second.x);
	}
};

int debugCnt = 0;
std::set<Area> areas;
// std::map<int, std::set<Area>::iterator> myMap;
bool canPlaceBlock(Vector3 block)
{
	for (auto it = areas.lower_bound({block, block}); it != areas.end() && std::min(it->first.x, it->second.x) <= block.x; ++it) {
		++debugCnt;
		if (it->inArea(block))
			return false;
	}
	return true;
}

int main() {
	// test code
	for (int l = 0; l <= 10000; l++) {
		int r = l + 100;
		Vector3 first{l, l, l};
		Vector3 second{r, r, r};
		areas.insert({first, second});
	}
	std::cout << (canPlaceBlock({123, 456, 789}) ? "true" : "false") << '\n';
	std::cout << debugCnt << '\n';
	return 0;
}