One ominous late October night you recieve a startling message:
------BEGIN MESSAGE------
From: <REDACTED>
Hello MCPT user. I have inserted an array initially consisting of integers, as well as a set of instructions onto this website.
Each instruction is in the form
x y
, stating that for all indices , if , is inserted between indices and of the array. Note that represents the size of the current array.Now comes the fun part. During an iteration, each instruction will be performed on all valid indices simultaneously, exactly once. My array will theoretically keep growing forever and ever, taking up all the resources and memory on this website.
There is hope. The array will stop growing if you can print out the correct stop key. The stop key is found by determining the sum of all integers within the array after exactly iterations, modulo . I'm almost certain there is no possible way to do this.
------END MESSAGE------
Help save MCPT! Print out the stop key.
Constraints
all are distinct.
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Input Specification
The first line will contain , , and , space-separated.
The next line will contain integers .
The next lines will contain integers and .
Output Specification
Output the stop key, the sum of all integers within the array after iterations, modulo .
Sample Input
5 2 2
1 2 3 1 2
3 4
5 1
Sample Output
24
Explanation
After the first iteration, the array is:
After the second iteration, the array is:
The sum of all integers in this array is .
Comments