#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, v[8];
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
}
do {
for (int i = 1; i <= n; ++i) {
cout << v[i] << " ";
}
cout << "\n";
} while (next_permutation (v + 1, v + 1 + n));
return 0;
}