library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub yuruhi/library

:heavy_check_mark: test/IO_2Dvector_and_Ruby_push_back_Transpose_Map_Sum.test.cpp

Depends on

Code

#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/all/ITP1_7_C"
#include "./../Utility/Scanner.cpp"
#include "./../Utility/Printer.cpp"
#include "./../Utility/Ruby.cpp"
#include <iostream>
using namespace std;

int main() {
	int h = in, w = in;
	vector<vector<int>> a = in[h][w];
	a << (a | Transpose | Map([](const auto& b) { return b | Sum; }));
	for (auto& v : a) {
		v << (v | Sum);
	}
	out(a);
}
#line 1 "test/IO_2Dvector_and_Ruby_push_back_Transpose_Map_Sum.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/all/ITP1_7_C"
#line 2 "Utility/Scanner.cpp"
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <type_traits>

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	template <class T, class = void> struct has_scan : std::false_type {};
	template <class T>
	struct has_scan<T, std::void_t<decltype(std::declval<T>().template scan<Scanner>())>>
	    : std::true_type {};

public:
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		scan(c);
		return c;
	}
	template <class T> static void scan(T& v) {
		if (has_scan<T>::value) {
			v.template scan<Scanner>();
		} else {
			std::cin >> v;
		}
	}
	static void scan(char& v) {
		while (std::isspace(v = gc()))
			;
	}
	static void scan(bool& v) {
		v = next_char() != '0';
	}
	static void scan(std::vector<bool>::reference v) {
		bool b;
		scan(b);
		v = b;
	}
	static void scan(std::string& v) {
		v.clear();
		for (char c = next_char(); !std::isspace(c); c = gc()) v += c;
	}
	static void scan(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; std::isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void scan(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; std::isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void scan(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; std::isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void scan(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; std::isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void scan(std::pair<T, U>& v) {
		scan(v.first);
		scan(v.second);
	}
	template <class T, std::enable_if_t<!std::is_same_v<bool, T>, std::nullptr_t> = nullptr>
	static void scan(std::vector<T>& v) {
		for (auto& e : v) scan(e);
	}
	template <class T, std::enable_if_t<std::is_same_v<bool, T>, std::nullptr_t> = nullptr>
	static void scan(std::vector<T>& v) {
		for (auto e : v) scan(e);
	}

private:
	template <std::size_t N = 0, class T> static void scan_tuple_impl(T& v) {
		if constexpr (N < std::tuple_size_v<T>) {
			scan(std::get<N>(v));
			scan_tuple_impl<N + 1>(v);
		}
	}

public:
	template <class... T> static void scan(std::tuple<T...>& v) {
		scan_tuple_impl(v);
	}

private:
	struct Read2DVectorHelper {
		std::size_t h, w;
		Read2DVectorHelper(std::size_t _h, std::size_t _w) : h(_h), w(_w) {}
		template <class T> operator std::vector<std::vector<T>>() {
			std::vector vector(h, std::vector<T>(w));
			scan(vector);
			return vector;
		}
	};
	struct ReadVectorHelper {
		std::size_t n;
		ReadVectorHelper(std::size_t _n) : n(_n) {}
		template <class T> operator std::vector<T>() {
			std::vector<T> vector(n);
			scan(vector);
			return vector;
		}
		auto operator[](std::size_t m) {
			return Read2DVectorHelper(n, m);
		}
	};

public:
	template <class T> T read() const {
		T result;
		scan(result);
		return result;
	}
	template <class T> auto read(std::size_t n) const {
		std::vector<T> result(n);
		scan(result);
		return result;
	}
	template <class T> auto read(std::size_t h, std::size_t w) const {
		std::vector result(h, std::vector<T>(w));
		scan(result);
		return result;
	}
	std::string read_line() const {
		std::string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	auto operator[](std::size_t n) const {
		return ReadVectorHelper(n);
	}
	auto operator[](const std::pair<std::size_t, std::size_t>& nm) const {
		return Read2DVectorHelper(nm.first, nm.second);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		scan(h);
		operator()(std::forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Column;
	template <template <class...> class V, class Head, class... Tail>
	struct Column<V, Head, Tail...> {
		template <class... Args> using vec = V<std::vector<Head>, Args...>;
		using type = typename Column<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Column<V> { using type = V<>; };
	template <class... T> using column_t = typename Column<std::tuple, T...>::type;
	template <std::size_t N = 0, class T> void column_impl(T& t) const {
		if constexpr (N < std::tuple_size_v<T>) {
			auto& vec = std::get<N>(t);
			using V = typename std::remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			column_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto column(std::size_t h) const {
		column_t<T...> result;
		while (h--) column_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(std::string, __VA_ARGS__)
#line 5 "Utility/Printer.cpp"
#include <array>
#line 7 "Utility/Printer.cpp"
#include <string_view>
#include <optional>
#include <charconv>
#line 11 "Utility/Printer.cpp"
#include <cstring>
#include <cassert>

class Printer {
public:
	struct BoolString {
		std::string_view t, f;
		BoolString(std::string_view _t, std::string_view _f) : t(_t), f(_f) {}
	};
	struct Separator {
		std::string_view div, sep, last;
		Separator(std::string_view _div, std::string_view _sep, std::string_view _last)
		    : div(_div), sep(_sep), last(_last) {}
	};

	inline static const BoolString Yes{"Yes", "No"}, yes{"yes", "no"}, YES{"YES", "NO"},
	    Int{"1", "0"}, Possible{"Possible", "Impossible"};
	inline static const Separator space{" ", " ", "\n"}, no_space{"", "", "\n"},
	    endl{"\n", "\n", "\n"}, comma{",", ",", "\n"}, no_endl{" ", " ", ""},
	    sep_endl{" ", "\n", "\n"};

	BoolString bool_str{Yes};
	Separator separator{space};

private:
	template <class T, class = void> struct has_print : std::false_type {};
	template <class T>
	struct has_print<T,
	                 std::void_t<decltype(std::declval<T>().print(std::declval<Printer>()))>>
	    : std::true_type {};

public:
	void print(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = std::to_chars(std::begin(buf), std::end(buf), v);
		    e == std::errc{}) {
			print(std::string_view(buf, ptr - buf));
		} else {
			assert(false);
		}
	}
	void print(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = std::to_chars(std::begin(buf), std::end(buf), v);
		    e == std::errc{}) {
			print(std::string_view(buf, ptr - buf));
		} else {
			assert(false);
		}
	}
	void print(bool v) const {
		print(v ? bool_str.t : bool_str.f);
	}
	void print(std::vector<bool>::reference v) const {
		print(v ? bool_str.t : bool_str.f);
	}
	void print(char v) const {
		putchar_unlocked(v);
	}
	void print(std::string_view v) const {
		fwrite_unlocked(v.data(), sizeof(std::string_view::value_type), v.size(), stdout);
	}
	void print(double v) const {
		std::printf("%.20f", v);
	}
	void print(long double v) const {
		std::printf("%.20Lf", v);
	}
	template <class T, std::enable_if_t<has_print<T>::value, std::nullptr_t> = nullptr>
	void print(const T& v) const {
		v.print(*this);
	}
	template <class T, std::enable_if_t<!has_print<T>::value, std::nullptr_t> = nullptr>
	void print(const T& v) const {
		std::cout << v;
	}
	template <class T, class U> void print(const std::pair<T, U>& v) const {
		print(v.first);
		print(separator.div);
		print(v.second);
	}
	template <class T> void print(const std::optional<T>& v) const {
		print(*v);
	}
	template <class InputIterater>
	void print_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) print(separator.sep);
			print(*i);
		}
	}
	template <class T> void print(const std::vector<T>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T, std::size_t N> void print(const std::array<T, N>& v) const {
		print_range(v.begin(), v.end());
	}
	template <class T> void print(const std::vector<std::vector<T>>& v) const {
		for (std::size_t i = 0; i < v.size(); ++i) {
			if (i) print(separator.last);
			print(v[i]);
		}
	}

	Printer() = default;
	Printer(const BoolString& _bool_str, const Separator& _separator)
	    : bool_str(_bool_str), separator(_separator) {}
	Printer& operator()() {
		print(separator.last);
		return *this;
	}
	template <class Head> Printer& operator()(Head&& head) {
		print(head);
		print(separator.last);
		return *this;
	}
	template <class Head, class... Tail> Printer& operator()(Head&& head, Tail&&... tail) {
		print(head);
		print(separator.sep);
		return operator()(std::forward<Tail>(tail)...);
	}
	template <class... Args> Printer& flag(bool f, Args&&... args) {
		if (f) {
			return operator()(std::forward<Args>(args)...);
		} else {
			return *this;
		}
	}
	template <class InputIterator>
	Printer& range(const InputIterator& begin, const InputIterator& end) {
		print_range(begin, end);
		print(separator.last);
		return *this;
	}
	template <class Container> Printer& range(const Container& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(std::forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Printer& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Printer& set(const BoolString& _bool_str) {
		bool_str = _bool_str;
		return *this;
	}
	Printer& set(const Separator& _separator) {
		separator = _separator;
		return *this;
	}
	Printer& set(std::string_view t, std::string_view f) {
		bool_str = BoolString(t, f);
		return *this;
	}
} out;
#line 4 "Utility/Ruby.cpp"
#include <map>
#include <algorithm>
#include <numeric>
#line 9 "Utility/Ruby.cpp"

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			std::sort(std::begin(v), std::end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		std::sort(std::begin(v), std::end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			std::sort(std::begin(v), std::end(v),
			          [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			std::sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		std::sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			std::sort(std::begin(v), std::end(v),
			          [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		std::reverse(std::begin(v), std::end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(std::unique(std::begin(v), std::end(v), std::end(v)));
		return v;
	}
	template <class T, class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			v.erase(std::unique(std::begin(v), std::end(v), f), std::end(v));
			return v;
		});
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		std::sort(std::begin(v), std::end(v));
		v.erase(std::unique(std::begin(v), std::end(v)), std::end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(std::size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				std::rotate(std::begin(v), std::begin(v) + left, std::end(v));
			} else {
				std::rotate(std::begin(v), std::end(v) + left, std::end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable(
		    [&](auto v) { return *std::max_element(std::begin(v), std::end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *std::max_element(std::begin(v), std::end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable(
		    [&](auto v) { return *std::min_element(std::begin(v), std::end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *std::min_element(std::begin(v), std::end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return std::max_element(std::begin(v), std::end(v)) - std::begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return std::min_element(std::begin(v), std::end(v)) - std::begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = std::begin(v);
			auto max_val = f(*max_it);
			for (auto it = std::next(std::begin(v)); it != std::end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = std::begin(v);
			auto min_val = f(*min_it);
			for (auto it = std::next(std::begin(v)); it != std::end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*std::begin(v));
			for (auto it = std::next(std::begin(v)); it != std::end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*std::begin(v));
			for (auto it = std::next(std::begin(v)); it != std::end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return std::count(std::begin(v), std::end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return std::count_if(std::begin(v), std::end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> std::optional<int> {
			auto result = std::find(std::begin(v), std::end(v), val);
			return result != std::end(v) ? std::optional(result - std::begin(v))
			                             : std::nullopt;
		});
	}
	template <class V> auto operator()(const V& val, std::size_t i) {
		return Callable([&](auto v) -> std::optional<int> {
			auto result = std::find(std::next(std::begin(v), i), std::end(v), val);
			return result != std::end(v) ? std::optional(result - std::begin(v))
			                             : std::nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> std::optional<int> {
			auto result = std::find_if(std::begin(v), std::end(v), f);
			return result != std::end(v) ? std::optional(result - std::begin(v))
			                             : std::nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> std::optional<typename decltype(v)::value_type> {
			auto result = std::find_if(std::begin(v), std::end(v), f);
			return result != std::end(v) ? std::optional(*result) : std::nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return std::accumulate(std::next(std::begin(v)), std::end(v), f(*std::begin(v)),
			                       [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sum_impl& c) {
		return std::accumulate(std::begin(v), std::end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable(
		    [&](auto v) { return std::find(std::begin(v), std::end(v), val) != std::end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			return std::find_if(std::begin(v), std::end(v), f) != std::end(v);
		});
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(std::remove_if(std::begin(v), std::end(v), f), std::end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct EachConsPair_impl {
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, EachConsPair_impl& c) {
		std::vector<std::pair<value_type, value_type>> result;
		if (std::size(v) >= 2) {
			result.reserve(std::size(v) - 1);
			for (std::size_t i = 0; i < std::size(v) - 1; ++i) {
				result.emplace_back(v[i], v[i + 1]);
			}
		}
		return result;
	}
} EachConsPair;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			std::vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = std::invoke_result_t<F, typename decltype(v)::value_type>;
			std::vector<result_type> result;
			result.reserve(std::size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		std::vector<std::pair<value_type, int>> result;
		result.reserve(std::size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	auto operator()(std::size_t max_val) {
		return Callable([&](auto v) {
			std::vector<std::size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<std::size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		std::map<value_type, std::size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

struct Reduce_impl {
	template <class T, class F> auto operator()(T memo, F f) {
		return Callable([memo, f](auto v) {
			auto acc = memo;
			for (auto i : v) {
				acc = f(acc, i);
			}
			return acc;
		});
	}
} Reduce;

struct Join_impl {
	auto operator()(std::string separater) {
		return Callable([&](auto v) {
			std::string result;
			bool first = true;
			for (const auto& i : v) {
				if (!std::exchange(first, false)) {
					result += separater;
				}
				result += std::to_string(i);
			}
			return result;
		});
	}
	template <class T> friend auto operator|(const T& v, Join_impl& c) {
		return v | c("");
	}
} Join;

struct At_impl {
	auto operator()(std::size_t l, std::size_t r) {
		return Callable(
		    [l, r](auto v) { return decltype(v)(std::begin(v) + l, std::begin(v) + r); });
	}
} At;
struct Slice_impl {
	auto operator()(std::size_t i, std::size_t cnt) {
		return Callable([i, cnt](auto v) {
			return decltype(v)(std::begin(v) + i, std::begin(v) + i + cnt);
		});
	}
} Slice;

struct Transpose_impl {
	template <class T>
	friend auto operator|(const std::vector<std::vector<T>>& v, Transpose_impl& c) {
		std::size_t h = v.size(), w = v.front().size();
		std::vector result(w, std::vector<T>(h));
		for (std::size_t i = 0; i < h; ++i) {
			assert(v[i].size() == w);
			for (std::size_t j = 0; j < w; ++j) {
				result[j][i] = v[i][j];
			}
		}
		return result;
	}
} Transpose;

template <class T> auto operator*(const std::vector<T>& a, std::size_t n) {
	T result;
	for (std::size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(std::string a, std::size_t n) {
	std::string result;
	for (std::size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}

namespace internal {
	template <class T, class U, class = void> struct has_push_back : std::false_type {};
	template <class T, class U>
	struct has_push_back<T, U,
	                     std::void_t<decltype(std::declval<T>().push_back(std::declval<U>()))>>
	    : std::true_type {};
}  // namespace internal
template <
    class Container, class T,
    std::enable_if_t<internal::has_push_back<Container, T>::value, std::nullptr_t> = nullptr>
auto& operator<<(Container& continer, const T& val) {
	continer.push_back(val);
	return continer;
}
template <
    class Container, class T,
    std::enable_if_t<internal::has_push_back<Container, T>::value, std::nullptr_t> = nullptr>
auto operator+(Container continer, const T& val) {
	continer << val;
	return continer;
}
#line 6 "test/IO_2Dvector_and_Ruby_push_back_Transpose_Map_Sum.test.cpp"
using namespace std;

int main() {
	int h = in, w = in;
	vector<vector<int>> a = in[h][w];
	a << (a | Transpose | Map([](const auto& b) { return b | Sum; }));
	for (auto& v : a) {
		v << (v | Sum);
	}
	out(a);
}
Back to top page