Help needed in this problem

Problem:- Practice Problem

My sub:- Hackerearth problem -The Chocolate Boy - Pastebin.com