Broken trophy

시간 제한1초메모리 제한1024 MB

요약
변이 3 이하인 K개의 작은 직사각형 조각으로 3 x N 직사각형을 채우고, 각 칸을 덮는 조각 번호를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 구현, 조합론
정답자
아직 제출이 없습니다

문제

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 N≥1N \ge 1, thereby consisting of 33 lines and NN columns, containing a total of 3N3N unit squares. It was broken into KK pieces, the kkth piece being a rectangle of size A_k×B_kA\_k \times B\_k for some integers A_kA\_k and B_kB\_k such that 1≤A_k≤B_k≤31 \le A\_k \le B\_k \le 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 i≤3i \le 3 and j≤Nj \le N, which piece will cover the unit square on the iith line and jjth 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 A_1,A_2,…,A_KA\_1, A\_2, \dots , A\_K. The third line contains the numbers B_1,B_2,…,B_KB\_1, B\_2, \dots, B\_K.

출력

The output should contain three lines, each one consisting of NN space-separated integers. If you plan to cover the unit square on the iith line and jjth column with the kkth piece, the jjth number on the iith 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.

제한

  • 1≤K≤300,0001 \le K \le 300\\, 000
  • 1≤N≤100,0001 \le N \le 100\\, 000
  • 1≤A_k≤B_k≤31 \le A\_k \le B\_k \le 3 for all k≤Kk \le K
  • the pieces described in the input can be reassembled in the form of a rectangle of size 3×N3 \times N.

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    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
    
    예상 출력
    4 2 2 2 1 1 1 7 7 6 6 6 10 10 15 14 14
    4 2 2 2 16 16 16 7 7 5 5 13 13 13 9 14 14
    4 11 11 3 12 12 12 7 7 5 5 13 13 13 8 14 14