#P12006. Determining the Sum of Song Goodness Values
Determining the Sum of Song Goodness Values
Determining the Sum of Song Goodness Values
In the year 2077, NetEase Cloud Music introduced a statistics feature where each song is assigned a so-called "goodness value" (which can be any integer). The combination value of any two consecutive songs is defined as the sum of their goodness values.
You are given that Little H listened to a sequence of songs, but he does not know the individual goodness values. Instead, for every , you are given the value [ S_i = A_i + A_{i+1}, ] where is the goodness value of the -th song.
Now, Little H is changing his listening pattern. In the new scheme, he will listen to songs in rounds. In the -th round, he listens to the -th song times. Since listening to a song multiple times counts the song's goodness value each time, the overall sum will be the sum of each song's goodness value multiplied by the number of times it is played.
However, note that the system of equations for the songs is underdetermined (there is one free variable). The goodness value for the -th song can be expressed as: [ A_i = c_i \cdot A_1 + d_i ] where [ c_i = \begin{cases} 1, & \text{if } i \text{ is odd}\ -1, & \text{if } i \text{ is even} \end{cases} ] and the offsets can be computed recursively using the relation [ A_{i+1} = S_i - A_i. ]
Let the final answer be [ \text{Answer} = \sum_{j=1}^{m} b_j \cdot A_{a_j} = A_1 \cdot \left(\sum_{j=1}^{m} b_j \cdot c_{a_j}\right) + \left(\sum_{j=1}^{m} b_j \cdot d_{a_j}\right). ]
If (\sum_{j=1}^{m} b_j \cdot c_{a_j} \neq 0), then the overall sum depends on the free variable , and it is impossible to determine a unique answer. In that case, you should output Impossible
.
Otherwise, if (\sum_{j=1}^{m} b_j \cdot c_{a_j} = 0), then the final answer is uniquely determined and equals (\sum_{j=1}^{m} b_j \cdot d_{a_j}).
inputFormat
The input consists of multiple lines:
The first line contains two integers and , where is the number of songs, and is the number of listening rounds in the new method.
The second line contains integers: , where each .
Then follow lines, each containing two integers and , indicating that in the -th round, Little H listens to the -th song times.
outputFormat
Output the total sum of the goodness values according to the new listening method. If the sum cannot be uniquely determined, output Impossible
.
sample
3 2
3 4
1 1
3 1
Impossible
</p>