The input contains nine integers, and the range of each integer is 1 to 9, for example, 4 3 5 9 8 7 3 6 2. Now, start from the first place, we get the number 4. It indicates that the next number we need to pick is at the 4th place, which is 9. Likewise, we then go to the 9th place and get the number 2. We repeat this process until we go to a place that has already been visited N-1 times. In this example, if N = 2, we will stop at the 7th place and get the number 3. Therefore, along the way we pick nine numbers, 4 9 2 3 5 8 6 7 3, and the output is the sum of these numbers, which is 47.
Note that we always start from the first place.
Other examples: Consider the input 1 9 8 7 6 5 4 3 2, if N = 4, the output should be 3 since we will visit the first place 3 times and then stop. Consider the input 9 2 3 4 5 6 7 8 1, if N = 3, the output should be 20.
N
A sequence of nine integers of 1 to 9.
Note that the nine integers have NO need to be different.
The sum of the integers being visited.
Remember to print a '
' at the end of the sum.