#P6891. [JOISC 2020] ビルの飾り付け 4

[JOISC 2020] ビルの飾り付け 4

Description

Given two sequences A,BA, B of length 2n2n, construct a sequence CC of length 2n2n that satisfies the following conditions:

  • For 1i2n1 \leq i \leq 2n, CiC_i can only be chosen from AiA_i and BiB_i.

  • The number of times CiC_i is chosen from AiA_i and the number of times it is chosen from BiB_i are both exactly nn.

  • CC is a non-decreasing sequence.

If there are multiple valid sequences CC, you only need to output one.

Input Format

The first line contains a positive integer nn.

The second line contains 2n2n numbers, where the ii-th number is AiA_i.

The third line contains 2n2n numbers, where the ii-th number is BiB_i.

Output Format

If there is no solution, output 1-1. Otherwise, output a string ss in the following way:

For 1i2n1 \leq i \leq 2n, if CiC_i is chosen from AiA_i, then si=As_i=\texttt{A}; otherwise, si=Bs_i=\texttt{B}.

3
2 5 4 9 15 11
6 7 6 8 12 14
AABABB
2
1 4 10 20
3 5 8 13
BBAA
2
3 4 5 6
10 9 8 7
-1
6
25 18 40 37 29 95 41 53 39 69 61 90
14 18 22 28 18 30 32 32 63 58 71 78
BABBABAABABA

Hint

Sample 1 Explanation

The constructed C=[2,5,6,9,12,14]C=[2,5,6,9,12,14]. You can check for yourself that this satisfies the conditions.

Sample 2 Explanation

There are also 55 other solutions: $\texttt{AABB}, \texttt{ABAB}, \texttt{BABA}, \texttt{BAAB}, \texttt{ABBA}$. Any one of them is acceptable.

Sample 3 Explanation

There is no solution that satisfies the conditions.

Subtasks

Subtask Special Property Score
11 1n2×1031 \leq n \leq 2\times 10^3 1111
22 None 8989

Constraints

For 100%100\% of the testdata, 1n5×1051 \leq n \leq 5\times 10^5, 1Ai,Bi1091 \leq A_i, B_i \leq 10^9.

Translated by ChatGPT 5