private boolean safe(boolean[][]board, int i, int j) {
        int d45x = j + i, d135x = j - i;
        for (int k = 0; k < board.length; k ++) {
            if (board[i][k]) return false;
            if (board[k][j]) return false;
            if (d45x - k >= 0 && d45x - k < board.length && board[k][d45x - k]) return false;
            if (d135x + k >= 0 && d135x + k < board.length && board[k][d135x + k]) return false;
        }
        return true;
    }