Yesterday during contest While solving Problem B of Educational Codeforces Round 191, I encountered something that completely confused me. A cout statement that had nothing to do with the construction logic seemed to change the output of my program. Removing it produced one answer, and adding it produced another. Naturally, I wondered how can a print statement affect the output of a loop.
this was all done in codechef online compiler, like vs code was behaving fine in this but nor codechef complier and cf compiler
It was quite strange to me you can go to my profile and see my code of the yesterday contest first i submitted this code My logic was simple: I found a valid construction for 2 numbers, and a valid construction for 3 numbers was already given in the statement. Since any n can be represented using combinations of 2 and 3, I built my solution around that idea.
This code looked completely correct to me, but I got a Wrong Answer on test case 1 For the second sample, where n=4, it seemed as if the count of 1 suddenly became 5 instead of 4, which was very surprising.
I started debugging, and after commenting out a few lines, I noticed that the code was actually producing the correct output. then i again made a submission
so again the response was same LIKE LITERALLY IF YOU RUN THIS CODE WITH t=1 and n=2 AND WHEN YOU WOULD COMMENT THE STATEMENT // cout<<ans[4]<<endl; output would be different and then if you uncomment this then the correct output would get displayed..
after all this i decided to just change the way of printing the things in my code 377959599
and then it got accepted
doing all this wasted my 20 minutes in my contest :(




