#P13803. [SWERC 2023] Broken trophy

[SWERC 2023] Broken trophy

题目描述

:::align{center}

:::

Coming back home after triumphally winning your long-coveted trophy, you discover that it was shattered to pieces in your trunk. It just remains to repair it.

Your trophy had the shape of a rectangle of size 3×N3 \times N, for some integer N1N \geq 1, thereby consisting of 3 lines and NN columns, containing a total of 3N3N unit squares. It was broken into KK pieces, the kthk^\text{th} piece being a rectangle of size Ak×BkA_k \times B_k for some integers AkA_k and BkB_k such that 1AkBk31 \leq A_k \leq B_k \leq 3. Such pieces may have been rotated, or even flipped, in the havoc that is your trunk.

As the first step towards repairing your trophy, you should reassemble them in the form of a rectangle of size 3×N3 \times N. More precisely, you have drawn, on a sheet of paper, a 3×N3 \times N rectangle on which you will place your KK pieces, and you need to know, for all integers i3i \leq 3 and jNj \leq N, which piece will cover the unit square on the ithi^\text{th} line and jthj^\text{th} column of your rectangle.

输入格式

The input consists of three lines, each one containing space-separated integers. The first line contains the numbers KK and NN. The second line contains the numbers A1,A2,,AKA_1, A_2, \dots, A_K. The third line contains the numbers B1,B2,,BKB_1, B_2, \dots, B_K.

Limits

  • 1K300 0001 \leq K \leq 300~000;
  • 1N100 0001 \leq N \leq 100~000;
  • 1AkBk31 \leq A_k \leq B_k \leq 3 for all kKk \leq K;
  • the pieces described in the input can be reassembled in the form of a rectangle of size 3×N3 \times N.

输出格式

The output should contain three lines, each one consisting of NN space-separated integers. If you plan to cover the unit square on the ithi^\text{th} line and jthj^\text{th} column with the kthk^\text{th} piece, the jthj^\text{th} number on the ithi^\text{th} output line should be the integer kk.

In case there are several ways to reassemble your pieces in the form of a rectangle of size 3×N3 \times N, every output representing one of these ways is considered correct.

16 17
1 2 1 1 2 1 2 1 1 1 1 1 2 2 1 1
3 3 1 3 2 3 3 1 1 2 2 3 3 3 1 3
1 2 2 2 12 6 4 13 13 16 16 16 9 10 10 7 7
1 2 2 2 12 6 4 13 13 5 5 14 14 14 11 7 7
1 3 15 8 12 6 4 13 13 5 5 14 14 14 11 7 7

提示

Sample Explanation 1

This output represents the following reassembling:

:::align{center}

:::

Another valid reassembling could be:

:::align{center}

:::