cho.sh
Notes
Loading...

Popping Balloons

Time limit

2s

Memory limit

4 MB

Problem

There are N balloons numbered from 1 to N arranged in a circle. For each balloon i, the balloon to its right is i + 1 and the balloon to its left is i - 1. Balloon 1 is to the right of balloon N, and balloon N is to the left of balloon 1.

Each balloon contains one paper with a nonzero integer written on it. The balloons are popped by the following rules.

First, pop balloon 1. Then read the number from the popped balloon and move that many positions among the balloons that have not yet been popped. If the number is positive, move to the right. If the number is negative, move to the left. Popped balloons are skipped while moving.

Repeat this process until every balloon has been popped.

Input

The first line contains a natural number N (1 <= N <= 1,000).

The second line contains N integers in order, where the i-th integer is written on the paper inside balloon i. Each integer is between -N and N inclusive, and none of them is 0.

Output

Print the numbers of the balloons in the order they are popped, separated by spaces on one line.