I have failed to submit div. 2 B problem in round #92 with the "Time limit exceeded" verdict. Later I have modified my solution and now it does pass the test, but the interesting part of it is that the complexity of both is equivalent (please correct me if I am wrong). This is the first time I encounter such a problem. Usually if you got the solution with the right complexity it does pass the test. For those who are interested in looking at the code it is here: http://pastebin.com/scSwyuEq. The fast function is f, the slow one is f1 (if you want to run the slow one, then just swap the names).