#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::vector<int>> vvi = {{1, 5, 3, 4}, {0, 4, 1, 0}, {7, 2, 3, 1}};
int mx, my;
mx = vvi[0].size();
my = vvi.size();
std::cout << "X方向のサイズ = " << mx << ", Y方向のサイズ = " << my << std::endl;
std::vector<int> wrk;
for (std::vector<int>& v : vvi)
std::copy(std::begin(v), std::end(v), std::back_inserter(wrk));
std::for_each(std::begin(wrk), std::end(wrk), [](int i){ std::cout << i << ' '; });
std::cout << std::endl;
std::sort(std::begin(wrk), std::end(wrk));
std::for_each(std::begin(wrk), std::end(wrk), [](int i){ std::cout << i << ' '; });
std::cout << std::endl;
for (int i = 0; i < my; i++) {
for (int j = 0; j < mx; j++) {
vvi[i][j] = wrk[i * mx + j];
std::cout << vvi[i][j] << ' ';
}
std::cout << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKaW50IG1haW4oKQp7CiAgc3RkOjp2ZWN0b3I8c3RkOjp2ZWN0b3I8aW50Pj4gdnZpID0ge3sxLCA1LCAzLCA0fSwgezAsIDQsIDEsIDB9LCB7NywgMiwgMywgMX19OwogIGludCBteCwgbXk7CgogIG14ID0gdnZpWzBdLnNpemUoKTsKICBteSA9IHZ2aS5zaXplKCk7CiAgc3RkOjpjb3V0IDw8ICJY5pa55ZCR44Gu44K144Kk44K6ID0gIiA8PCBteCA8PCAiLCBZ5pa55ZCR44Gu44K144Kk44K6ID0gIiA8PCBteSA8PCBzdGQ6OmVuZGw7CgogIHN0ZDo6dmVjdG9yPGludD4gd3JrOwoKICBmb3IgKHN0ZDo6dmVjdG9yPGludD4mIHYgOiB2dmkpCiAgICBzdGQ6OmNvcHkoc3RkOjpiZWdpbih2KSwgc3RkOjplbmQodiksIHN0ZDo6YmFja19pbnNlcnRlcih3cmspKTsKCiAgc3RkOjpmb3JfZWFjaChzdGQ6OmJlZ2luKH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