#B4246. Teacher's Walk in Circle
Teacher's Walk in Circle
Teacher's Walk in Circle
There are (n) children arranged in a circle and numbered clockwise from (1) to (n). Each child (i) wears a shirt with a number (a_i). The teacher initially stands next to the child numbered (1) and will perform (m) moves. In each move, the teacher looks at the number on the current child's shirt and then moves counterclockwise by that many children. After (m) moves, determine next to which child the teacher stands.
Note: The movement is performed in a circle. For example, if the teacher is next to child (1) and the number on the shirt is (2), then moving counterclockwise will take the teacher to child (n-1) if (n = 5), the order being (1 \to 5 \to 4).
inputFormat
The first line contains two integers (n) and (m) ((1 \leq n, m \leq 10^5) for example). The second line contains (n) integers (a_1, a_2, \ldots, a_n), where (a_i) is the number on the shirt of the (i)-th child.
outputFormat
Output a single integer representing the number of the child next to whom the teacher stands after (m) moves.
sample
5 3
2 1 3 2 1
1
</p>