Byte Trains

Talb has managed to gather enough ijo to pass the selection stage and is on his way to Sacred Ino. However, as he found out, getting there is a whole lot harder than he imagined. He has to pass a series of tasks in order to even dare to get close, and the Big Jarab won't let him rest.

His first task is to be the gatekeeper of the city where the Sacred Ino is kept. Being the gatekeeper, he can't take any breaks, as even the shortest distraction could result in competitor infiltration. This might mean that he would be replaced and lose the chance to get to the Sacred Ino.

We know that an array of locomotives and cars that enter the city is a competitor array if there exists a locomotive that is not followed by exactly the required number of cars. To be more precise, an array of locomotives and cars is given as a sequence of bytes, where each byte represents:

  • a locomotive, if the first bit is 1
  • a car, otherwise

The number of trailing 0 bits in a locomotive byte denotes the number of cars that must follow the respective locomotive. For example, 10101000 is a locomotive which must be followed by exactly 3 cars, and 10101001 must have no cars attached.

Any sequence which is not a competitor is considered friendly. Given a sequence of bits, decide whether it is a friendly sequence, in which case you should print Yes, or not, in which case the output should be No.


A sequence of at most 1000 bytes, where each byte is given as 8 characters that are either 0 or 1, with no spaces between bytes.


The word Yes if the sequence is friendly. The word No if the sequence is a competitor sequence.


  • The sequence contains at most 1000 bytes.
  • It is guaranteed that the sequence starts with a locomotive.


1011011001110010YesThere is one locomotive and one car.
1011011011110010NoThe first locomotive indicates that it should be followed by exactly one car, but instead it's actually followed by another locomotive.

Sponsors Gold