#include using namespace std; using ll=long long; #define rep2(i, a, n) for(int i = (a); i < (n); i++) #define rep(i, n) rep2(i,0,n) int main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); int h,n,w,a;cin>>h>>w; map map; rep(i,h)rep(i,w){ cin>>a;map[a]++; } int cnt=0; for(auto itr=map.begin();itr!=map.end();++itr){ rep(i,itr->second){ cnt!=w-1?cout<first<<" ":cout<first<<"\n"; cnt++; if(cnt==w)cnt=0; } } }