Not passing all the test cases

Your code is not producing correct output for following test case :
Input :
5
39
45
40
42
43
Your output : 1 2 1 4 5 END
Expected output : 1 2 1 2 3 END

Try to change the approach you are following up in your code…