Sequence Conversion

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

You are given two arrays of non-negative integers a_1,a_2,,a_Na\_1, a\_2, \dots, a\_N and b_1,b_2,,b_Nb\_1, b\_2, \dots, b\_N.

You can perform the following operation several times:

  • Choose a non-negative integer xx and an index 1i<N1 \leq i < N. Then change a_ia\_i to a_ixa\_i \oplus x and change a_i+1a\_{i+1} to a_i+1xa\_{i+1} \oplus x.

Expression xyx \oplus y means bitwise xor of two numbers xx and yy.
In binary representation, if the ii-th digit of x and y is equal, then the ii-th digit of xyx \oplus y is 00, and if not, it is 11.
The given operation exists in all modern programming languages. For example, in C++ and Java, it is represented as x  yx\ ^{\wedge}\ y.

You want to convert a_i\\{a\_i\\} to b_i\\{b\_i\\} by performing the minimum number of operations.

Find the minimum number of operations to convert a_i\\{a\_i\\} to b_i\\{b\_i\\}.

If you cannot convert a_i\\{a\_i\\} to b_i\\{b\_i\\} with the given operation, print 1-1.

입력

The first line contains an integer NN, where NN denotes the length of the two sequences.

The second line contains NN space-separated non-negative integers a_1,a_2,,a_Na\_1, a\_2, \dots, a\_N.

The third line contains NN space-separated non-negative integers b_1,b_2,,b_Nb\_1, b\_2, \dots, b\_N.

출력

Print 1-1, if it is impossible to change the sequence a_i\\{a\_i\\} to b_i\\{b\_i\\}.

Otherwise, print the minimum number of operations needed to change the sequence a_i\\{a\_i\\} to b_i\\{b\_i\\}.

제한

  • 1N1061 \leq N \leq 10^6
  • 0a_i,b_i<2300 \leq a\_i, b\_i < 2^{30} (1iN)(1 \le i \le N)