// Copyright Johannes Kapfhammer 2019-2022. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef SOI_HEADER_IO #define SOI_HEADER_IO #include #include #include #include template T read() { T x; std::cin >> x; return x; } template std::pair read() { return std::pair{read(), read()}; } template std::tuple read() { return std::tuple{read(), read(), read(), read()...}; } int64_t read_int() { return read(); } char read_char() { return read(); } double read_double() { return read(); } std::string read_string() { return read(); } template std::vector read_vector(int n) { assert(n >= 0); std::vector v; v.reserve(n); std::generate_n(std::back_inserter(v), n, read); return v; } namespace soi { namespace io { template inline typename std::enable_if::value, std::basic_ostream &>::type print(std::basic_ostream &stream, const T &x) { return stream << x; } template inline std::basic_ostream& print(std::basic_ostream &stream, std::string const& x) { return stream << x; } template std::basic_ostream & print(std::basic_ostream &stream, const bool &x) { return stream << (x ? "true" : "false"); } struct space_separated_delims { static const ::soi::prettyprint::delimiters_values values; }; const ::soi::prettyprint::delimiters_values space_separated_delims::values = { "", " ", "" }; template inline typename std::enable_if<::soi::prettyprint::is_container::value, std::basic_ostream &>::type print(std::basic_ostream &stream, const T &x) { return ::soi::prettyprint::pretty_print(stream, soi::prettyprint::custom_delims(x)); } template void print_with_space(std::basic_ostream &stream, T&& x) { stream << ' '; ::soi::io::print(stream, std::forward(x)); } } } template void print(Arg&& arg, Args&&... args) { soi::io::print(std::cout, arg); using expander = bool[]; (void)expander{0, (soi::io::print_with_space(std::cout, std::forward(args)), false)...}; std::cout << '\n'; } void print() { std::cout << '\n'; } template void print_no_space(Args&&... args) { using expander = bool[]; (void)expander{0, (soi::io::print(std::cout, std::forward(args)), false)...}; } #endif // SOI_HEADER_IO