Wyliczanka
InterviewTime limit6sMemory limit1024 MB
Given N children in a circle and step counts X1 to XN, the task is to output the order in which children leave, each round removing the child reached by the Xi-th tap.
- Level
Medium5 of 10
- Topics
- Array, Simulation, Segment tree
- Solved
- No attempts yet
Statement
Children from Bajtogród invented a new game called Wyliczanka.
N children numbered 1, 2, ..., N take part, and each child receives a different number. The children then stand in a circle so that child i sees the back of child i+1, and child N sees the back of child 1.
The game starts with child 1 saying an integer X1. Child 1 taps the back of the child standing in front of them. The tapped child taps the back of the next child, and so on, until the X1-th tap happens. The child tapped last leaves the circle. The child who would have been tapped next says the next number X2. The game ends when only one child remains in the circle.
For a given N and the successive values Xi, determine which child drops out in each round.
Input
The first line contains a natural number N (). The second line contains N natural numbers ().
Output
Print N natural numbers, the numbers of the children in the order they leave the circle.