2702.Fibonotci

Time Limit: 1s Memory Limit: 256MB

Fibonotci sequence is an integer recursive sequence defined by the recurrence relation Fn=sn-1 \cdot Fn-1+sn-2 \cdot Fn-2 with F0=0,F1=1 Sequence s is an infinite and almost cyclic sequence with a cycle of length N. A sequence s is called almost cyclic with a cycle of length N if 2702_1.png, for i \ge N, except for a finite number of values si, for which 2702_2.png (i \ge N).Following is an example of an almost cyclic sequence with a cycle of length 4: s = (5,3,8,11,5,3,7,11,5,3,8,11,...) Notice that the only value of s for which the equality 2702_3.png does not hold is s6 (s6=7 and s2=8). You are given s0,s1,...sN-1 and all the values of sequence s for which 2702_2.png (i \ge N).Find 2702_4.png.

Input Format(From the terminal/stdin)

Input The first line contains two numbers K and P. The second line contains a single number N. The third line contains N numbers separated by spaces, that represent the first N numbers of the sequence s. The fourth line contains a single number M, the number of values of sequence s for which 2702_2.png. Each of the following M lines contains two numbers j and v, indicating that 2702_5.png and sj=v. All j-s are distinct. 1 \le N,M \le 50000 0 \le K \le 1018 1 \le P \le 109 1 \le si \le 109, for all i=0,1,...N-1 N \le j \le 1018 1 \le v \le 109 All values are integers

Output Format(To the terminal/stdout)

Output Output should contain a single integer equal to 2702_4.png.

Sample Input

Copy
10 8
3
1 2 1
2
7 3
5 4
  · \n
 \n
 · · \n
 \n
 · \n
 · \n

Sample Output

Copy
4
 \n

Submit

请先 登录

© 2025 FAQs