Where am i making mistake

code:https://ide.codingblocks.com/s/219346

@spagire4 If there is no solution, print -1.

@aa1 did as:
if(ans==0)
cout<<-1<<endl;
else
cout<<ans<<endl;
but still giving wrong ans

@spagire4 refer to this


this ll pass all the test cases.please mark your doubt as resolved if u are satisfied