In the future and/or for this post, can you add code formatting and/or/and the problem link?
Your code will fail when sum \in [121, 124] because of integer division screwing you over. Make the condition sum * p <= 120 instead of sum * p / 5 <= 24.