solve the candy problem.