import java.util.Arrays;
class NQueens {
static int N, count;
static int[] column;
public static void main
(String[] args
) { N = 14;
column = new int[N];
nQueens(0);
}
private static void nQueens(int row) {
if (row == N) {
// System.out.println(Arrays.toString(column));
count++;
return;
}
for (int col = 0; col < N; col++) {
if (place(row, col)) {
column[row] = col;
nQueens(row + 1);
}
}
}
private static boolean place(int row, int col) {
for (int i = 0; i < row; i++) {
if (column
[i
] == col
|| Math.
abs(column
[i
] - col
) == Math.
abs(i
- row
)) { return false;
}
}
return true;
}
}
aW1wb3J0IGphdmEudXRpbC5BcnJheXM7CgpjbGFzcyBOUXVlZW5zIHsKICAgIHN0YXRpYyBpbnQgTiwgY291bnQ7CiAgICBzdGF0aWMgaW50W10gY29sdW1uOwogICAgCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgewogICAgICAgIE4gPSAxNDsKICAgICAgICBjb2x1bW4gPSBuZXcgaW50W05dOwogICAgICAgIG5RdWVlbnMoMCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKGNvdW50KTsKICAgIH0KICAgICAgICAKICAgIHByaXZhdGUgc3RhdGljIHZvaWQgblF1ZWVucyhpbnQgcm93KSB7CiAgICAgICAgaWYgKHJvdyA9PSBOKSB7CiAgICAgICAgICAgIC8vIFN5c3RlbS5vdXQucHJpbnRsbihBcnJheXMudG9TdHJpbmcoY29sdW1uKSk7CiAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgY29sID0gMDsgY29sIDwgTjsgY29sKyspIHsKICAgICAgICAgICAgaWYgKHBsYWNlKHJvdywgY29sKSkgewogICAgICAgICAgICAgICAgY29sdW1uW3Jvd10gPSBjb2w7CiAgICAgICAgICAgICAgICBuUXVlZW5zKHJvdyArIDEpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgICAgIAogICAgcHJpdmF0ZSBzdGF0aWMgYm9vbGVhbiBwbGFjZShpbnQgcm93LCBpbnQgY29sKSB7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCByb3c7IGkrKykgewogICAgICAgICAgICBpZiAoY29sdW1uW2ldID09IGNvbCB8fCBNYXRoLmFicyhjb2x1bW5baV0gLSBjb2wpID09IE1hdGguYWJzKGkgLSByb3cpKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9Cn0=