#include <iostream>
int stack[100], level, n;
void init() {
stack[level] = -1;
}
void print() {
for(int i = 1; i <= n; ++i) {
if(stack[i] == 1) {
printf("%d ", i);
}
}
printf("\n");
}
int succ() {
if(stack[level]<1){
stack[level]++;
return 1;
}
return 0;
}
int valid() {
return 1;
}
int sol() {
return level == n;
}
void bk() {
int s,v;
level = 1;
init();
while(level>0) {
s = 1;
v = 0;
while(s && !v) {
s = succ();
if(s) v = valid();
}
if(s){
if( sol() ) print();
else {
level++;
init();
}
} else {
level--;
}
}
}
int main(int argc, char const *argv[]) {
n = 3;
bk();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgc3RhY2tbMTAwXSwgbGV2ZWwsIG47Cgp2b2lkIGluaXQoKSB7CiAgc3RhY2tbbGV2ZWxdID0gLTE7Cn0KCnZvaWQgcHJpbnQoKSB7CgogIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CgogICAgaWYoc3RhY2tbaV0gPT0gMSkgewoKICAgICAgcHJpbnRmKCIlZCAiLCBpKTsKICAgIH0KICB9CiAgcHJpbnRmKCJcbiIpOwp9CgppbnQgc3VjYygpIHsKICBpZihzdGFja1tsZXZlbF08MSl7CiAgICBzdGFja1tsZXZlbF0rKzsKICAgIHJldHVybiAxOwogIH0KICByZXR1cm4gMDsKfQoKaW50IHZhbGlkKCkgewogIHJldHVybiAxOwp9CgppbnQgc29sKCkgewogIHJldHVybiBsZXZlbCA9PSBuOwp9Cgp2b2lkIGJrKCkgewppbnQgcyx2OwpsZXZlbCA9IDE7CmluaXQoKTsKCiB3aGlsZShsZXZlbD4wKSB7CiAgICAgIHMgPSAxOwogICAgICB2ID0gMDsKICAgICAgd2hpbGUocyAmJiAhdikgewogICAgICAgICBzID0gc3VjYygpOwogICAgICAgICBpZihzKSB2ID0gdmFsaWQoKTsKICAgICAgfQogICAgICBpZihzKXsKICAgICAgICBpZiggc29sKCkgKSBwcmludCgpOwogICAgICAgIGVsc2UgewogICAgICAgICAgbGV2ZWwrKzsKICAgICAgICAgIGluaXQoKTsKICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgbGV2ZWwtLTsKICAgICAgfQogIH0KCn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pIHsKCiAgbiA9IDM7CiAgYmsoKTsKCiAgcmV0dXJuIDA7Cn0=