Question 1172098
.


The logic is correct.


My congratulations (!) --- you got really good solution.



--------------


            At which high school / college / university did you get this problem ?