Train and Peter

CodeForces - 8A