#P12006. Determining the Sum of Song Goodness Values

    ID: 14109 Type: Default 1000ms 256MiB

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 nn songs, but he does not know the individual goodness values. Instead, for every 1i<n1 \leq i < n, you are given the value [ S_i = A_i + A_{i+1}, ] where AiA_i is the goodness value of the ii-th song.

Now, Little H is changing his listening pattern. In the new scheme, he will listen to songs in mm rounds. In the ii-th round, he listens to the aia_i-th song bib_i 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 nn songs is underdetermined (there is one free variable). The goodness value for the ii-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 did_i 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 A1A_1, 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 nn and mm, where nn is the number of songs, and mm is the number of listening rounds in the new method.

The second line contains n1n-1 integers: S1,S2,,Sn1S_1, S_2, \ldots, S_{n-1}, where each Si=Ai+Ai+1S_i = A_i + A_{i+1}.

Then follow mm lines, each containing two integers aia_i and bib_i, indicating that in the ii-th round, Little H listens to the aia_i-th song bib_i 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>