#arc120c. [arc120_c]Swaps 2
[arc120_c]Swaps 2
Problem Statement
Given are two sequences of length each: and .
Determine whether it is possible to make equal by repeatedly doing the operation below (possibly zero times). If it is possible, find the minimum number of operations required to do so.
- Choose an integer such that , and do the following in order:
- swap and ;
- add to ;
- subtract from .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to make equal , print -1
.
Otherwise, print the minimum number of operations required to do so.
Sample Input 1
3
3 1 4
6 2 0
Sample Output 1
2
We can match with in two operations, as follows:
- First, do the operation with , making .
- Next, do the operation with , making .
We cannot meet our objective in one or fewer operations.
Sample Input 2
3
1 1 1
1 1 2
Sample Output 2
-1
In this case, it is impossible to match with .
Sample Input 3
5
5 4 1 3 2
5 4 1 3 2
Sample Output 3
0
may equal before doing any operation.
Sample Input 4
6
8 5 4 7 4 5
10 5 6 7 4 1
Sample Output 4
7