eolymp
bolt
Try our new interface for solving problems

Monad

\textit{Monad} - the simplest mathematical object, which you can think of. Suppose there is a finite set \textbf{M}. And let there be a map of a finite set into itself. Each point of the finite set of maps to another point in this set. This is a monad. Consider the monad \textbf{f}: \textbf{X} → \textbf{X}, где \textbf{X = \{1, ..., n\}}. We introduce the notation: \textbf{f_k(x) = f(f(...f(x)...))} (\textbf{k} раз). Your task - for a given \textbf{x} and \textbf{k} define \textbf{f_k(x)}. \InputFile The first line contains the number \textbf{n} - the power of \textbf{X} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}). The second line lists the space of integers \textbf{n}, \textbf{i}-th number is equal to \textbf{f(i)} (\textbf{1} ≤ \textbf{f(i)} ≤ \textbf{n}). The third line contains the \textbf{x} (\textbf{1} ≤ \textbf{x} ≤ \textbf{n}) and \textbf{k} (\textbf{1} ≤ \textbf{k} ≤ \textbf{10^100000}). \OutputFile In a single line output \textbf{f_k(x)}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
5
1 2 3 4 5
2 3
Output example #1
2