#include<bits/stdc++.h>
using namespace std;
void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void perum(int list[],int k,int m)
{
if(k==m) //到最底层了
{
for(int i=0;i<=m;i++)
{
cout<<list[i]<<" ";
}
cout<<endl;
}
else
{
for(int i=k;i<=m;i++)
{
swap(list[i],list[k]);
perum(list,k+1,m);
swap(list[i],list[k]);
}
}
}
int main()
{
int n;
cin>>n;
const int p=n;
int tot[p];
for(int i=0;i<n;i++)
{
cin>>tot[i];
}
sort(tot,tot+n);
perum(tot,0,n-1);
return 0;
}