Candies.cpp solution