시간 제한 | 메모리 제한 | 제출 | 정답 | 맞은 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 0 | 0 | 0 | 0.000% |
Yuuka has a deck of $n$ cards labeled with $0, 1, 2, \dots, (n - 1)$.
Initially, the cards are placed in the order $p_1, p_2, \dots, p_n$ from top to bottom. In each round, if the top card is labeled with $x$, Yuuka will place it $x$ cards downward, so it becomes the card number $(x + 1)$ in the deck, counting from $1$. The relative order of other cards will not be changed.
How many rounds will pass until the card labeled with $0$ comes to the top?
The first line contains an integer $n$ ($1 \leq n \leq 32$).
The second line contains $n$ distinct integers $p_1, p_2, \dots, p_n$ ($0 \leq p_i < n$).
Output an integer which denotes the number of rounds. If the card labeled with $0$ never comes to the top, output "-1
" instead.
5 1 3 2 4 0
13
2 0 1
0