#C10835. Enchanted Garden Energy Absorption

    ID: 40084 Type: Default 1000ms 256MiB

Enchanted Garden Energy Absorption

Enchanted Garden Energy Absorption

In an enchanted garden, each plant is endowed with an energy value. The plants can absorb the energy of a neighboring plant according to the following operation:

  • Choose two adjacent plants. If the left plant has an energy strictly greater than the right one, the left plant can absorb its right neighbor: its energy becomes the sum of both energies, and the right plant is removed. This operation is denoted as (i, R) where i is the 1-indexed position of the absorbing plant.
  • If no such pair exists, then one may choose a pair where the left plant’s energy is strictly less than the right one, and merge them similarly (always recorded as a right-absorption event).

You are given a list of $m$ plants with energies $[E_1,E_2,\dots,E_m]$ and a target configuration of $t$ energies $[T_1,T_2,\dots,T_t]$. Your goal is to perform a sequence of absorption events so that the final list (in order) equals the target configuration. If it is possible to achieve the target configuration, output "POSSIBLE" followed by the list of absorption events (one event per line). Otherwise, output "IMPOSSIBLE".

Note that an absorption event is described by two parts: the 1-indexed position of the plant that absorbs its neighbor and the direction (always 'R' in the operations below). The rules guarantee that after each operation the number of plants decreases by one. The final resulting energy for a group is the sum of the merged energies, i.e. if a segment of plants is merged, its energy satisfies $$\sum_{i=l}^{r} E_i = T_j.$$

inputFormat

The input is given via stdin and consists of four lines:

  1. An integer m representing the number of plants.
  2. m space‐separated integers representing the initial energies of the plants.
  3. An integer t representing the number of plants required in the target configuration.
  4. t space‐separated integers representing the target energies.

It is guaranteed that $1 \le m \le 10^5$ and $1 \le t \le m$.

outputFormat

The output should be written to stdout. If it is impossible to obtain the target configuration, print a single line containing IMPOSSIBLE. Otherwise, print POSSIBLE on the first line, followed by one line for each absorption event. Each event line should contain two entries: the 1-indexed position of the plant that performed the absorption and the letter R indicating a right absorption.

## sample
6
1 3 3 2 1 4
3
6 2 4
IMPOSSIBLE