An airport shuttle route is modeled as a singly linked list of stop codes, front to back. Instead of ending, the LAST stop's next-hop may point back to an EARLIER stop, forming a loop. You are given the stop codes and, separately, the 0-indexed position that the last stop's next-hop points to (or -1 if the route simply ends with no loop). Print the number of stops that belong to the loop (0 if there is no loop).
Input format
Line 1: an integer n — the number of stops.
Line 2: n space-separated integers — the stop codes, front to back.
Line 3: an integer pos — the 0-indexed stop that the last stop's next-hop points to, or -1 if there is no loop.
Output format
A single integer: the number of stops in the loop (0 if there is no loop).
Constraints
- 1 ≤ n ≤ 100000
- -1 ≤ pos ≤ n-1
- -1000000000 ≤ stop code ≤ 1000000000