Board Game
InterviewTime limit1sMemory limit1024 MB
Given a cyclic board where 0 cells roll a six-sided die and other cells jump by their value, find which cells can be visited from cell 1.
Problem
A friend recently gave you a board game as a gift. It is like Tsirkus, but cyclic.
The board has cells numbered , and cell is followed by cell . Each cell has an integer written on it.
- If , the player throws a six-sided die at cell and moves forward by the result.
- If , the player moves forward cells (backward if is negative).
The second rule repeats until the player lands on a cell with written on it. The player may also get stuck in an infinite cycle. The game starts at cell , and .
You suspect that some cells can never be reached. Write a program that finds which cells can be visited during the game.
Input
The first line contains the number of cells (). The second line contains the space-separated integers (, ).
Output
Print a single line with space-separated numbers, each or . The -th number is if cell can be visited, and if it cannot.