#ifdef USE_BUFFER_IO #include "optimization.h" #else #include #endif namespace template_io { namespace meta { template struct type_list { }; template class make_n_list { template> struct impl; template struct impl> { template using wrap = T; using type = type_list...>; }; public: using type = typename impl<>::type; }; template using make_n_list_t = typename make_n_list::type; template struct head { using type = T; }; template using head_t = typename head::type; } namespace input { template struct reader { }; #ifdef USE_BUFFER_IO template struct reader>> { static auto func() { return readInt(); } }; template<> struct reader { static auto func() { return readDouble(); } }; #else template struct reader>> { static auto func() { T x; std::cin >> x; return x; } }; template<> struct reader { static auto func() { double x; std::cin >> x; return x; } }; #endif template auto read() { return reader::func(); } template= 2>> auto read() { return std::tuple{read()...}; } template= 1>> auto read(meta::type_list) { return read(); } template auto read() { return read(meta::make_n_list_t()); } struct read_s { template operator T() { return read(); } }; auto read() { return read_s(); } } namespace output { template struct writer { }; #ifdef USE_BUFFER_IO template struct writer>> { static void func(const T& t, char end) { writeInt(t, end); } }; template<> struct writer { static auto func(double d, char end) { writeDouble(d); if (end) writeChar(end); } }; #else template struct writer>> { static void func(const T& t, char end) { std::cout << t << end; } }; template<> struct writer { static auto func(double d, char end) { std::cout << d << end; } }; #endif template void write(T t, char end = '\0') { return writer::func(t, end); } } using input::read, output::write; }