#P11120. Symmetric Seating Arrangement

    ID: 13180 Type: Default 1000ms 256MiB

Symmetric Seating Arrangement

Symmetric Seating Arrangement

You are given the seating status for a row of seat pairs in an airplane. There are n pairs of seats, with one seat on the left and one on the right of the aisle for each pair. A seat is either already booked online (marked with a 1) or empty (marked with a 0). You are also given an integer m representing the number of additional passengers you must seat. Your task is to assign exactly m additional passengers to empty seats so that the final seating arrangement is symmetric with respect to the aisle; that is, for each seat pair, either both seats are occupied or both are empty.

The pre-booked seats cannot be changed. However, if one seat in a pair is booked and its symmetric counterpart is empty, you must assign an additional passenger to fill the gap if you have enough passengers available. Furthermore, when assigning new passengers to an initially empty pair, you must assign both seats simultaneously (using 2 passengers) to maintain symmetry.

If it is not possible to achieve a symmetric seating arrangement by assigning exactly m additional passengers, output Impossible. Otherwise, print the final seating arrangement as two binary strings (one for the left side and one for the right side) on separate lines.

Note: All formulas should be written in LaTeX. For example, the number of seat pairs is given by $n$, and the number of additional passengers is given by $m$.

inputFormat

The input consists of three lines:

  1. The first line contains two space-separated integers $n$ and $m$ ($1 \le n, m \le 10^5$), where $n$ is the number of seat pairs, and $m$ is the number of additional passengers.
  2. The second line is a binary string of length $n$ representing the seating status of the left side of the aisle. A character '1' indicates that the seat is already occupied, while '0' indicates it is empty.
  3. The third line is a binary string of length $n$ representing the seating status of the right side of the aisle in the same format.

outputFormat

If it is possible to assign exactly $m$ additional passengers such that the seating arrangement becomes symmetric (i.e. for every pair the seats are either both occupied or both empty), output the final seating arrangement in two lines:

  1. The first line is the binary string for the left side.
  2. The second line is the binary string for the right side.

If it is impossible, output the string Impossible.

sample

3 2
101
000
101

101

</p>