Sequence Conversion
시간 제한3초메모리 제한1024 MB
인접한 두 원소에 같은 x를 xor하는 연산으로 배열 a를 b로 바꾸는 최소 연산 횟수를 구하고, 불가능하면 -1을 출력한다.
문제
You are given two arrays of non-negative integers and .
You can perform the following operation several times:
- Choose a non-negative integer and an index . Then change to and change to .
Expression means bitwise xor of two numbers and .
In binary representation, if the -th digit of x and y is equal, then the -th digit of is , and if not, it is .
The given operation exists in all modern programming languages. For example, in C++ and Java, it is represented as .
You want to convert to by performing the minimum number of operations.
Find the minimum number of operations to convert to .
If you cannot convert to with the given operation, print .
입력
The first line contains an integer , where denotes the length of the two sequences.
The second line contains space-separated non-negative integers .
The third line contains space-separated non-negative integers .
출력
Print , if it is impossible to change the sequence to .
Otherwise, print the minimum number of operations needed to change the sequence to .