#include #define rep(i, ss, ee) for (int i = ss; i < ee; ++i) using namespace std; void solve() { int H, W; cin >> H >> W; vector v(H * W); rep(i, 0, H * W) { cin >> v[i]; } sort(v.begin(), v.end()); int i = 0; for (auto e : v) { cout << ((i == 0) ? "" : " ") << e; if (i == W - 1) { cout << endl; i = 0; } else { i++; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); getchar(); }