#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; #define MEM(a,b) memset((a),(b),sizeof(a)) const LL INF = 1e9 + 7; const int N = 5e5 + 10; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n, m; scanf("%d%d", &n, &m); vector v(n * m); for (auto& x : v) scanf("%d", &x); sort(v.begin(), v.end()); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { printf("%d%c", v[i * m + j], " \n"[j + 1 == m]); } } return 0; }