Only one test case is passing

please check

U are not erasing i from beginning

https://ide.codingblocks.com/s/308695 please check i am not getting the ans and dont getting the mistake, please correct my code

u should print ans rather than sum

Also, take mod at every step in loop