Solves Candies problem