#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 14
void f(int p, int *a, int n) {
int i;
if (n == p) {
for (i = 0; i < n; i++)
} else {
int *b;
if ((b
= malloc(sizeof(int) * n
)) != 0) { for (i = 0; i < n; i++)
if (a[i] < 0) {
memcpy(b
, a
, sizeof(int) * n
); b[i] = p;
f(p + 1, b, n);
}
}
}
}
#define N 14
int main(int argc, char *argv[]) {
int *a, n, i;
if (argc != 2) {
usage:
printf("usage: %s <num>\n", argv
[0]); printf("1 < <num> < %d\n", N
+ 1); return 1;
}
if ((n
= atoi(argv
[1])) <= 1 || n
> N
) goto usage;
if ((a
= malloc(sizeof(int) * n
)) != 0) { for (i = 0; i < N; i++)
a[i] = -1;
f(0, a, n);
}
return 0;
}
/* end */
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBOIDE0CnZvaWQgZihpbnQgcCwgaW50ICphLCBpbnQgbikgewogIGludCBpOwogIGlmIChuID09IHApIHsKICAgIGZvciAoaSA9IDA7IGkgPCBuOyBpKyspCiAgICAgIHByaW50ZigiJWMsICIsIGFbaV0gKyAnYScpOwogICAgcHV0Y2hhcignXG4nKTsKICB9IGVsc2UgewogICAgaW50ICpiOwogICAgaWYgKChiID0gbWFsbG9jKHNpemVvZihpbnQpICogbikpICE9IDApIHsKICAgICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykKICAgICAgICBpZiAoYVtpXSA8IDApIHsKICAgICAgICAgIG1lbWNweShiLCBhLCBzaXplb2YoaW50KSAqIG4pOwogICAgICAgICAgYltpXSA9IHA7CiAgICAgICAgICBmKHAgKyAxLCBiLCBuKTsKICAgICAgICB9CiAgICAgIGZyZWUoYik7CiAgICB9CiAgfQp9CgojZGVmaW5lIE4gMTQKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkgewogIGludCAqYSwgbiwgaTsKICBpZiAoYXJnYyAhPSAyKSB7CiAgdXNhZ2U6CiAgICBwcmludGYoInVzYWdlOiAlcyA8bnVtPlxuIiwgYXJndlswXSk7CiAgICBwcmludGYoIjEgPCA8bnVtPiA8ICVkXG4iLCBOICsgMSk7CiAgICByZXR1cm4gMTsKICB9CiAgCiAgaWYgKChuID0gYXRvaShhcmd2WzFdKSkgPD0gMSB8fCBuID4gTikKICAgIGdvdG8gdXNhZ2U7CiAgaWYgKChhID0gbWFsbG9jKHNpemVvZihpbnQpICogbikpICE9IDApIHsKICAgIGZvciAoaSA9IDA7IGkgPCBOOyBpKyspCiAgICAgIGFbaV0gPSAtMTsKICAgIGYoMCwgYSwgbik7CiAgICBmcmVlKGEpOwogIH0KICByZXR1cm4gMDsKfQovKiBlbmQgKi8K