AT_arc232_c [ARC232C] All Add or Single Negate
Description
You are given length- $ N $ integer sequences: $ A=(A_1,A_2,\ldots,A_N) $ and $ B=(B_1,B_2,\ldots,B_N) $ .
You can perform the following two types of operations any number of times in any order.
- Add $ 1 $ to every element of $ A $ .
- Choose an integer $ i $ satisfying $ 1\leq i\leq N $ , and replace $ A_i $ with $ -A_i $ .
Determine whether it is possible to make $ A $ and $ B $ equal as multisets. If it is possible, also find the minimum number of operations required. Here, $ A $ and $ B $ are equal as multisets when, for every integer, the number of its occurrences in $ A $ equals the number of its occurrences in $ B $ .
You are given $ T $ test cases; find the answer for each of them.
Input Format
The input is given from Standard Input in the following format:
> $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $
Each test case is given in the following format:
> $ N $ $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $ $ B_1 $ $ B_2 $ $ \ldots $ $ B_N $
Output Format
Output $ T $ lines. The $ i $ -th line should contain `-1` if it is impossible to make $ A $ and $ B $ equal as multisets in the $ i $ -th test case, and otherwise the minimum number of operations required.
Explanation/Hint
### Sample Explanation 1
In the first test case, first negate $ A_2 $ , then add $ 1 $ to every element, which makes $ A=(-2,2,1,3) $ . Now $ A $ and $ B $ are equal as multisets. They cannot be made equal with one operation, so the minimum number of operations required is $ 2 $ .
In the second test case, no matter how you perform the operations, $ A $ cannot be made equal to $ B=(0,1) $ as multisets.
### Constraints
- $ 1\leq T\leq 10^4 $
- $ 1\leq N\leq 100 $
- $ -10^9\leq A_i,B_i\leq 10^9 $ $ (1 \leq i \leq N) $
- The sum of $ N^3 $ over all test cases in a single input is at most $ 10^6 $ .
- All input values are integers.