#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int n;
int solution_count = 0;
uint32_t col=0, asc=0, desc=0;
void backtrack(int i)
{
if(i == n) {
solution_count++;
return;
}
uint32_t mc, md, ma;
for(int j=0; j != n; j++) {
if (col & (mc = 1<<j)) continue;
if (desc & (md = 1 << (i+j))) continue;
if (asc & (ma = 1 << (15+i-j))) continue;
uint32_t oldc = col, oldd = desc, olda = asc;
col |= mc;
desc |= md;
asc |= ma;
backtrack(i+1);
col = oldc;
desc = oldd;
asc = olda;
}
}
int main()
{
n = 14;
backtrack(0);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0ZGludC5oPgoKaW50IG47CmludCBzb2x1dGlvbl9jb3VudCA9IDA7CnVpbnQzMl90IGNvbD0wLCBhc2M9MCwgZGVzYz0wOwoKdm9pZCBiYWNrdHJhY2soaW50IGkpIAp7CiAgICBpZihpID09IG4pIHsKICAgICAgICBzb2x1dGlvbl9jb3VudCsrOwogICAgICAgIHJldHVybjsKICAgIH0KICAgIHVpbnQzMl90IG1jLCBtZCwgbWE7CiAgICBmb3IoaW50IGo9MDsgaiAhPSBuOyBqKyspIHsKICAgIAlpZiAoY29sICYgKG1jID0gMTw8aikpIGNvbnRpbnVlOwogICAgCWlmIChkZXNjICYgKG1kID0gMSA8PCAoaStqKSkpIGNvbnRpbnVlOwogICAgCWlmIChhc2MgJiAobWEgPSAxIDw8ICgxNStpLWopKSkgY29udGludWU7CiAgICAJdWludDMyX3Qgb2xkYyA9IGNvbCwgb2xkZCA9IGRlc2MsIG9sZGEgPSBhc2M7CiAgICAgICAgY29sIHw9IG1jOwogICAgICAgIGRlc2MgfD0gbWQ7CiAgICAgICAgYXNjIHw9IG1hOwogICAgICAgIGJhY2t0cmFjayhpKzEpOwogICAgICAgIGNvbCA9IG9sZGM7CiAgICAgICAgZGVzYyA9IG9sZGQ7CiAgICAgICAgYXNjID0gb2xkYTsKICAgIH0KfQoKaW50IG1haW4oKSAKeyAKICAgIG4gPSAxNDsgCiAgICBiYWNrdHJhY2soMCk7CiAgICBwcmludGYoIiVkIiwgc29sdXRpb25fY291bnQpOwogICAgcmV0dXJuIDA7Cn0=