#define _USE_MATH_DEFIMES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int MOD = 1'000'000'007; const int MOD2 = 998'244'353; const int INF = 1'000'000'000; //1e9 const int NIL = -1; const long long LINF = 1'000'000'000'000'000'000; // 1e18 const long double EPS = 1E-10L; template inline bool chmax(T &a, const S &b){ if(a < b){a = b; return true;} return false; } template inline bool chmin(T &a, const S &b){ if(b < a){a = b; return true;} return false; } template inline bool exist(Container &s, const T &e){ return (s.find(e) != std::end(s)); } template inline bool inside(T x, T lx, T rx){ return (std::clamp(x, lx, rx) == x); } template inline bool inside(T x, T y, T lx, T rx, T ly, T ry){ return inside(x, lx, rx) && inside(y, ly, ry); } int main(){ int H, W; std::cin >> H >> W; std::vector A(H * W); for(auto &e: A) std::cin >> e; std::sort(std::begin(A), std::end(A)); for(int i{0}; i < H; ++i){ for(int j{0}; j < W; ++j){ if(j) std::cout << " "; std::cout << A[W*i + j]; } std::cout << "\n"; } return 0; }