Under construction

Still being built. Things may change

Board Game

Interview

Time limit1sMemory limit1024 MB

Summary
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.
Level

Easy3 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

A friend recently gave you a board game as a gift. It is like Tsirkus, but cyclic.

The board has NN cells numbered 1,…,N1, \ldots, N, and cell NN is followed by cell 11. Each cell ii has an integer aia_i written on it.

  • If ai=0a_i = 0, the player throws a six-sided die at cell ii and moves forward by the result.
  • If ai≠0a_i \ne 0, the player moves forward aia_i cells (backward if aia_i is negative).

The second rule repeats until the player lands on a cell with 00 written on it. The player may also get stuck in an infinite cycle. The game starts at cell 11, and a1=0a_1 = 0.

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 NN (1≤N≤10001 \le N \le 1000). The second line contains the space-separated integers a1,…,aNa_1, \ldots, a_N (−N<ai<N-N < a_i < N, a1=0a_1 = 0).

Output

Print a single line with NN space-separated numbers, each 00 or 11. The ii-th number is 11 if cell ii can be visited, and 00 if it cannot.

Examples2

  1. Example 1

    Input
    10
    0 8 2 2 2 4 -6 0 -1 0
    
    Expected output
    1 1 1 1 1 1 1 0 0 1
    
  2. Example 2

    Input
    11
    0 6 5 4 3 2 1 -1 0 0 0
    
    Expected output
    1 1 1 1 1 1 1 1 0 0 0