The trilero of la Rambla

0.65

One day, walking down la Rambla of Barcelona, you notice a crowd around a board table. You get closer and you see that a “trilero” (someone who makes a living by cheating people) is playing a game with a tourist.

The game is as follows. On the table there are nn identical plastic caps. First, the trilero hides a ball under one of the caps, initially known to the player. Then the trilero starts moving the caps very fast. At the end, the player must guess under which cap the ball is.

0.35

The game is over and, obviously, the tourist has lost it (and some money). But you realize that the trilero just repeats kk times the same permutation of caps σ\sigma. This is why he can be so fast! Please write a program that, given σ\sigma, kk and the initial position xx of the ball, tells the final position of the ball.

Input

Input consists of several cases. Every case begins with nn, followed by a permutation of the numbers between 1 and nn, followed by kk and xx. Assume 1n1051 \le n \le 10^5, 1k1091 \le k \le 10^9, and 1xn1 \le x \le n.

Output

For every case, print the final position of the ball.

Problem information

Author: Enric Rodríguez

Generation: 2026-01-25T11:10:17.730Z

© Jutge.org, 2006–2026.
https://jutge.org