algorithm working input -> ouput