Stuck on Modular Equation

My approach was similar to the one given in the video editorial. I am unable to understand where the code is failing. Please help.

Problem: CodeChef: Practical coding for everyone
My solution: CodeChef: Practical coding for everyone

Try this test case your code gives 45

Thank You for your help @cubefreak777