#include <iostream> #include <fstream> #include <deque> #include <algorithm> using namespace std; ifstream f("Input"); ofstream g("Output"); deque <int> v; int main() { int n,x,i,j; f>>n; for(i = 1; i <= n*n ;i++) f>> x,v.push_back(x); sort(v.begin(),v.begin()+(n*n)); for(i = 1; i <= n ;i++) { for(j = 1; j <= n ; j++ ) { if(i == j) g<<v.back()<<" ",v.pop_back(); else g<<v.front()<<" ",v.pop_front(); } g<<"\n"; } return 0; }