Strange Operation

Time limit: 1s Memory limit: 256MB Input: Output:

Task

Doctor Strange found two integer arrays of length NN, namely A0,,AN1A_0, \dots, A_{N-1} and B0,,BN1B_0, \dots, B_{N-1}.
He can perform the following operation on AA any number of times:

  • Choose an index 1iN21 \leq i \leq N - 2 and let Ai:=(Ai1+Ai+Ai+1)A_i := -(A_{i - 1} + A_i + A_{i + 1}). That is, assign the value (Ai1+Ai+Ai+1)-(A_{i - 1} + A_i + A_{i + 1}) to AiA_i.

Help the Doctor determine whether it is possible to make the array AA equal to BB and if so, then find the minimum number of operations required to achieve this.

Input data

The first line contains the only integer NN.
The second line contains NN integers, the elements of array AA.
The third line contains NN integers, the elements of array BB.

Output data

You need to write a single line with an integer: the minimum number of operations required to make AA equal to BB, or 1-1 if it is not possible to do so.

Constraints and clarifications

  • 2N21052 \le N \le 2 \cdot 10^5.
  • 109Ai,Bi109-10^9 \le A_i, B_i \le 10^9 for each i=0N1i=0\ldots N-1.

Scoring

In this task, you can get partial scores: you will get 50%50\% of the points for a subtask if you successfully determine whether it is possible to make AA equal to BB (but do not correctly solve all of its test cases).
For this, the following condition must be satisfied for all test cases in a subtask: you should output 1-1 whenever it is impossible to make the two arrays equal, and otherwise, you should output a non-negative integer between 00 and 26312^{63}-1.

# Points Constraints
1 0 Examples.
2 15 There is at most one non-zero number in AA
3 18 N7N \le 7
4 50 N1000N \le 1000
5 17 No additional limitations.

Example 1

stdin

6
2 7 1 8 2 8
2 -10 1 -11 1 8

stdout

3

Explanation

In the first sample case, consider the following steps for the array A=[2,7,1,8,2,8]A = [2,7,1,8,2,8]:

  • Perform the operation on index 33. The array becomes: [2,7,1,11,2,8][2,7,1,-11,2,8].
  • Perform the operation on index 11. The array becomes: [2,10,1,11,2,8][2,-10,1,-11,2,8].
  • Perform the operation on index 44. The array becomes: [2,10,1,11,1,8][2,-10,1,-11,1,8].

It is not possible to make the two arrays equal in less than 33 moves.

Example 2

stdin

4
3 1 4 1
-4 1 -6 1

stdout

-1

Explanation

In the second sample case, it can be proven that there is no way to make AA equal to BB using the described operation.

Log in or sign up to be able to send submissions!