#SGM0000020. Cân bằng (Equilibrium)
Cân bằng (Equilibrium)
Equilibrium
Source: Codeforces
Version: Phuoc Hung OJ Extended
You are given two arrays and of length . Each query segment is processed independently.
One balancing operation selects an even number of positions:
Then are increased by , while are increased by .
For each query, find the minimum number of operations needed to make for all , or print if it is impossible.
Input
The first line contains .
The second line contains .
The third line contains .
Each of the next lines contains with .
Output
For every query, print the minimum number of operations, or if impossible.
Subtasks
- Subtask 1 — 20%: , , .
- Subtask 2 — 30%: , , .
- Subtask 3 — 50%: , .
Examples
Input
8 5
0 1 2 9 3 2 7 5
2 2 1 9 4 1 5 8
2 6
1 7
2 4
7 8
5 8
Output
1
3
1
-1
-1
Explanation
The sample follows the operations exactly; each printed line corresponds to a query that requires output.