PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000003. Trộn hai dãy tăng (Merge Sequences)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Trộn hai dãy tăng (Merge Sequences)

Merge Sequences

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

You are given two integer sequences, A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,…,BM)B=(B_1,B_2,\ldots,B_M). Both sequences are strictly increasing: each element is greater than its predecessor. Furthermore, no element of AA equals any element of BB.

Combine all N+MN+M elements and sort them in ascending order to obtain sequence CC. Because all values are distinct, every original element has a unique position in CC.

Find the position in CC of every AiA_i, followed by the position in CC of every BjB_j. Positions are numbered starting from 11.

Input

  • The first line contains two integers NN and MM, the lengths of the sequences.
  • The second line contains exactly NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N in strictly increasing order.
  • The third line contains exactly MM integers B1,B2,…,BMB_1,B_2,\ldots,B_M in strictly increasing order.

Output

  • On the first line, print NN integers: the positions in CC of A1,A2,…,ANA_1,A_2,\ldots,A_N, in this order.
  • On the second line, print MM integers: the positions in CC of B1,B2,…,BMB_1,B_2,\ldots,B_M, in this order.

Separate numbers on the same line with spaces. The smallest position is 11.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤1051\le N,M\le10^5; 2≤N+M≤132\le N+M\le13; 1≤A1<A2<⋯<AN≤1091\le A_1<A_2<\cdots<A_N\le10^9; 1≤B1<B2<⋯<BM≤1091\le B_1<B_2<\cdots<B_M\le10^9; Ai≠BjA_i\ne B_j for all 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M.
  • Subtask 2 (30 points): 1≤N,M≤1051\le N,M\le10^5; 2≤N+M≤1202\le N+M\le120; 1≤A1<A2<⋯<AN≤1091\le A_1<A_2<\cdots<A_N\le10^9; 1≤B1<B2<⋯<BM≤1091\le B_1<B_2<\cdots<B_M\le10^9; Ai≠BjA_i\ne B_j for all 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M.
  • Subtask 3 (50 points): 1≤N,M≤1051\le N,M\le10^5; 2≤N+M≤2⋅1052\le N+M\le2\cdot10^5; 1≤A1<A2<⋯<AN≤1091\le A_1<A_2<\cdots<A_N\le10^9; 1≤B1<B2<⋯<BM≤1091\le B_1<B_2<\cdots<B_M\le10^9; Ai≠BjA_i\ne B_j for all 1≤i≤N1\le i\le N, 1≤j≤M1\le j\le M.

Examples

Input

4 3
3 14 15 92
6 53 58

Output

1 3 4 7
2 5 6

Explanation

Combining and sorting the sequences gives C=[3,6,14,15,53,58,92]C=[3,6,14,15,53,58,92]. In CC, the elements 33, 1414, 1515, and 9292 occur at positions 11, 33, 44, and 77, respectively, so the first line is 1 3 4 7.

Likewise, the elements of BB, namely 66, 5353, and 5858, appear at positions 22, 55, and 66, giving the second line 2 5 6.