#include using namespace std; int main() { int H, W; cin >> H >> W; vector vt(H * W); for (int i = 0; i < H * W; ++i) { cin >> vt[i]; } sort(vt.begin(), vt.end()); int cur = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cout << vt[cur]; if (j != W - 1) cout << " "; cur++; } cout << endl; } return 0; }