https://www.codechef.com/viewsolution/33626108
It is not written anywhere that the direction in which you are going,is same as direction of train.
Thank You…