#include <iostream>
#include <set>
using namespace std;
int n, a[10], perm[10], used[10], d = 1;
set<string> seen;
void pr() {
string state = "";
for (int i = 0; i < n; i++) {
state += to_string(perm[i]) + " ";
}
if (seen.find(state) == seen.end()) {
cout << d << ": " << state << endl;
seen.insert(state);
d++;
}
}
void permutation(int i) {
for (int j = 0; j < n; j++) {
if (!used[j]) {
perm[i] = a[j];
used[j] = 1;
if (i == n - 1)
pr();
else
permutation(i + 1);
used[j] = 0;
}
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
permutation(0);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIGFbMTBdLCBwZXJtWzEwXSwgdXNlZFsxMF0sIGQgPSAxOwpzZXQ8c3RyaW5nPiBzZWVuOwoKdm9pZCBwcigpIHsKICAgIHN0cmluZyBzdGF0ZSA9ICIiOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBzdGF0ZSArPSB0b19zdHJpbmcocGVybVtpXSkgKyAiICI7CiAgICB9CgogICAgaWYgKHNlZW4uZmluZChzdGF0ZSkgPT0gc2Vlbi5lbmQoKSkgewogICAgICAgIGNvdXQgPDwgZCA8PCAiOiAiIDw8IHN0YXRlIDw8IGVuZGw7CiAgICAgICAgc2Vlbi5pbnNlcnQoc3RhdGUpOwogICAgICAgIGQrKzsKICAgIH0KfQoKdm9pZCBwZXJtdXRhdGlvbihpbnQgaSkgewogICAgZm9yIChpbnQgaiA9IDA7IGogPCBuOyBqKyspIHsKICAgICAgICBpZiAoIXVzZWRbal0pIHsKICAgICAgICAgICAgcGVybVtpXSA9IGFbal07CiAgICAgICAgICAgIHVzZWRbal0gPSAxOwogICAgICAgICAgICBpZiAoaSA9PSBuIC0gMSkKICAgICAgICAgICAgICAgIHByKCk7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIHBlcm11dGF0aW9uKGkgKyAxKTsKICAgICAgICAgICAgdXNlZFtqXSA9IDA7CiAgICAgICAgfQogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsgCiAgICB9CiAgICBwZXJtdXRhdGlvbigwKTsKfQo=