#t91. 数列的第 m 个数

数列的第 m 个数

The m-th Term of the Sequence

Problem Description

There is an infinite sequence. Starting from the kk-th term, every nn terms form one cycle.

Specifically, the terms from the kk-th to the (k+n−1)(k+n-1)-th are the given nn integers in order, after which these nn numbers keep repeating.

Given nn, kk, these nn integers, and an integer mm, find the mm-th term of the sequence. It is guaranteed that m≥km \ge k.

Input Format

The first line contains two integers n,kn, k, satisfying 0<k≤100, 0<n≤300<k\le100,\ 0<n\le30.

The second line contains nn integers, representing the kk-th, (k+1)(k+1)-th, ..., (k+n−1)(k+n-1)-th terms of the sequence in order.

The third line contains an integer mm, satisfying k≤m≤109k\le m\le10^9.

Output Format

Output one integer, the value of the mm-th term of the sequence.

Sample Input

5 7
23 7 19 51 6
13

Sample Output

7

Sample Explanation

The given 55 numbers start repeating from the 7th term, so the sequence from the 7th term is:

  • 7th term = 23
  • 8th term = 7
  • 9th term = 19
  • 10th term = 51
  • 11th term = 6
  • 12th term = 23
  • 13th term = 7

So the 13th term is 7, and the output is 7.