//next_permutation函数,生成下一个全排列
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 20;
int a[N];
int main()
{
int n;
cin>>n;
for (int i = 1; i <= n; i ++ )
{
cin>>a[i];
}
do
{
for (int i = 1; i <= n; i ++ )
cout<<a[i]<<' ';
cout<<endl;
}while(next_permutation(a+1,a+n));
}