Code delivering the wrong result at higher inputs

I am an aspiring coder. I have been trying to solve this question on codechef. What do you reckon is the problem here? A link to the question: CodeChef | Competitive Programming | Participate & Learn industlab My code fail when the input is 990, which, in the question refers to the value of n. The value of ‘n’ refers to the length of the string. My code for the question has been provided below.