sort through input sequence