#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 10010;
int N, m, n;
int a[maxn];
int used[110][110], mat[110][110];
bool cmp(int x, int y){
return x > y;
}
int legal(int x, int y){
return x >= 0 && x < m &&
y >= 0 && y < n &&
used[x][y] == 0;
}
int main(){
scanf("%d", &N);
for(int i = 0; i < N; i++){
scanf("%d", &a[i]);
}
sort(a, a + N, cmp);
m = ceil(sqrt(1.0 * N));
while(N % m != 0) m++;
n = N / m;
memset(used, 0, sizeof(used));
int i = 0, j = 0, p = 0;
while(p < N){
while(legal(i, j)){
used[i][j] = 1;
mat[i][j++] = a[p++];
}j--; i++;
while(legal(i, j)){
used[i][j] = 1;
mat[i++][j] = a[p++];
}i--; j--;
while(legal(i, j)){
used[i][j] = 1;
mat[i][j--] = a[p++];
}j++; i--;
while(legal(i, j)){
used[i][j] = 1;
mat[i--][j] = a[p++];
}i++; j++;
}
for(int i = 0; i < m; i++){
printf("%d", mat[i][0]);
for(int j = 1; j < n; j++){
printf(" %d", mat[i][j]);
}putchar('\n');
}
return 0;
}