CF1906E Merge Not Sort

Description

You are currently researching the Merge Sort algorithm. Merge Sort is a sorting algorithm that is based on the principle of Divide and Conquer. It works by dividing an array into two subarrays of equal length, sorting each subarrays, then merging the sorted subarrays back together to form the final sorted array. You are particularly interested in the merging routine. Common merge implementation will combine two subarrays by iteratively comparing their first elements, and move the smaller one to a new merged array. More precisely, the merge algorithm can be presented by the following pseudocode. ```


Merge(A[1..N], B[1..N]):

C = []

i = 1

j = 1

while i

Input Format

The first line consists of an integer $ N $ ( $ 1 \leq N \leq 1000 $ ). The following line consists of $ 2 \cdot N $ integers $ C_i $ . The array $ C $ is a permutation of $ 1 $ to $ 2 \cdot N $ .

Output Format

If it is impossible to construct two arrays $ A $ and $ B $ of length $ N $ such that $ \text{Merge}(A, B) = C $ , then output -1. Otherwise, output the arrays $ A $ and $ B $ in two lines. The first line consists of $ N $ integers $ A_i $ . The second line consists of $ N $ integers $ B_i $ . If there are several possible answers, output any of them.

Explanation/Hint

Explanation for the sample input/output #1 The solution $ A = [3, 1, 4] $ and $ B = [5, 2, 6] $ is also correct. Explanation for the sample input/output #2 The solution $ A = [1, 2, 3, 4] $ and $ B = [5, 6, 7, 8] $ is also correct.