Why isn't it working

sol: https://ide.codingblocks.com/s/382841
prob: https://hack.codingblocks.com/app/contests/1975/413/problem

I want to solve this in brute force way

see this: