CSES - Aalto Competitive Programming 2024 - wk6 - Wed - Ladders
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Uolevi has bough a new board game: Ladders. The board has nn squares numbered 1,2,,n1,2,\dots,n. Number aia_i is written on square ii. Each of the numbers 1,2,,n1,2,\dots,n occurs exactly once in aa. For each pair of squares (i,j)(i, j), there is a ladder starting from ii and ending in jj if aja_j is a multiple of aia_i.

When playing the game, a player can either move up one square or use one of the ladders that starts from the current square. All players start from square 11 and their goal is to reach square nn. Uolevi wants to calculate the minimum number of moves needed to finish the game so that he can beat Maija every time they play.

Input

The first line contain a single integers nn. The second line contains nn integers a1,a2,,ana_1,\,a_2,\dots,\,a_n.

Output

Print the minimum number of moves required to finish the game.

Constraints

  • 1n1051 \leq n \leq 10^5
  • 1ain1 \leq a_i \leq n
  • aiaja_i \neq a_j if iji \neq j

Example 1

Input:

10
8 10 3 6 5 1 4 7 2 9

Output:

3

Explanation:
The indices of the visited squares are:
12310.1 \rightarrow 2 \rightarrow 3 \rightarrow 10.
We can do the last move since a10=3×a3.a_{10} = 3 \times a_3.

Example 2

Input:

10
6 7 10 9 2 1 3 8 4 5

Output:

6

Example 3

Input:

1
1

Output:

0