#P9511. 『STA - R3』大豆
『STA - R3』大豆
Background
Soy (Soybean) has a very promising future.

Problem Description
For a sequence , define its Soybeanization sequence by the following process:
- Initially, is the same as .
- Traverse all positive integers in increasing order. For each , do:
- Traverse all integers in increasing order. For each , apply .
- If , stop the process.
Furthermore, define the -Soybeanization sequence of a sequence as the sequence obtained after applying the Soybeanization operation times.
Now you are given an integer sequence . Repeat infinitely to obtain the sequence . Find the -th term of the -Soybeanization sequence of .
Indices start from 1. The answer may be very large; output it modulo (a prime).
Input Format
The first line contains three positive integers .
The second line contains positive integers describing the sequence .
Output Format
Output one line containing the answer modulo .
2 3 1
1 2
23068672
3 5 2
2 1 2
23068666
5 1000000000 1
1 5 10 3 2
68769
5 1000000000 3
1 5 10 3 2
5430204
Hint
Sample Explanation
Sample 1 Explanation
Construct the sequence as follows:
- .
- .
- $b_3=a_3-b_{\lfloor\frac 32\rfloor}-b_{\lfloor\frac 33\rfloor}=a_3-b_1-b_1=-1$.
Therefore, the answer is .
Sample 2 Explanation
The first 5 terms after the first Soybeanization: .
The first 5 terms after the second Soybeanization: .
So the answer is .
Constraints
$$\newcommand{\arraystretch}{1.5} \begin{array}{c|c|c|c}\hline\hline \textbf{Subtask} & \bm{m}\le & \textbf{Score} & \textbf{Special Property} \\\hline \textsf{1} & 10^6 & 10 & \\\hline \textsf{2} & 10^9 & 20 & \\\hline \textsf{3} & 10^{10} & 20 & k=1 \\\hline \textsf{4} & 10^{10} & 50 & \\\hline\hline \end{array}$$For all testdata, , , , .
Translated by ChatGPT 5