Solved CodeChef November Chalenge problem #3