ZCO Wormhole

Hello, I have been trying to solve https://www.codechef.com/ZCOPRAC/problems/ZCO12002

This is my current code. http://pastebin.com/aF2KGHqy

It fails on test case 14 only with Wrong Answer

It was a very stupid mistake. I forgot that one could begin competition at the very moment the person arrived using a wormhole. Correct code - http://pastebin.com/J7rVHJAh