#include<iostream>
#include<array>
#include<cmath>
#include<algorithm>
using namespace std;
int cmp(int a,int b)
{
return a > b;
}
int main()
{
int cou;
cin >> cou;
array<int,10000>num;
array<int, 10000>after = {0,};
for (int i = 0; i < cou; i++)
cin >> num[i];
sort(num.begin(),num.begin()+cou,cmp);
int wide = sqrt(cou);
for (; cou%wide != 0; wide--);
int length = cou / wide;
int k = 0;
for (int i = 0; i < wide / 2; i++)//把一圈看作是一次循环,一共wide/2圈
{
for (int j = 0; j < wide - 2*i-1; j++)
after[i*wide + i + j] = num[k++];//上
for(int j=0;j<length-2*i-1;j++)
after[i*wide + wide - i -1+ j*wide] = num[k++];//右
for (int j = 0; j < wide - 2 * i - 1;j++)
after[(length - (i + 1))*wide + wide - i - 1 - j] = num[k++];//下
for (int j = 0; j < length - 2 * i - 1; j++)
after[(length - (i + 1))*wide + i - j*wide] = num[k++];//左
}
if (wide % 2)//如果没处理好,继续处理最后一列
for (int j = 0; j < length - wide + 1; j++)
after[(wide/2)*wide+wide/2+j*wide] = num[k++];
for (int i = 0; i < length; i++)
{
for (int j = 0; j < wide; j++)
{
cout << after[i*wide + j];
if (j != wide - 1)
cout << " ";
}
cout << endl;
}
system("pause");
return 0;
}