static int tNQHelper(boolean[][]u, int i) {
        int n=u[0].length;
        if (i==n)
            return 1;
        int sum=0;
        for (int j=0;j<n;++j) {
            if (u[0][j]||u[1][i+j]||u[2][n-i-1+j])
                continue;
            u[0][j]=u[1][i+j]=u[2][n-i-1+j]=true;
            sum+=tNQHelper(u,i+1);
            u[0][j]=u[1][i+j]=u[2][n-i-1+j]=false;
        }
        return sum;
    }