CodeChef Problem solution