Bob is a CS major at CUPK, as a hardworking student, he jots down $N$ pages of notes for his computer science class.
represented by array $A$ of size $N$.
Unfortunately, due to his highspeed writing, his writings are almost unrecognisable. After trying hard to decipher his own notes. He managed to unscramble his notes partially,
His partially unscrambled notes are represented by arrays $B$ and $C$ both of size $N$, where $$ B_i = (A_i \hspace{0.1cm} \land \hspace{0.1cm}A_1) + (A_i\hspace{0.1cm} \land \hspace{0.1cm}A_2) +
(A_i\hspace{0.1cm} \land \hspace{0.1cm}A_3) + ...+(A_i\hspace{0.1cm} \land \hspace{0.1cm}A_n),$$
and
$$ C_i = (A_i \hspace{0.1cm} \lor \hspace{0.1cm}A_1) + (A_i \hspace{0.1cm} \lor \hspace{0.1cm}A_2) + (A_i \hspace{0.1cm} \lor \hspace{0.1cm} A_3)+...+(A_i \hspace{0.1cm} \lor \hspace{0.1cm} A_n).$$
Note that $\hspace{0.1cm}\land\hspace{0.1cm}$ denotes the bitwise AND operator, $\hspace{0.1cm}\lor\hspace{0.1cm}$ denotes the bitwise OR operator.
Given $B$ and $C$, help Bob unscramble his notes $A$ or report that it is impossible.
Input
The first line of input contains two integers $T$ and $N$, the corresponding subtask and the number of pages in Bob's notes.
The second line of input contains $N$ integers, where the $i$-th integer is $B_i$.
The third line of input contains $N$ integers, where the $i$-th integer is $C_i$.
Output
Output $N$ integers, where $A_i$ represents the $i$-th page of Bob's notes, or a single integer -1 if it is impossible to unscramble.
If there are multiple solutions, output one of them.
Constraints:
For all cases: $1 \le N \le 10^5, 0 \le B_i \le 10^9, 0 \le C_i \le 10^9, A_i \ge 0$
Subtask 1 (5%): $1 \le N \le 16$, $0 \le A_i \le 1$ if a solution exists
Subtask 2 (10%): $0 \le A_i \le 1$ if a solution exists
Subtask 3 (35%): It is guaranteed a solution exists
Subtask 4 (10%): $1 \le N \le 1000$
Subtask 5 (40%): No additional constraints
Sample Test Cases
| Input | Output | |
|---|---|---|
| 1 4 3 3 0 3 4 4 3 4 |
1 1 0 1 | |
| 1 10 6 0 6 0 6 6 0 6 6 0 10 6 10 6 10 10 6 10 10 6 |
1 0 1 0 1 1 0 1 1 0 | |
| 4 4 4 0 4 5 13 9 13 24 |
2 0 2 5 | |
| 4 4 4 0 4 5 13 8 13 24 |
-1 |
Scoring: Per Subtask
Authored by s19f34
Appeared in 2025 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆