#include #define ll long long #define pi (acos(-1)) #define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i) using namespace std; std::vector genprimevec(const unsigned ll N); int main() { int h, w; cin >> h >> w; vector v(h * w); rep(i, h * w) { cin >> v[i]; } sort(v.begin(), v.end()); rep(i, h) { rep(j, w) { cout << v[(i * w) + j] << ' '; } cout << endl; } return 0; } /*author https://qiita.com/drken/items/0c88a37eec520f82b788*/ ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } std::vector genprimevec(const unsigned ll N) { std::vector is_prime(N + 1); for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; } std::vector P; for (unsigned ll i = 2; i <= N; i++) { if (is_prime[i]) { for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); } } return P; }