#pragma once #include #include #include #include #include #include #include #include #include #include #include #include template struct Binary { static_assert(std::is_integral_v); explicit Binary(T value_, int length_ = std::numeric_limits::digits) : value{value_}, length{length_} {} T value; int length; }; namespace std { template ostream &operator<<(ostream &out, const tuple &t) { out << '('; std::apply( [&out](const T &...args) { int index = 0; ((out << args << (++index != sizeof...(T) ? ", " : "")), ...); }, t); return out << ')'; } template ostream &operator<<(ostream &out, const pair &v) { return out << tuple(v.first, v.second); } template ostream &operator<<(ostream &out, const Binary &b) { out << "("; for (auto i : std::ranges::iota_view(0, b.length)) { out << (b.value >> i & 1); } return out << ")_2"; } template ostream &operator<<(ostream &out, Range &&range) requires(!same_as, char>) { out << "["; bool first = true; for (auto &&elem : range) { if (first) { first = false; } else { out << ", "; } out << elem; } return out << "]"; } template ostream &operator<<(ostream &out, priority_queue pq) { vector v; while (!pq.empty()) { v.push_back(pq.top()); pq.pop(); } return out << v; } } // namespace std struct DebugLine { explicit DebugLine(int lineno) { std::cerr << lineno << "L "; } ~DebugLine() { std::cerr << std::endl; } template DebugLine &operator<<(T &&v) { std::cerr << std::forward(v); return *this; } }; #define KV(x) #x "=" << (x) << ";" #define DEBUG DebugLine(__LINE__)