Square Brackets--where am i going wrong?

Link–https://ide.codingblocks.com/s/164542
why is my code giving wa .I unlocked the test cases and saw that it is generating 0 for some cases,it is getting overflowed i think or there is some issue.Pls reply asap.I am stuck on it.

Take mod like this.
ans = (ans%mod + x%mod)%mod to avoid overflow.

still giving WA.Link—https://ide.codingblocks.com/s/164761

Code is alright. I am also getting WA for this question. Maybe string multiplication has to be used. You can skip the question from here and move onto other.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.