What's the error in my approach (ACM14AM5)

problem- ACM14AM5 Problem - CodeChef
code- CodeChef: Practical coding for everyone